<template>
  <at-table
    @load="loadData"
    :data="data"
    :page-result="pageResult"
    ref="AtTable"
    :dialogTitle="dialogTitle"
    :dialogVisible="dialogVisible"
    :isSortLoad="false"
    :default-sorter="[
      {direction: 'DESC', property: 'bc.contract_date_'},
      {direction: 'ASC', property: 'project_id_'},
      {direction: 'ASC', property: 'bc.type_'},
    ]"
    :cellClassNameFn="cellClassNameFn"
    @select-all="handleSelect"
    @select="handleSelect"
    @handleDialogCancel="handleDialogCancel"
    @handleDialogClose="handleDialogClose"
    @handleDialogSubmit="handleDialogSubmit"
    @row-dblclick="handleRowDBClick"
  >
    <template v-slot:searchInput>
      <el-form
        ref="searchForm"
        :model="searchForm"
        label-width="80px"
        class="search-top"
        @submit.native.prevent
      >
        <project-info-selector
          v-if="isShow"
          v-model="searchForm.projectId"
          style="width: 100%"
          @keyup.enter.native="findinfo"
        ></project-info-selector>
        <!--<el-input
          v-model="searchForm.contractNumber"
          style="width: 100%"
          placeholder="请输入合同编号"
          @keyup.enter.native="findinfo"
          clearable
        > -->
        <!-- <dict-select
          dictCode="htgl-htlb"
          :filterable="true"
          :hasDefaultOption="true"
          clearable
          placeholder="请选择合同类型"
          v-model="searchForm.type"
          style="width: 100%"
        /> -->

        <el-input
          v-model="searchForm.typeValue"
          placeholder="请输入合同类型"
          clearable
          @keyup.enter.native="findinfo"
        ></el-input>
        <el-input
          v-model="searchForm.name"
          placeholder="请输入合同名称"
          clearable
          @keyup.enter.native="findinfo"
        ></el-input>
        <!-- todo -->
        <el-input
          v-model="searchForm.contractReceiver"
          placeholder="请输入经办人"
          clearable
          @keyup.enter.native="findinfo"
        ></el-input>
        <!-- todo -->
        <!--<dict-select
          dictCode="zbfs"
          :hasDefaultOption="true"
          clearable
          placeholder="请选择招标方式"
          v-model="searchForm.biddingChargeType"
          style="width: 100%"
        />
         <el-date-picker
          v-model="searchForm.contractDate"
          type="date"
          placeholder="选择签订日期"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          style="width: 100%"
          @keyup.enter.native="findinfo"
        > 
        </el-date-picker>-->
        <el-button
          size="small"
          @click="findinfo"
          type="primary"
          class="el-icon-search search-btn"
          >查询</el-button
        >
        <el-button
          size="small"
          @click="handleReset"
          type="primary"
          plain
          class="el-icon-refresh"
          >重置</el-button
        >
      </el-form>
      <div class="administrativePay">
        <el-button size="mini" @click="handelPay">行政缴费</el-button>
      </div>
    </template>
    <template v-slot:operationBtn>
      <el-button
        size="small"
        type="primary"
        @click="handleAdd"
        icon="el-icon-plus"
        >添加</el-button
      >
      <ht-delete-button
        :url="deleteUrl"
        :requestMethod="'POST'"
        :htTable="$refs.AtTable"
        >删除</ht-delete-button
      >
      <import-file :importData="importData" @load="load"></import-file>
      <el-button
        size="small"
        type="primary"
        @click="handleExport"
        icon="el-icon-download"
        plain
        style="margin-left: 10px"
        >导出</el-button
      >
      <el-button
        size="small"
        type="primary"
        plain
        icon="el-icon-download"
        @click="handleDownFile"
        >下载合同文件</el-button
      >
      <div class="operation-input">
        <span>全过程造价咨询单位：</span>
        <div class="input">
          <el-input
            v-model="costConsultation"
            placeholder="请输入全过程造价咨询单位"
            clearable
          >
          </el-input>
        </div>
        <el-button
          size="medium"
          type="primary"
          plain
          @click="handleSaveCostConsultation"
          >保存</el-button
        >
      </div>
    </template>
    <template>
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column type="index" label="序号" align="center" width="55">
      </el-table-column>
      <!-- <el-table-column
        prop="project.projectCode"
        label="项目代码"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->
      <el-table-column
        prop="project.projectName"
        label="项目名称"
        :show-overflow-tooltip="true"
        align="center"
        min-width="110"
        sortable
      >
      </el-table-column>

      <!-- <el-table-column
        prop="contract.contractNumber"
        label="合同编号"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->
      <el-table-column
        prop="contract.name"
        label="合同名称"
        align="center"
        min-width="110"
        sortable
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="contract.typeValue"
        label="合同类型"
        align="center"
        width="150"
        sortable
        :show-overflow-tooltip="true"
      >
        <!-- <template slot-scope="scope">
          {{ getDictName('htgl-htlb', scope.row.contract.type) }}
        </template> -->
      </el-table-column>
      <!-- <el-table-column
        prop="contract.contractReceiver"
        label="经办人"
        align="center"
        min-width="110"
        sortable
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->
      <!-- <el-table-column
        prop="contract.biddingChargeType"
        label="招标方式"
        align="center"
         width="120"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{
            getDictName('zbfs', scope.row.contract.biddingChargeType)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="contract.firstParty"
        label="甲方"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="contract.secondParty"
        label="乙方"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="contract.thirdParty"
        label="丙方"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->
      <el-table-column
        prop="contract.contractDate"
        label="签订日期"
        align="center"
        width="130"
        sortable
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="contract.contractAmount"
        label="合同金额(元)"
        align="center"
        width="160"
        sortable
        :show-overflow-tooltip="true"
      >
        <template v-slot="{row}">
          {{
            row.contract.contractAmount &&
            moneyFormatter(row.contract.contractAmount)
          }}
        </template>
      </el-table-column>
      <el-table-column
        prop="contract.secondLevelType"
        label="结算方式"
        align="center"
        width="120"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.contract.secondLevelType !== '----'">
            {{ getDictName('htgl-jsfs', scope.row.contract.secondLevelType) }}
          </span>
          <span v-else>----</span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="contract.retentionMoney"
        label="保证金"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->
      <!-- <el-table-column
        prop="contract.establishmentRemarks"
        label="备注"
        align="center"
        width="100"
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->
      <el-table-column
        prop="contract.opation_"
        label="操作"
        align="center"
        width="180"
        fixed="right"
      >
        <template v-slot="{row}">
          <!-- <el-link type="primary" @click="handleRouterClick(row)">
            <i class="el-icon-s-custom">支付管理</i>
          </el-link> -->
          <!-- <el-dropdown
            size="mini"
            split-button
            @command="handleCommand"
            @click="handleCommand({row:row, command: 'admin'})"
          >
            <span>
              <el-link type="primary">
                <i class="el-icon-s-custom">支付管理</i>
              </el-link>
            </span>
          </el-dropdown> -->
          <el-dropdown
            v-if="row.contract.opation_ !== '----'"
            size="mini"
            split-button
            @command="handleCommand"
            @click="handleCommand({row: row, command: 'pay'})"
          >
            <span>
              <el-link type="primary">
                <i class="el-icon-s-custom">支付管理</i>
              </el-link>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :command="{row: row, command: 'plan'}">
                <el-link type="primary">
                  <i class="el-icon-document">资金计划</i>
                </el-link>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <span v-else>----</span>
        </template>
      </el-table-column>
    </template>
    <template v-slot:dialogContent>
      <!-- <el-steps
        :active="active"
        finish-status="success"
        simple
        style="margin-top: 5px; margin-bottom: 20px"
      >
        <el-step title="基本信息"></el-step>
        <el-step title="工程量清单"></el-step>
        <el-step title="附件管理"></el-step>
      </el-steps> -->
      <el-form
        ref="form"
        v-form
        data-vv-scope="form"
        :model="form"
        :rules="rules"
        label-width="120px"
        v-if="dialogVisible"
        v-loading.fullscreen="loading"
      >
        <!-- <div
          v-if="active == 0"
          class="task-con-box"
        > -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="project.projectName">
              <el-input
                v-model="form.project.projectName"
                placeholder="请选择项目名称"
                @focus="handleFocusProject"
                :disabled="!isShow"
                clearable
              >
                <el-button
                  type="primary"
                  @click="handleFocusProject"
                  slot="append"
                  icon="el-icon-search"
                ></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同名称" prop="contract.name">
              <el-input
                v-model="form.contract.name"
                placeholder="请输入合同名称"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同编号" prop="contract.contractNumber">
              <el-input
                v-model="form.contract.contractNumber"
                placeholder="请输入合同编号"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同分类" prop="contract.mold">
              <dict-select
                dictCode="htgl-htfl"
                :hasDefaultOption="true"
                clearable
                placeholder="请选择项目类型"
                v-model="form.contract.mold"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <!-- <el-form-item label="合同类型" prop="contract.type">
              <dict-select
                dictCode="htgl-htlb"
                :hasDefaultOption="true"
                :filterable="true"
                clearable
                placeholder="请选择项目类型"
                v-model="form.contract.type"
                style="width: 100%"
              />
            </el-form-item> -->
            <el-form-item label="合同类型" prop="contract.typeValue">
              <el-input
                v-model="form.contract.typeValue"
                placeholder="请输入合同类型"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发包方式" prop="contract.biddingChargeType">
              <!-- <dict-select
                dictCode="htgl-fbfs"
                :filterable="true"
                :hasDefaultOption="true"
                clearable
                @input="(val, obj) => handleDict(val, obj, 'htgl-fbfs')"
                v-model="form.contract.biddingChargeType"
                style="width: 100%"
              /> -->
              <dict-select
                dictCode="htgl-fbfs"
                :hasDefaultOption="true"
                clearable
                placeholder="请选择项目类型"
                v-model="form.contract.biddingChargeType"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="签订日期" prop="contract.contractDate">
              <el-date-picker
                v-model="form.contract.contractDate"
                type="date"
                placeholder="选择签订日期"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="决策依据" prop="contract.decisionDocuments">
              <el-input
                v-model="form.contract.decisionDocuments"
                placeholder="请输入决策依据"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="金额(大写)">
                <el-input
                  v-model="form.contract.contractBigAmount"
                  placeholder="系统自动处理"
                  disabled
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                 <el-form-item label="保证金" prop="contract.retentionMoney">
                <el-input
                 type="number"
                  v-model="form.contract.retentionMoney"
                  placeholder="请输入保证金"
                  clearable
                >
                 <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同金额" prop="contract.contractAmount">
              <el-input
                type="number"
                v-model="form.contract.contractAmount"
                placeholder="请输入合同金额"
                clearable
                @change="handleChangeAmount"
              >
                <i slot="suffix">元</i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结算方式" prop="contract.secondLevelType">
              <dict-select
                dictCode="htgl-jsfs"
                :filterable="true"
                :hasDefaultOption="true"
                clearable
                v-model="form.contract.secondLevelType"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <!-- <el-form-item label="招标方式" prop="contract.biddingChargeType">
                <dict-select
                  dictCode="zbfs"
                  :hasDefaultOption="true"
                  clearable
                  @input="(val, obj) => handleDict(val, obj, 'zbfs')"
                  v-model="form.contract.biddingChargeType"
                  style="width: 100%"
                />
              </el-form-item> -->
            <el-form-item label="甲方单位" prop="contract.firstParty">
              <el-input
                v-model="form.contract.firstParty"
                placeholder="请输入甲方单位"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="乙方单位" prop="contract.secondParty">
              <el-input
                v-model="form.contract.secondParty"
                placeholder="请输入乙方单位"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="丙方单位" prop="contract.thirdParty">
              <el-input
                v-model="form.contract.thirdParty"
                placeholder="请输入丙方单位"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同执行进度" prop="contract.contractSchedule">
              <el-input
                v-model="form.contract.contractSchedule"
                placeholder="请输入合同执行进度"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="合同履行异常记录"
              prop="contract.contractExceptionLog"
            >
              <el-input
                v-model="form.contract.contractExceptionLog"
                placeholder="请输入合同履行异常记录"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="经办人" prop="contract.contractReceiver">
              <el-input
                v-model="form.contract.contractReceiver"
                placeholder="请输入经办人"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同存放处" prop="contract.contractStorage">
              <el-input
                v-model="form.contract.contractStorage"
                placeholder="请输入合同存放处"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item
              label="合同约定付款方式"
              prop="treatyContents
"
            >
              <el-input
                type="textarea"
                v-model="form.contract.treatyContents"
                placeholder="请输入合同约定付款方式"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item
              label="收款人及账号、电话"
              prop="payeeAccountPhone
"
            >
              <el-input
                type="textarea"
                v-model="form.contract.payeeAccountPhone"
                placeholder="请输入收款人及账号、电话"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item
              label="备注"
              prop="establishmentRemarks
"
            >
              <el-input
                type="textarea"
                v-model="form.contract.establishmentRemarks"
                placeholder="请输入备注"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- </div> -->
        <!-- <div
          v-if="active == 1"
          class="task-con-box"
        > -->
        <!-- <div class="btnDetailed">
          <el-button
            type="primary"
            @click="addListItem"
            icon="el-icon-plus"
          >
            添加</el-button>
          <import-file
            :importData="importDataDetailed"
            @load="loadDetailed"
          ></import-file>
          <el-button
            size="small"
            type="primary"
            @click="handleExportDetailed"
            icon="el-icon-download"
            plain
            style="margin-left: 10px"
          >导出</el-button>
        </div> -->
        <!-- <el-table
          :data="form.contractItem"
          border
          stripe
          style="max-width: 100%; min-width: 100%"
          max-height="460"
        >
          <el-table-column
            prop="name"
            label="科目名称"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.name"> </el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="subjectName"
            label="子科目名称"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.subjectName"> </el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="price"
            label="单价(元)"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.price"> </el-input>
            </template>
          </el-table-column>

          <el-table-column
            prop="amount"
            label="数量"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.amount"
                @change="(val) => changeAmount(val, scope.$index)"
              >
              </el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="monty"
            label="金额(元)"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.monty"> </el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="spec"
            label="单位"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.spec"> </el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="remarks"
            label="备注"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.remarks"> </el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="subjectName"
            label="操作"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                icon="el-icon-delete"
                @click="deleteTableData(scope.row.key, scope.row.id)"
              ></el-button>
            </template>
          </el-table-column>
        </el-table> -->
        <!-- </div> -->
        <!-- <div
          v-if="active == 2"
          class="task-con-box"
        > -->
        <file-table
          style="margin-top: 20px"
          @handleFile="handleFile"
          :file="form.accessoryInfo"
          :info="'上传项目相关合同文件，甲方不是本公司的不必上传'"
        />
        <!-- </div> -->
      </el-form>
      <!-- <div class="button-box">
        <div
          v-if="active == 0"
          @click="handleDialogCancel"
        >取消</div>
        <div
          @click="prevSteps"
          v-if="active != 0"
        >上一步</div>
        <div
          @click="nextSteps"
          v-if="active != 2"
        >下一步</div>
        <div
          v-if="active == 2"
          @click="handleDialogSubmit"
        >保存</div>
      </div> -->
    </template>
    <template v-slot:showTotalData>
      <span class="show-slected">
        已选中<i>{{ selected.numbers }}</i>
        条数据， 合同金额合计
        <i>{{ moneyFormatter(selected.contractAmount) }} </i>元
      </span>
    </template>
    <project-info-dialog
      ref="project"
      :single="true"
      @select="handleSelectProject"
    ></project-info-dialog>
  </at-table>
</template>
<script>
import ProjectInfoDialog from '@/components/dialog/ProjectInfoDialog.vue'
import {duration} from 'moment'
import {numToCny} from '@/lib/tool'
import req from '@/request.js'
const BigNumber = require('bignumber.js')
export default {
  name: 'ContractInformation', //合同管理
  components: {
    ProjectInfoDialog,
  },
  props: {
    pid: {
      type: String,
      default: '',
    },
    isShow: {
      type: Boolean,
      default: true,
    },
    alias: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      total: {
        project: {
          projectName: '合计',
        },
        contract: {
          name: '----',
          typeValue: '----',
          contractDate: '----',
          contractAmount: 1000,
          secondLevelType: '----',
          opation_: '----',
        },
      },
      selected: {
        numbers: 0,
        contractAmount: '0',
      },
      importData: {
        title: '合同信息导入',
        templateName: '合同信息模板.xls',
        downloadUrl: '/../fvue/static/excel/ExportContractInformation.xlsx',
        importUrl: window.context.cqxy + '/biz/contract/v1/importExcelData',
        showProject: true,
        projectId: '',
      },
      importDataDetailed: {
        title: '合同信息明细导入',
        templateName: '合同信息明细模板.xls',
        downloadUrl:
          '../../static/excel/ExportContractInformationDetailed.xlsx',
        importUrl: window.context.cqxy + '/biz/contract/item/v1/readExcelData',
      },
      projectObj: [],
      searchForm: {
        contractNumber: '',
        projectId: '',
        name: '',
        biddingChargeType: '',
        type: '',
        typeValue: '',
        contractReceiver: '',
      }, //顶部搜索参数
      dataBaseOptions: {
        dataBaseId: '',
        tableName: '', // 必填
        tableSchema: '',
      },
      ConstructionModeArr: [],
      ProjectTypeArr: [],
      originAPIOptions: {
        url: '', // 列表请求接口地址
        method: 'post', // 列表请求方法
        moduleRoot: '', // 微服务根路径
      },
      exportQuery: {},
      data: [], //表格数据
      pageResult: {
        page: 1,
        pageSize: 20,
        total: 0,
      },
      form: {}, //基本信息表单
      dialogVisible: false,
      dialogTitle: '添加',
      selectionArr: [],
      active: 0,
      loading: false,
      // tableData: [],
      // tableDataFiles: [],
      querySearch: [],
      costConsultation: '', //全过程造价咨询单位
      rules: {
        'project.projectName': {
          required: true,
          message: '请选择项目名称',
          trigger: 'blur',
        },
        'contract.biddingChargeType': {
          required: true,
          message: '请选择发包方式',
          trigger: 'blur',
        },
        // 'project.projectCode': {
        //   required: true,
        //   message: '请输入项目代码',
        //   trigger: 'blur',
        // },
        'contract.contractDate': {
          required: true,
          message: '请选择签订日期',
          trigger: 'blur',
        },
        'contract.decisionDocuments': {
          required: true,
          message: '请输入决策依据',
          trigger: 'blur',
        },
        'contract.typeValue': {
          required: true,
          message: '输入合同类型',
          trigger: 'blur',
        },

        // 'contract.type': {
        //   required: true,
        //   message: '输入合同类型',
        //   trigger: 'blur',
        // },
        'contract.mold': {
          required: true,
          message: '输入合同分类',
          trigger: 'blur',
        },
        // 'contract.contractNumber': {
        //   required: true,
        //   message: '请输入合同编号',
        //   trigger: 'blur',
        // },
        'contract.name': {
          required: true,
          message: '请输入合同名称',
          trigger: 'blur',
        },
        // 'contract.biddingChargeType': {
        //   required: true,
        //   message: '请输入招标方式',
        //   trigger: 'blur'
        // },
        // 'contract.contractAmount': {
        //   required: true,
        //   message: '请输入合同金额',
        //   trigger: 'blur',
        // },
        // 'contract.retentionMoney': {
        //   required: true,
        //   message: '请输入保证金',
        //   trigger: 'blur',
        // },
        // 'contract.firstParty': {
        //   required: true,
        //   message: '请输入甲方单位',
        //   trigger: 'blur',
        // },
        // 'contract.secondParty': {
        //   required: true,
        //   message: '请输入乙方单位',
        //   trigger: 'blur',
        // },
        // 'contract.thirdParty': {
        //   required: true,
        //   message: '请输入丙方单位',
        //   trigger: 'blur'
        // }
      },
    }
  },
  mounted() {
    this.initProjectAll()
  },
  created() {
    this.getByIdProject(this.pid)
  },
  computed: {
    deleteUrl: function () {
      return window.context.cqxy + '/biz/contract/v1/delete'
    },
  },
  methods: {
    // 根据项目id和合同ids导出相应合同文件
    handleDownFile() {
      if (this.$refs.AtTable.selection.length === 0)
        return this.$message.error('请选择导出合同文件')
      let projectId = this.$refs.AtTable.selection[0].project.id
      let arr = []
      this.$refs.AtTable.selection.forEach((item) => {
        arr.push(item.contract.id)
      })
      let contractIds = arr.join(',')
      let formData = new FormData()
      formData.append('projectId', projectId)
      formData.append('contractIds', contractIds)
      this.$http
        .post('${cqxy}/biz/contract/v1/downloadBatch', formData, 'arraybuffer')
        .then((res) => {
          if (res.status === 200) {
            this.$message.success('合同文件导出成功')
          } else {
            this.$message.error('合同文件导出失败')
          }
        })
    },
    // 行政缴费
    handelPay() {
      let id = this.$route.params.id
      let name = this.$route.params.projectName
      this.$router.push({
        name: 'administrativePay',
        params: {
          projectName: name,
          id: id,
        },
      })
    },
    handleSaveCostConsultation() {
      let params = {
        costConsultation: this.costConsultation,
        id: this.pid,
      }
      this.$http
        .post(
          '${cqxy}/biz/projectManagement/pm/v1/updateCostConsultationById',
          params
        )
        .then((res) => {
          this.getByIdProject(this.pid)
        })
    },
    getByIdProject(id) {
      this.$http
        .post('${cqxy}/biz/projectManagement/pm/v1/detail/' + id)
        .then((res) => {
          this.costConsultation = res.data.value.costConsultation
        })
    },
    handleCommand(params) {
      let data = params.row
      data.alias = this.alias
      sessionStorage.setItem('routerParams', JSON.stringify(data))
      if (params.command == 'pay') {
        this.$router.push({
          name: 'PaymentApproval',
          params: {
            projectName: data.project.projectName,
            id: data.project.id,
          },
        })
      } else if (params.command == 'plan') {
        this.$router.push({
          name: 'fundPlan',
          params: {
            projectName: params.row.project.projectName,
            id: params.row.project.id,
          },
        })
      }
    },
    //重置
    handleReset() {
      this.searchForm.projectId = ''
      this.searchForm.contractNumber = ''
      this.searchForm.name = ''
      this.searchForm.biddingChargeType = ''
      this.searchForm.type = ''
      this.searchForm.typeValue = ''
      this.searchForm.contractReceiver = ''
      this.$refs['searchForm'].resetFields()
      this.pageResult = {
        page: 1,
        pageSize: 20,
        total: 0,
      }
      this.$nextTick(() => {
        this.$refs.AtTable.load()
      })
    },
    //导入后重新加载数据
    load() {
      this.$refs.AtTable.load()
    },
    //导出
    handleExport() {
      let query = []
      let search = {
        project_id_: this.searchForm.projectId,
        'bc.name_': this.searchForm.name,
        contract_number_: this.searchForm.contractNumber,
        'bc.type_value': this.searchForm.typeValue,
        bidding_charge_type_: this.searchForm.biddingChargeType,
      }
      if (!this.isShow) {
        search['pm.ID_'] = this.pid
      }
      for (let i in search) {
        if (search[i]) {
          query.push({
            group: 'advance',
            operation: 'LIKE',
            property: i,
            relation: 'AND',
            value: search[i],
          })
        }
      }
      let param = {
        pageBean: {
          page: 1,
          pageSize: -1,
          showTotal: true,
        },

        querys: query,
        sorter: [],
      }
      req
        .downloadPostCopy('${cqxy}/biz/contract/v1/exportDataToExcel', param)
        .then((res) => {
          if (res.status === 200) {
            this.$message.success('导出成功')
          } else {
            this.$message.error('导出失败')
          }
        })
    },
    //导入
    loadDetailed(data) {
      let newData = data.map((item) => {
        item.contractId = this.form.contract.id
        return item
      })
      this.form.contractItem.push(...newData)
    },
    //导出
    handleExportDetailed() {
      let param = {
        pageBean: {
          page: 1,
          pageSize: -1,
          showTotal: true,
        },
        querys: [],
        sorter: [],
      }
      req
        .downloadPostCopy(
          '${cqxy}/biz/contract/item/v1/exportDataToExcel',
          param
        )
        .then((res) => {
          if (res.status === 200) {
            this.$message.success('导出成功')
          } else {
            this.$message.error('导出失败')
          }
        })
    },
    //上一步
    prevSteps() {
      this.active--
      this.active = this.active
    },
    //下一步
    nextSteps() {
      if (this.active == 0) {
        let _this = this
        let vaitalArr = [
          'project.projectName',
          // 'project.projectCode',
          // 'contract.contractDate',
          // 'contract.type',
          // 'contract.contractNumber',
          // 'contract.name',
          // 'contract.biddingChargeType',
          // 'contract.contractAmount',
          // 'contract.retentionMoney',
          // 'contract.firstParty',
          // 'contract.secondParty',
          // 'contract.thirdParty'
        ]
        Promise.all(
          vaitalArr.map((item) => {
            const p = new Promise((resolve, reject) => {
              _this.$refs.form.validateField(item, (vaild) => {
                resolve(vaild)
              })
            })
            return p
          })
        ).then((result) => {
          result = result.filter((item) => item)
          if (!result.length) {
            this.active++
            this.active = this.active
            this.$refs['form'].clearValidate()
          }
        })
      } else {
        this.active++
        this.active = this.active
        this.$refs['form'].clearValidate()
      }
    },
    // handleDict(val, obj, str) {
    //   console.log(this.form.contract)
    //   if (str === 'zbfs') {
    //     this.form.contract.biddingChargeTypeValue = obj.name
    //   } else if (str === 'htgl-htlb') {
    //     this.form.contract.type = obj.name
    //   } else if (str == 'htgl-htfl') {
    //     this.form.contract.moleValue = obj.name
    //   }
    // },
    handleAdd() {
      this.dialogTitle = '添加'
      this.form = {
        projectId: '',
        contractItem: [],
        project: {
          projectName: '',
          projectCode: '',
        },
        contract: {
          contractBigAmount: '', //金额大写
          type: 'G1', //合同类型
          biddingChargeType: 1, //招标方式
          secondLevelType: 1,
          firstParty: '重庆西永微电子产业园区开发有限公司', //甲方单位
          establishmentRemarks: '',
        },
        accessoryInfo: [],
      }
      this.dialogVisible = true
      if (this.isShow) {
        let selectedProject = this.projectObj.find((item) => {
          if (item.currentProject && item.currentProject == 1) {
            return item.currentProject == 1
          }
        })
        this.form.project.projectName = selectedProject.projectName
        this.form.project.projectCode = selectedProject.projectCode
        this.form.projectId = selectedProject.id
        this.form.contract.projectId = selectedProject.id
        this.costConsultation = selectedProject.costConsultation
      } else {
        //根据项目id查询
        this.form.project.projectName = this.projectObj[0].projectName
        this.form.project.projectCode = this.projectObj[0].projectCode
        this.form.projectId = this.projectObj[0].id
        this.form.contract.projectId = this.projectObj[0].id
      }
    },
    handleRowDBClick(data) {
      this.$http
        .post('${cqxy}/biz/contract/v1/detail/' + data.contract.id)
        .then((res) => {
          if (res.data.state) {
            this.dialogTitle = '修改'
            this.form = {
              // project: {
              //   projectName: '',
              //   projectCode: '',
              // },
              ...res.data.value,
            }
            //明细导入传入合同id

            // this.importDataDetailed.contractId = this.form.contract.id
            // this.importDataDetailed.projectId = this.form.project.id
            this.handleChangeAmount(this.form.contract.contractAmount)
            this.dialogVisible = true
          } else {
            this.$message.error('请求出错,请重新选择')
          }
        })
    },
    handleFocusProject() {
      this.$refs.project.open()
    },
    handleSelectProject(data) {
      this.form.contract.projectId = data.id
      this.form.projectId = data.id
      this.form.project.projectCode = data.projectCode
      this.form.project.projectName = data.projectName
      // this.importDataDetailed.projectId=data.id
      this.$refs.form.clearValidate()
    },
    handleSelect(selection) {
      selection.forEach((item, index) => {
        if (item.project.projectName === '合计') {
          selection.splice(index, 1)
        }
      })
      this.selected.numbers = selection.length
      let total = this.calculationTotal(selection, 'contractAmount')
      this.selected.contractAmount = total
    },
    handleDialogCancel() {
      this.dialogVisible = false
      this.active = 0
      /* 发送一个事件用于侧边栏按钮监听是否显示 */
      this.$bus.$emit('handleAsideBtn', true)
    },
    handleDialogClose() {
      this.dialogVisible = false
      this.active = 0
    },
    handleFile(file) {
      this.form.accessoryInfo = file
    },
    initProjectAll() {
      //初始获取所有项目数据
      if (this.isShow) {
        this.$http.post('${cqxy}/biz/projectManagement/pm/v1/All').then(
          (res) => {
            this.projectObj = res.data.value
          },
          (error) => {
            reject(error)
          }
        )
      } else {
        let params = {
          pageBean: {
            page: 1,
            pageSize: 500,
            total: 0,
          },
          querys: [
            {
              group: 'main',
              operation: 'EQUAL',
              property: 'id',
              relation: 'AND',
              value: this.pid,
            },
          ],
        }
        this.$http
          .post('${cqxy}/biz/projectManagement/pm/v1/page', params)
          .then((res) => {
            if (res.data.state) {
              let resp = res.data.value
              this.projectObj = resp.rows
            }
          })
      }
    },
    handleDialogSubmit() {
      if (this.form.accessoryInfo && this.form.accessoryInfo.length > 0) {
        this.form.accessoryInfo.forEach((item) => {
          if (item.id) {
            delete item.id
          }
        })
      }
      this.loading = true
      this.$http.post('${cqxy}/biz/contract/v1/save', this.form).then((res) => {
        if (res.data.state) {
          this.$refs.form.resetFields()
          this.$message.success(res.data.message)
          this.dialogVisible = false
          this.$refs.AtTable.load()
          this.active = 0
        } else {
          this.$message.error(res.data.message)
        }
        this.loading = false
      })
    },
    loadData(param, cb) {
      let query = []
      let search = {
        project_id_: this.searchForm.projectId,
        'bc.name_': this.searchForm.name,
        contract_number_: this.searchForm.contractNumber,
        'bc.type_': this.searchForm.type,
        bidding_charge_type_: this.searchForm.biddingChargeType,
        'bc.type_value_': this.searchForm.typeValue,
        'bc.contract_receiver_': this.searchForm.contractReceiver,
        // contract_date_: this.searchForm.contractDate,
      }
      if (!this.isShow) {
        search['pm.ID_'] = this.pid
        this.importData.projectId = this.pid
      }
      for (let i in search) {
        if (search[i]) {
          query.push({
            group: 'advance',
            operation: 'LIKE',
            property: i,
            relation: 'AND',
            value: search[i],
          })
        }
      }

      if (param.querys && param.querys.length) {
        param.querys.push(...query)
      } else {
        param.querys = query
      }
      this.$http
        .post('${cqxy}/biz/contract/v1/page', param)
        .then(
          (resp) => {
            let response = resp.data.value
            this.selected = {
              numbers: 0,
              contractAmount: '0',
            }
            let data = response.rows
            let total = this.calculationTotal(data, 'contractAmount')
            this.total.contract.contractAmount = total
            if (data.length !== 0) {
              data.push(this.total)
            }
            this.data = data
            this.pageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total,
            }
          },
          (error) => {
            reject(error)
          }
        )
        .finally(() => {
          if (cb) {
            cb()
          }
        })
    },
    findinfo() {
      this.$refs.AtTable.load()
    },
    changeAmount(val, index) {},
    changePrice(val, index) {},
    addListItem() {
      let length
      length = this.form.contractItem.length
      let newData = {
        key: length + 1,
        contractId: this.form.contract.id,
        subjectName: '',
        amount: 1,
      }
      this.form.contractItem.push(newData)
    },
    deleteTableData(key, id) {
      this.form.contractItem = this.form.contractItem.filter((item) => {
        if (key) {
          return item.key !== key
        } else {
          return item.id !== id
        }
      })
      if (id) {
        let formData = new FormData()
        formData.append('ids', id)
        this.$http
          .post('${cqxy}/biz/contract/item/v1/delete', formData)
          .then((res) => {
            if (res.data.state) {
              this.$message.success(res.data.message)
            } else {
              this.$message.error(res.data.message)
            }
          })
      }
    },
    handleChangeAmount(value) {
      let num = numToCny(value)
      this.form.contract.contractBigAmount = num
    },
    // 计算列表合同金额合计金额
    calculationTotal(data, key) {
      let total = new BigNumber(0)
      if (key && data && data.length !== 0) {
        data.forEach((item) => {
          item = item.contract
          if (item[key]) {
            total = total.plus(item[key])
          } else {
            total = total.plus(0)
          }
        })
      }
      return this.moneyFormatter(total)
    },
    cellClassNameFn(row) {
      // 列表项目名称为【合计】隐藏复选框
      if (row.row.project.projectName === '合计') {
        return 'table-column-hidden'
      }
    },
  },
  // destroyed() {
  //   this.$bus.$off('fileAdded')
  //   this.$bus.$off('fileSuccess')
  // }
}
</script>
<style lang="scss" scoped>
@import '@/assets/css/common.scss';
// /deep/ .el-form--label-top .el-form-item__label {
//   padding: 0 !important;
// }
// /deep/ .el-form-item {
//   margin-bottom: 10px !important;
// }
// /deep/ .el-dialog__body {
//   padding: 5px 20px !important;
// }
// /deep/ .el-dialog {
//   height: 750PX;
// }
/deep/ .el-step.is-simple:not(:last-of-type) .el-step__title {
  max-width: 60% !important;
}
.button-box {
  display: flex;
  justify-content: flex-end;
  // position: absolute;
  // bottom: 30px;
  // right: 30px;
  div {
    padding: 10px;
    background: #2f86ff;
    margin: 10px;
    border-radius: 4px;
    cursor: pointer;
    color: #ffffff;
  }
}
.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  i {
    font-size: 30px;
  }
}
.modelDiv {
  position: absolute;
  width: 1000px;
  height: 700px;
  top: 50px;
  left: 0;
  background-color: rgba($color: #000000, $alpha: 0.2);
}
.btnDetailed {
  display: flex;
  margin-bottom: 20px;
}

.operation-input {
  display: flex;
  width: 100%;
  justify-content: flex-end;
  align-items: center;
  span {
    font-size: 18px;
  }
  .input {
    width: 280px;
    margin-right: 10px;
    /deep/ .el-input--small .el-input__inner {
      height: 38px;
      line-height: 38px;
      font-size: 16px;
    }
  }
}
// /deep/ .el-link--inner i{
//   font-size: 14px;
// }
.show-slected {
  font-size: 18px;
  i {
    font-style: normal;
    font-weight: 700;
    margin: 0 5px;
    color: #f40;
  }
}
/deep/ .table-column-hidden .el-checkbox__input {
  display: none;
}
/deep/ .table-column-hidden .cell > div {
  display: none;
}
</style>
