<template>
  <div>
    <up-down-layout :handleFlag.sync="handleFlag" :header="$t('ladingManageList.ladingManage')">
      <search-form @clearParam="clearParam" @handleFilter="queryhandleFilter"
                   @selectChanged="selectChanged"
                   searchPerms="search" resetPerms="reset" :formValue.sync="queryParas" v-model="queryParas"
                   :componentList="componentList" slot="query">
      </search-form>
      <template slot="table">
        <data-table
          :menuFlag="true"
          :btnCreate="false"
          :queryParas="queryParas"
          :btnDels="false"
          :cellStyle="cellStyle"
          :operateBtnLayout="operateBtnLayout"
          :columns="columns"
          :sourceData="sourceData"
          :api="api"
          v-bind="elHeightObj"
          :showSelection="true"
          @sort-change="sortChange"
          @selectRowChange="selectionData"
          :loadCount="loadCount">
          <template slot="headButton">
            <el-row>
              <el-col :span="24" class="textRight">
                <auth-button icon="iconfont iconquxiao" size="medium"
                             type="primary" :label="$t('ladingManageList.cancelConfirmException')"
                             :menuCode="menuId" perms="cancelConfirmException" :openPerms="true" @click="cancelConfirmException"></auth-button>
                <auth-button icon="iconfont iconquerenyichang" size="medium"
                             type="primary" :label="$t('ladingManageList.confirmException')"
                             :menuCode="menuId" perms="confirmException" :openPerms="true" @click="confirmException"></auth-button>
                <auth-button icon="iconfont icondaoru" size="medium" type="primary"
                             :menuCode="menuId" perms="showImport" :openPerms="true"
                             :label="$t('common.import')" @click="showImport"></auth-button>
                <auth-button icon="iconfont iconpiliangqueren" size="medium" type="primary"
                             :menuCode="menuId" perms="batchConfirmation" :openPerms="true" :loading="patchOkloading"
                             :label="$t('ladingManageList.batchConfirmation')" @click="batchConfirmation"></auth-button>
                <auth-button icon="iconfont iconquyuzhuanyuanbeizhu" size="medium"
                             :menuCode="menuId" perms="showAreaCommissionerMemo" :openPerms="true"
                             type="primary" :label="$t('ladingManageList.areaCommissionerMemo')" @click="showAreaCommissionerMemo"></auth-button>
                <auth-button icon="iconfont iconshangchuan" size="medium" type="primary"
                             :menuCode="menuId" perms="showBatchUpload" :openPerms="true"
                             :label="$t('ladingManageList.batchUpload')" @click="showBatchUpload"></auth-button>
                <auth-button icon="iconfont icondaochu" size="medium" type="primary" :loading="loading"
                             :menuCode="menuId" perms="exportData" :openPerms="true"
                             :label="$t('common.export')" @click="exportData"></auth-button>
                <auth-button icon="iconfont iconxiazai1" size="medium" type="primary"
                             :menuCode="menuId" perms="showImportFileHistory" :openPerms="true"
                             :label="$t('ladingManageList.downloadImportFile')" @click="showImportFileHistory"></auth-button>
                <auth-button icon="iconfont iconpiliangjiance" size="medium" type="primary"
                             :menuCode="menuId" perms="batchInspection" :openPerms="true"
                             :loading="batchInspectionLoading" class="XianZhiWidth"
                             :label="$t('ladingManageList.batchInspection')" @click="batchInspection"></auth-button>
                <auth-button icon="iconfont iconshanchu" size="medium" type="danger"
                             :menuCode="menuId" perms="batchDels" :openPerms="true"
                             :label="$t('common.dels')" @click="batchDels"></auth-button>
                <auth-button icon="iconfont icontuihui" size="medium" type="primary"
                             :menuCode="menuId" perms="batchBack" :openPerms="true"
                             :label="$t('ladingManageList.batchBack')" @click="batchBack"></auth-button>
              </el-col>
            </el-row>
          </template>
          <template slot="coreAreaRemark" slot-scope="scope">
            <el-tooltip class="item" effect="dark" :content="scope.data.row.coreAreaRemark" placement="top" :disabled="scope.data.row.coreAreaRemarkFocusStat || !scope.data.row.coreAreaRemark || scope.data.row.coreAreaRemark.length === '0'">
              <el-input maxlength="100" v-model="scope.data.row.coreAreaRemark" size="medium" @blur="memoBlur(scope.data.row)" @focus="coreAreaRemarkFocus(scope.data.row)"></el-input>
            </el-tooltip>
          </template>
          <el-table-column align="center" min-width="360px" :label="$t('common.operate')" fixed="right">
            <template slot-scope="scope">
              <auth-button size="small" class="iconCircle" icon="iconfont iconbianji" v-if="scope.row.pushWorkbenchStatus === '0'"
                           :menuCode="menuId" perms="edit" :openPerms="true"
                           :title="$t('common.edit')" @click="showEdit(scope.row)"></auth-button>
              <btn-upload :classType="true" class="marginLeft10"
                          v-if="scope.row.stopStatus !== '1'"
                          :menuCode="menuId" perms="upload" :openPerms="true" :fileID="scope.row.hasFile"
                          :uploadApi="uploadApi" :rowData="scope.row" @uploadSuccess="uploadSuccess"></btn-upload>
              <btn-download :size="'small'"
                            v-if="scope.row.hasFile === '1'"
                            :fileID="scope.row.fileId"
                            class="marginLeft10"
                            :title="$t('common.downLoad')"
                            :openPerms="true" :menuCode="menuId" perms="downloadBtnPer"
                            :classType="false">
              </btn-download>
              <btn-upload v-if="replenishDataShow(scope.row)"
                          :classType="true" class="marginLeft10" :uploadApi="uploadApi"
                          :menuCode="menuId" perms="replenishData" :openPerms="true"
                          icon="iconfont iconziliaobuchong" :rowData="scope.row"
                          :title="$t('ladingManageList.replenishData')" @uploadSuccess="replenishData"></btn-upload>
              <auth-button size="small" class="iconCircle marginLeft10" icon="iconfont iconlvli"
                           :menuCode="menuId" perms="record" :openPerms="true"
                           :title="$t('ladingManageList.record')" @click="showRecordInfo(scope.row)"></auth-button>
              <!--确认-->
              <auth-button size="small" class="iconCircle" icon="iconfont iconqueren"
                           :menuCode="menuId" perms="confirmation" :openPerms="true"
                           v-if="confirmationCheckFun(scope.row)"
                           :title="$t('ladingManageList.confirmation')" @click="confirmation(scope.row)"></auth-button>
              <!--异常数据调整-->
              <auth-button v-if="scope.row.errorConfirmStatus === '0'" size="small"
                           :menuCode="menuId" perms="abnormalDataAdjustment" :openPerms="true"
                           class="iconCircle" icon="iconfont iconyichangshujutiaozheng"
                           :title="$t('ladingManageList.abnormalDataAdjustment')" @click="showAbnormalDataAdjustment(scope.row)"></auth-button>
            </template>
          </el-table-column>
        </data-table>
      </template>
    </up-down-layout>
    <area-commissioner-memo-edit :rows="selectedRows" :visible.sync="areaCommissionerMemoVisible" editModel="E" :form="item" @refinish="queryhandleFilter" :menuCode="menuId"></area-commissioner-memo-edit>
    <!--异常数据调整-->
    <abnormal-data-adjustment-edit :visible.sync="abnormalDataAdjustmentVisible" editModel="E" :form="item" @close="queryhandleFilter" :menuCode="menuId"></abnormal-data-adjustment-edit>
    <lading-manage-edit :menuCode="menuId" :visible.sync="ladingManageVisible" editModel="E" :form="item" @close="queryhandleFilter"></lading-manage-edit>
    <import-file-history-edit :menuCode="menuId" :visible.sync="importFileHistoryVisible" editModel="V" :form="item"></import-file-history-edit>
    <!-- 履历-->
    <record-info-edit :visible.sync="recordInfoVisible" editModel="V" :form="item"></record-info-edit>
    <import-edit code="10" :menuCode="menuId" :visible.sync="importVisible" editModel="E" :form="item" @close="queryhandleFilter"></import-edit>
    <batch-upload-edit :menuCode="menuId" :visible.sync="batchUploadVisible" editModel="E" :form="item" @close="queryhandleFilter"></batch-upload-edit>
    <confirm-exception-result :visible.sync="singlePushResultVisible" :editModel="'V'" :form="item" @close="queryhandleFilter"></confirm-exception-result>
    <single-push-result :visible.sync="singlePushResultVisibleitem" :editModel="'V'" :form="item"></single-push-result>
    <batch-back-result :visible.sync="batchBackResultVisibleitem" :editModel="'V'" :form="item"></batch-back-result>
  </div>
</template>

<script>
import BasePage from '@/pages/basePage'
import { upDownLayout, searchForm, DataTable, authButton, btnImport, btnBatchUpload, btnDownload,
  SelectCoreEnterpriseCascade, SelectProductName, SelectFinancialInstitutionsCascade,
  SelectAssetsServiceCascade, SelectPrimitiveRightsHolderCascade, SelectSmallArea, SelectPeriodsCascade,
  SelectAreaCommissioner, btnUpload } from 'newepoch-components'
import SelectCompanyName from '@/components/element/shourang/SelectCompanyName'
import ladingManageApi from '@/api/ladingManageApi'
import { IMPORT_API, UPLOAD_API } from '@/constant'
import AreaCommissionerMemoEdit from '@/pages/shouji/ladingManage/areaCommissionerMemoEdit'
import AbnormalDataAdjustmentEdit from '@/pages/shouji/ladingManage/abnormalDataAdjustmentEdit'
import LadingManageEdit from '@/pages/shouji/ladingManage/ladingManageEdit'
import ImportFileHistoryEdit from '@/pages/shouji/ladingManage/importFileHistoryEdit'
import RecordInfoEdit from '@/pages/shouji/ladingManage/recordInfoEdit'
import ImportEdit from '@/pages/shouji/guideSheetManage/importEdit.vue'
import BatchUploadEdit from '@/pages/shouji/ladingManage/batchUploadEdit'
import componentsApi from '@/api/componentsApi'
import * as format from '@/filters/index'
import fileApi from '@/api/fileApi.js'
import { downFile } from '@/utils/devUtils'
import mixin from '@/pages/mixin'
import ConfirmExceptionResult from '@/pages/shouji/guideSheetManage/confirmExceptionResult'
import singlePushResult from '@/pages/shouji/ladingManage/batchConfirmationResult'
import batchBackResult from '@/pages/shouji/ladingManage/batchBackResult'
export default {
  extends: new BasePage(),
  mixins: [mixin],
  name: 'ladingManageList',
  components: {
    ConfirmExceptionResult,
    AreaCommissionerMemoEdit,
    AbnormalDataAdjustmentEdit,
    LadingManageEdit,
    ImportFileHistoryEdit,
    RecordInfoEdit,
    ImportEdit,
    BatchUploadEdit,
    upDownLayout,
    searchForm,
    DataTable,
    authButton,
    btnImport,
    SelectCompanyName,
    btnBatchUpload,
    btnDownload,
    btnUpload,
    singlePushResult,
    batchBackResult
  },
  mounted () {
    if (this.queryParas) {
      this.queryParas = Object.assign({}, { pageIndex: 1, pageSize: 10 })
    }
  },
  // activated () {
  //   if (this.queryParas) {
  //     this.queryParas = Object.assign({}, { pageIndex: 1, pageSize: 10 })
  //   }
  // },
  data () {
    const labelWidth = '165px' // 整体搜索文字大小
    return {
      batchBackResultVisibleitem: false,
      patchOkloading: false,
      loading: false,
      uploadApi: UPLOAD_API,
      areaCommissionerMemoVisible: false,
      abnormalDataAdjustmentVisible: false,
      singlePushResultVisible: false,
      singlePushResultVisibleitem: false,
      ladingManageVisible: false,
      batchInspectionLoading: false,
      importFileHistoryVisible: false,
      recordInfoVisible: false,
      importVisible: false,
      batchUploadVisible: false,
      operateBtnLayout: '',
      expressForm: '',
      currentTotal: 0,
      sourceData: [],
      importApi: IMPORT_API,
      selectedRows: [],
      componentList: [
        // 产品名称
        {
          label: this.$i18n.messages[this.$i18n.locale].common.productName,
          value: 'projectId',
          name: 'projectName',
          componentName: SelectProductName,
          clearable: true,
          labelWidth: labelWidth
        },
        // 期数
        {
          label: this.$i18n.messages[this.$i18n.locale].common.periodsNum,
          value: 'specialPlanPeriodsId',
          name: 'specialPlanPeriodsId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          queryName: 'projectId',
          queryValue: 'projectId',
          componentName: SelectPeriodsCascade,
          clearable: true,
          labelWidth: labelWidth
        },
        // 核心企业
        {
          label: this.$i18n.messages[this.$i18n.locale].common.coreEnterprises,
          value: 'coreEnterpriseId',
          queryName: 'projectId',
          queryValue: 'projectId',
          clearable: true,
          componentName: SelectCoreEnterpriseCascade,
          labelWidth: labelWidth
        },
        // 计划管理人/再保理银行
        {
          label: this.$i18n.messages[this.$i18n.locale].common.refactorBank,
          value: 'planningManagerId',
          queryName: 'projectId',
          queryValue: 'projectId',
          componentName: SelectFinancialInstitutionsCascade,
          clearable: true,
          labelWidth: labelWidth
        },
        // 原始权益人
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.rightsHolder,
          value: 'initialOwnersId',
          queryName: 'projectId',
          queryValue: 'projectId',
          componentName: SelectPrimitiveRightsHolderCascade,
          clearable: true,
          labelWidth: labelWidth
        },
        // 资产服务机构
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.assetServiceOrgan,
          value: 'assetServiceId',
          clearable: true,
          queryName: 'projectId',
          queryValue: 'projectId',
          componentName: SelectAssetsServiceCascade,
          labelWidth: labelWidth
        },
        // 区域
        {
          label: this.$i18n.messages[this.$i18n.locale].common.area,
          value: 'coreArea',
          name: 'coreArea',
          clearable: true,
          multiple: false,
          componentName: SelectSmallArea,
          queryName: 'coreCompanyId',
          queryValue: 'coreEnterpriseId',
          labelWidth: labelWidth
        },
        // 区域专员
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaCommissioner,
          value: 'coreAreaAttache',
          clearable: true,
          componentName: SelectAreaCommissioner,
          labelWidth: labelWidth
        },
        // 项目公司名称
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectCompanyName,
          value: 'debtor',
          clearable: true,
          componentName: 'el-input',
          labelWidth: labelWidth
        },
        // 项目名称
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectName,
          value: 'projectContractName',
          clearable: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          componentName: 'el-input',
          labelWidth: labelWidth
        },
        // 区域编号
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaCode,
          value: 'regionCode',
          clearable: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          componentName: 'el-input',
          labelWidth: labelWidth
        },
        // 提单模式
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.ladingMode,
          value: 'ladingWay',
          clearable: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'ZD0101',
          labelWidth: labelWidth
        },
        // 预提单确认状态
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.advanceLadingStatus,
          value: 'planLadingConfirmStatus',
          componentName: 'SelectDictionary',
          clearable: true,
          dictTypeCode: 'ZD0102',
          labelWidth: labelWidth
        },
        // 正式提单确认状态
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.formalLadingStatus,
          value: 'officalLadingConfirmStatus',
          clearable: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'ZD0103',
          labelWidth: labelWidth
        },
        // 是否确认异常
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.isHandleException,
          value: 'errorConfirmStatus',
          clearable: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'SJ010',
          labelWidth: labelWidth
        }
      ],
      columns: [
        {
          // 付款确认书编号
          prop: 'assetCode',
          align: 'left',
          width: '250px',
          label: this.$i18n.messages[this.$i18n.locale].guideSheetManage.payCode
        },
        // 供应商名称
        {
          prop: 'creditor',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.supplierName,
          width: '200px'
        },
        // 收款人名称
        {
          prop: 'receiverName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.payee,
          width: '200px'
        },
        // 项目名称
        {
          prop: 'projectContractName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectName,
          width: '200px'
        },
        // 区域
        {
          prop: 'coreAreaName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.area,
          width: '120px'
        },
        // 区域编号
        {
          prop: 'regionCode',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaCode,
          width: '160px'
        },
        // 区域专员
        {
          prop: 'coreAreaAttacheName',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaCommissioner,
          width: '100px'
        },
        // 区域专员备注
        {
          prop: 'coreAreaRemark',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaCommissionerMemo,
          width: '200px',
          slot: true
        },
        // 产品名称
        {
          prop: 'projectName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.productName,
          width: '200px'
        },
        // 期数
        {
          prop: 'specialPlanPeriods',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.periodsNum,
          width: '60px',
          format: (row) => {
            if (!row.specialPlanPeriods || row.specialPlanPeriods.toString() === '0') {
              return ''
            } else {
              return row.specialPlanPeriods
            }
          }
        },
        // 核心企业
        {
          prop: 'coreEnterpriseName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.coreEnterprises,
          width: '180px'
        },
        // 计划管理人/再保理银行
        {
          prop: 'planningManagerName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.refactorBank,
          width: '200px'
        },
        // 提单类型
        {
          prop: 'ladingType',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.ladingType,
          width: '100px',
          format: (row) => { return format.formatDict(row.ladingType, 'ZD0100') }
        },
        // 原始权益人
        {
          prop: 'initialOwnersName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.rightsHolder,
          width: '200px'
        },
        // 资产服务机构
        {
          prop: 'assetServiceName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.assetServiceOrgan,
          width: '200px'
        },
        // 应收账款金额 - 保理金额
        {
          prop: 'factoringMoney',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.accountReceivable,
          width: '170px',
          sortable: true,
          format: (row) => { return format.thousandFilter(row.factoringMoney) }
        },
        // 项目公司名称 - 债务人
        {
          prop: 'debtor',
          align: 'left',
          sortable: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectCompanyName,
          width: '200px'
        },
        // 开户行
        {
          prop: 'receiverBank',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.openingBank,
          width: '200px'
        },
        // 收款账号
        {
          prop: 'receiverBankAccount',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.payAccount,
          width: '200px'
        },
        // 合同名称
        {
          prop: 'basicContractName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.contractName,
          width: '200px'
        },
        // 合同编号
        {
          prop: 'basicContractCode',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.contractNum,
          width: '200px'
        },
        // 发票号码
        {
          prop: 'invoiceNo',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.invoiceNum,
          width: '200px'
        },
        // 发票金额
        {
          prop: 'taxExcludingAmount',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.invoiceAmount,
          width: '150px',
          format: (row) => { return format.thousandFilter(row.taxExcludingAmount) }
        },
        {
          // 批次日期
          prop: 'factoringApplyTime',
          align: 'center',
          width: '150px',
          label: this.$i18n.messages[this.$i18n.locale].guideSheetManage.factApplicationDate,
          format: (row) => { return format.formatDateTpcModify(row.factoringApplyTime) }
        },
        // 预提单确认状态
        {
          prop: 'planLadingConfirmStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.advanceLadingStatus,
          width: '120px',
          format: (row) => { return format.formatDict(row.planLadingConfirmStatus, 'ZD0102') }
        },
        // 正式提单确认状态
        {
          prop: 'officalLadingConfirmStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.formalLadingStatus,
          width: '135px',
          format: (row) => { return format.formatDict(row.officalLadingConfirmStatus, 'ZD0103') }
        },
        // 提单方式
        {
          prop: 'ladingWay',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.ladingMode,
          width: '80px',
          format: (row) => { return format.formatDict(row.ladingWay, 'ZD0101') }
        },
        {
          // 检测结果
          prop: 'errorConfirmStatus',
          align: 'center',
          width: '80px',
          label: this.$i18n.messages[this.$i18n.locale].guideSheetManage.detectionResult,
          format: (row) => { return format.formatDict(row.errorConfirmStatus, 'SJ010') }
        }
      ]
    }
  },
  computed: {
    api: function () {
      return ladingManageApi.ladingManageList
    }
  },
  methods: {
    confirmationCheckFun (row) {
      if (!row.planLadingConfirmStatus || !row.officalLadingConfirmStatus) return true
      return ((row.planLadingConfirmStatus && row.planLadingConfirmStatus.toString() !== '1') ||
        (row.officalLadingConfirmStatus && row.officalLadingConfirmStatus.toString() !== '1'))
    },
    coreAreaRemarkFocus (data) {
      this.$set(data, 'coreAreaRemarkFocusStat', true)
    },
    // 根据ID获取产品类别
    getTypeById () {
      componentsApi.productenterprise.getclassify({ projectId: this.queryParas.projectId }).then(res => {
        let disabled = res.data ? res.data.productType : '2'
        this.$set(this.componentList[1], 'disabled', disabled !== '1')
      })
    },
    selectChanged (obj) {
      if (obj.specialPlanPeriodsIdInfo) {
        this.queryParas.specialPlanPeriods = obj.specialPlanPeriodsIdInfo.specialPlanPeriods
      }
      if (obj.projectNameInfo) {
        this.getTypeById()
      }
      if (Object.keys(obj).some(it => it === 'projectNameInfo')) {
        this.clearInfoList()
      }
      // if (Object.keys(obj).some(it => it === 'coreEnterpriseIdInfo')) {
      //   if (!obj.coreEnterpriseIdInfo || !this.queryParas.coreEnterpriseId || obj.coreEnterpriseIdInfo.enterpriseId !== this.queryParas.coreEnterpriseId) {
      //     this.clearcoreArea()
      //   }
      // }
    },
    sortChange (columDate) {
      if (columDate.order) {
        let shenjiang = (columDate.order.indexOf('desc') > 0) ? '1' : '2'
        if (!this.queryParas.sortInfoList) {
          this.queryParas.sortInfoList = [
            {
              field: columDate.prop,
              sortType: shenjiang
            }
          ]
        } else {
          let isYou = false
          this.queryParas.sortInfoList.forEach(it => {
            if (it.field === columDate.prop) {
              it.sortType = shenjiang
              isYou = true
            }
          })
          if (!isYou) {
            this.queryParas.sortInfoList.push({ field: columDate.prop, sortType: shenjiang })
          }
        }
      } else {
        this.queryParas.sortInfoList = this.queryParas.sortInfoList.filter(it => it.field !== columDate.prop)
      }
      this.queryhandleFilter()
    },
    clearParam () {
      for (let key in this.queryParas) {
        this.queryParas[key] = ''
      }
      this.queryParas.pageIndex = 1
      this.queryParas.pageSize = 10
    },
    selectionData (value) {
      this.selectedRows = value
    },
    showEdit (row) {
      this.item = Object.assign({}, row)
      this.ladingManageVisible = true
    },
    // 区域专员备注
    showAreaCommissionerMemo () {
      if (this.selectedRows.length > 0) {
        this.item = {}
        this.areaCommissionerMemoVisible = true
      } else {
        this.warning(this.$i18n.messages[this.$i18n.locale].ladingManageList.selectData)
      }
    },
    // 异常数据调整
    showAbnormalDataAdjustment (row) {
      this.item = Object.assign({}, row)
      this.abnormalDataAdjustmentVisible = true
    },
    showImportFileHistory () {
      this.item = {}
      this.importFileHistoryVisible = true
    },
    showRecordInfo (row) {
      this.item = Object.assign({}, row)
      this.recordInfoVisible = true
    },
    // 导入
    showImport () {
      let obj = {}
      obj.fileName = ''
      this.item = obj
      this.importVisible = true
    },
    showBatchUpload () {
      let obj = {}
      obj.productId = ''
      obj.coreEnterpriseId = ''
      obj.planningManagerId = ''
      obj.specialPlanPeriods = ''
      obj.batchDate = ''
      obj.fileName = ''
      obj.fileList = []
      this.item = Object.assign({}, obj)
      this.batchUploadVisible = true
    },
    // 导出
    exportData () {
      if (this.selectedRows.length > 0) {
        let $this = this
        let arr = []
        this.selectedRows.forEach(it => {
          arr.push(it.keyId)
        })
        $this.loading = true
        ladingManageApi.ladingManageList.export({ assetInfoIds: arr, type: '1' }).then(res => {
          if (res.success) {
            fileApi.file.download({ keyId: res.data }).then(res => {
              downFile(res)
              $this.loading = false
            }).catch(() => {
              $this.loading = false
            })
          } else {
            $this.loading = false
            $this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.exportFaile)
          }
        }).catch(() => {
          $this.loading = false
        })
      } else {
        this.warning(this.$i18n.messages[this.$i18n.locale].ladingManageList.selectData)
      }
    },
    memoBlur (row) {
      this.$set(row, 'coreAreaRemarkFocusStat', false)
      let $this = this
      ladingManageApi.ladingManageList.updateMemo([row]).then(res => {
        if (res.success) {
          $this.success(this.$i18n.messages[this.$i18n.locale].common.updateSuccess)
        } else {
          $this.error(this.$i18n.messages[this.$i18n.locale].common.updateError)
        }
      })
    },
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      if (row.errorFields instanceof Array) {
        let flag = false
        row.errorFields.forEach(it => {
          if (it === column.property) {
            flag = true
          }
        })
        if (flag) {
          return 'color: red'
        } else {
          return ''
        }
      } else {
        return ''
      }
    },
    // 确认异常
    confirmException () {
      if (this.selectedRows.length > 0) {
        let $this = this
        this.$confirm(this.$i18n.messages[this.$i18n.locale].guideSheetManage.whetherAbnormalData, this.$i18n.messages[this.$i18n.locale].common.tip, {
          confirmButtonText: this.$i18n.messages[this.$i18n.locale].guideSheetManage.okbtn,
          cancelButtonText: this.$i18n.messages[this.$i18n.locale].guideSheetManage.cancelbtn,
          type: 'warning'
        }).then(() => {
          let data = JSON.parse(JSON.stringify(this.selectedRows))
          data.forEach(it => {
            it.errorConfirmStatus = '1'
          })
          ladingManageApi.ladingManageList.confirmException(data).then(res => {
            if (res.success && res.data) {
              $this.queryhandleFilter()
              this.item = Object.assign({ single: 0 }, { data: res.data })
              this.singlePushResultVisible = true
              // $this.success(this.$i18n.messages[this.$i18n.locale].guideSheetManage.confirmExceptionOk)
            } else {
              $this.error(this.$i18n.messages[this.$i18n.locale].guideSheetManage.confirmExceptionFailed)
            }
          })
        })
      } else {
        this.warning(this.$i18n.messages[this.$i18n.locale].guideSheetManage.pleaseselectabnormalData)
      }
    },
    // 取消确认
    cancelConfirmException () {
      if (this.selectedRows.length > 0) {
        let $this = this
        this.$confirm(this.$i18n.messages[this.$i18n.locale].guideSheetManage.cancelwhetherAbnormalData, this.$i18n.messages[this.$i18n.locale].common.tip, {
          confirmButtonText: this.$i18n.messages[this.$i18n.locale].guideSheetManage.okbtn,
          cancelButtonText: this.$i18n.messages[this.$i18n.locale].guideSheetManage.cancelbtn,
          type: 'warning'
        }).then(() => {
          let data = JSON.parse(JSON.stringify(this.selectedRows))
          data.forEach(it => {
            it.errorConfirmStatus = '0'
          })
          ladingManageApi.ladingManageList.confirmException(data).then(res => {
            if (res.success && res.data) {
              $this.queryhandleFilter()
              this.item = Object.assign({ single: 1 }, { data: res.data })
              this.singlePushResultVisible = true
              // $this.success(this.$i18n.messages[this.$i18n.locale].guideSheetManage.confirmExceptionOk)
            } else {
              $this.error(this.$i18n.messages[this.$i18n.locale].guideSheetManage.cancelconfirmExceptionFailed)
            }
          })
        })
      } else {
        this.warning(this.$i18n.messages[this.$i18n.locale].guideSheetManage.pleaseselectcancelabnormalData)
      }
    },
    // 确认
    confirmation (row) {
      let $this = this
      let arr = []
      arr.push(row)
      this.$confirm(this.$i18n.messages[this.$i18n.locale].ladingManageList.isModifyCiGokData,
        this.$i18n.messages[this.$i18n.locale].common.tip, {
          confirmButtonText: this.$i18n.messages[this.$i18n.locale].common.confirm,
          cancelButtonText: this.$i18n.messages[this.$i18n.locale].common.cancel,
          type: 'warning'
        }).then(() => {
        ladingManageApi.ladingManageList.batchConfirmation(arr).then(res => {
          if (res.success && res.data) {
            this.success('操作成功！')
            this.item = Object.assign({}, { data: res.data })
            this.singlePushResultVisibleitem = true
            $this.queryhandleFilter()
          } else {
            $this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.okFaile)
          }
        })
      })
    },
    // 批量确认
    batchConfirmation () {
      if (this.selectedRows.length > 0) {
        let $this = this
        this.$confirm(this.$i18n.messages[this.$i18n.locale].ladingManageList.isModifyGokData,
          this.$i18n.messages[this.$i18n.locale].common.tip, {
            confirmButtonText: this.$i18n.messages[this.$i18n.locale].common.confirm,
            cancelButtonText: this.$i18n.messages[this.$i18n.locale].common.cancel,
            type: 'warning'
          }).then(() => {
          this.patchOkloading = true
          ladingManageApi.ladingManageList.batchConfirmation($this.selectedRows).then(res => {
            if (res.success && res.data) {
              this.success('操作成功！')
              this.item = Object.assign({}, { data: res.data })
              this.singlePushResultVisibleitem = true
              $this.queryhandleFilter()
            } else {
              $this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.okFaile)
            }
          }).finally(() => {
            this.patchOkloading = false
          })
        })
      } else {
        this.warning(this.$i18n.messages[this.$i18n.locale].ladingManageList.selectData)
      }
    },
    // 异常检测
    batchInspection () {
      if (this.selectedRows.length > 0) {
        // let flag = false
        let data = []
        this.selectedRows.forEach(it => {
          if (it.errorConfirmStatus !== '1') {
            data.push(it)
          }
        })
        if (data.length === 0) {
          this.warning(this.$i18n.messages[this.$i18n.locale].ladingManageList.pleaseCheckUnData)
          return false
        }
        let $this = this
        this.batchInspectionLoading = true
        ladingManageApi.ladingManageList.batchInspection(data).then(res => {
          $this.success(this.$i18n.messages[this.$i18n.locale].ladingManageList.checkWanCheng)
          if (res.success) {
            if (res.data.length > 0) {
              $this.selectedRows.forEach(it => {
                res.data.forEach(it1 => {
                  if (it.keyId === it1.keyId) {
                    this.$set(it, 'errorFields', it1.errorFields)
                    this.$set(it, 'errorConfirmStatus', it1.errorConfirmStatus)
                  }
                })
              })
            } else {
              $this.warning(this.$i18n.messages[this.$i18n.locale].ladingManageList.okdataNocheck)
            }
          } else {
            $this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.batchFaile)
          }
        }).finally(() => {
          this.batchInspectionLoading = false
        })
      } else {
        this.warning(this.$i18n.messages[this.$i18n.locale].ladingManageList.selectData)
      }
    },
    // 批量删除
    batchDels () {
      let keyIds = []
      this.selectedRows.forEach(it => {
        keyIds.push(it.keyId)
      })
      if (keyIds.length > 0) {
        let $this = this
        this.$confirm(this.$i18n.messages[this.$i18n.locale].ladingManageList.isDeleteData, this.$i18n.messages[this.$i18n.locale].common.tip, {
          confirmButtonText: this.$i18n.messages[this.$i18n.locale].common.confirm,
          cancelButtonText: this.$i18n.messages[this.$i18n.locale].common.cancel,
          type: 'warning'
        }).then(() => {
          ladingManageApi.ladingManageList.batchDelete(keyIds).then(res => {
            if (res.success && res.data) {
              $this.queryhandleFilter()
            } else {
              $this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.batchDeleteDataSuccess)
            }
          })
        })
      } else {
        this.warning(this.$i18n.messages[this.$i18n.locale].ladingManageList.selectData)
      }
    },
    // 批量退回
    batchBack () {
      if (this.selectedRows.length > 0) {
        let $this = this
        this.$confirm(this.$i18n.messages[this.$i18n.locale].ladingManageList.isBackConfirm, this.$i18n.messages[this.$i18n.locale].common.tip, {
          confirmButtonText: this.$i18n.messages[this.$i18n.locale].common.confirm,
          cancelButtonText: this.$i18n.messages[this.$i18n.locale].common.cancel,
          type: 'warning'
        }).then(() => {
          ladingManageApi.ladingManageList.batchBack($this.selectedRows).then(res => {
            if (res.success && res.data) {
              $this.queryhandleFilter()
              this.item = Object.assign({}, { data: res.data })
              // $this.success(this.$i18n.messages[this.$i18n.locale].ladingManageList.batchBackSuccess)
              this.batchBackResultVisibleitem = true
            } else {
              $this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.batchBackFaile)
            }
          })
        })
      } else {
        this.warning(this.$i18n.messages[this.$i18n.locale].ladingManageList.selectData)
      }
    },
    uploadSuccess (returnData) {
      let $this = this
      let obj = {}
      obj.assetLadingPaymentConfirmId = returnData.rowData.keyId
      obj.fileId = returnData.fileID
      ladingManageApi.ladingManageList.uploadSuccess(obj).then(res => {
        if (res.success && res.data) {
          $this.success(this.$i18n.messages[this.$i18n.locale].common.uploadSuccess)
          $this.queryhandleFilter()
        } else {
          $this.error(this.$i18n.messages[this.$i18n.locale].common.uploadError)
        }
      })
    },
    replenishDataShow (row) {
      return row.stopStatus !== '1' && row.hasFile && row.hasFile === '1'
    },
    replenishData (returnData) {
      let $this = this
      let obj = {}
      obj.assetLadingPaymentConfirmId = returnData.rowData.keyId
      obj.fileId = returnData.fileID
      ladingManageApi.ladingManageList.replenishData(obj).then(res => {
        if (res.success && res.data) {
          $this.success(this.$i18n.messages[this.$i18n.locale].common.uploadSuccess)
          $this.queryhandleFilter()
        } else {
          $this.error(this.$i18n.messages[this.$i18n.locale].common.uploadError)
        }
      })
    },
    clearInfoList () {
      this.$set(this.componentList[1], 'disabled', false)
      delete this.queryParas.coreEnterpriseId
      delete this.queryParas.planningManagerId
      delete this.queryParas.initialOwnersId
      delete this.queryParas.assetServiceId
      delete this.queryParas.coreArea
      delete this.queryParas.specialPlanPeriodsId
      delete this.queryParas.specialPlanPeriods
      if (!this.queryParas.projectId) {
        delete this.queryParas.projectId
      }
    },
    clearcoreAreaId () {
      delete this.queryParas.coreArea
      if (!this.queryParas.coreEnterpriseId) {
        delete this.queryParas.coreEnterpriseId
      }
    },
    queryhandleFilter () {
      if (!this.UtilJs.isEmpty(this.queryParas.debtor)) {
        this.queryParas.debtor = this.queryParas.debtor.trim()
      }
      if (!this.UtilJs.isEmpty(this.queryParas.projectContractName)) {
        this.queryParas.projectContractName = this.queryParas.projectContractName.trim()
      }
      if (!this.UtilJs.isEmpty(this.queryParas.regionCode)) {
        this.queryParas.regionCode = this.queryParas.regionCode.trim()
      }
      this.handleFilter()
    }
  },
  watch: {
    // 'queryParas.projectId' (n, o) {
    //   this.$set(this.componentList[1], 'disabled', false)
    //   delete this.queryParas.coreEnterpriseId
    //   delete this.queryParas.planningManagerId
    //   delete this.queryParas.initialOwnersId
    //   delete this.queryParas.assetServiceId
    //   delete this.queryParas.coreAreaId
    //   delete this.queryParas.specialPlanPeriodsId
    // },
    'queryParas.coreEnterpriseId' (n, o) {
      this.clearcoreAreaId()
    }
  }
}
</script>

<style lang="scss" scoped>
  @import '~@/styles/shouji/ladingManage/ladingManageList.scss';
</style>
