<!--自定义文件盖章任务管理-->
<template>
  <div class="documentSealingTaskManage">
    <up-down-layout :header="$t('documentSealingTaskManage.head')" :handleFlag.sync="handleFlag" :footerFlag.sync="footerFlag">
      <search-form
        @handleFilter="handleFilter"
        @clearParam="clearParam"
        :menuCode="menuId"
        searchPerms="searchPerms"
        :formValue.sync="queryParas"
        :componentList="componentList"
        @selectChanged="selectChanged"
        resetPerms="resetPerms"
        slot="query">
      </search-form>
      <template slot="table">
        <data-table
          :headTitle="$t('documentSealingTaskManage.headCenter')"
          :operateBtnLayout="''"
          :columns="columns"
          :menuFlag="true"
          :queryParas="queryParas"
          :sourceData="sourceData"
          :api="api" v-bind="elHeightObj"
          :loadCount="loadCount">
          <!-- 签章方 -->
          <template slot="stampParty" slot-scope="scope">
            <el-row v-for="(it, index) in scope.data.row.participateList" :key="index">
              <span>{{it.participant | formatDict('SCRS0138')}}</span>
            </el-row>
          </template>
          <!-- 操作 -->
          <el-table-column fixed="right" align="center" :label="$t('common.operate')" width="150px">
            <template slot-scope="scope">
              <!--详情-->
              <auth-button class="iconCircle" size="small" :title="$t('documentSealingTaskManage.details')"
                           :menuCode="menuId" perms="btnDetails" :openPerms="true"
                           icon="iconfont iconview" @click="handleClick(scope.row, 'E')"></auth-button>
            </template>
          </el-table-column>
          <!-- 发起盖章任务 -->
          <template slot="headButton">
            <div class="btn-right">
              <auth-button size="medium" :label="$t('documentSealingTaskManage.startTask')"
                           :menuCode="menuId" perms="btnStartTask" :openPerms="true" icon="iconfont iconzhengshushenhexinxiguanli"
                           @click="handleClick({}, 'C')" type="primary"></auth-button>
            </div>
          </template>
        </data-table>
      </template>
    </up-down-layout>
    <document-sealing-task-manage-edit :visible.sync="editVisible" :form="formItem" :editModel="editModel" @edit-success="handleFilter" @stop-success="handleFilter"></document-sealing-task-manage-edit>
    <document-sealing-task-manage-create :menuCode="menuId" :visible.sync="editVisibleC" :form="formItem" :editModel="editModel" @create-success="handleFilter"></document-sealing-task-manage-create>
  </div>
</template>

<script>
import { upDownLayout, searchForm, DataTable, authButton, SelectProductName, SelectProjectCompanyName,
  SelectCoreEnterprise, SelectFinancialInstitutions, SelectSupplier } from 'newepoch-components'
import BasePage from '@/pages/basePage'
import customizejobApi from '@/api/shourangAssetassignee/customizejobApi'
import SelectFileName from '@/components/element/shourang/SelectFileName'
import DocumentSealingTaskManageEdit from '@/pages/shourang/documentSealingTaskManage/documentSealingTaskManageEdit'
import DocumentSealingTaskManageCreate from '@/pages/shourang/documentSealingTaskManage/documentSealingTaskManageCreate'
import * as format from '@/filters/index'
import mixin from '@/pages/mixin.js'
import { regExp } from '@/validator/index'
import componentsApi from '@/api/componentsApi'

export default {
  extends: new BasePage(),
  mixins: [mixin],
  name: 'documentSealingTaskManageList',
  components: {
    SelectProductName,
    DocumentSealingTaskManageEdit,
    DocumentSealingTaskManageCreate,
    upDownLayout,
    searchForm,
    DataTable,
    authButton,
    SelectProjectCompanyName,
    SelectSupplier,
    SelectFileName
  },
  computed: {
    api () {
      return customizejobApi.assetassigneejob
    }
  },
  data () {
    const labelWidth = '160px'
    return {
      queryParas: {},
      formItem: {},
      editModel: 'E',
      editVisibleC: false,
      editVisible: false,
      footerFlag: true,
      formValue: {},
      sourceData: [],
      componentList: [
        // 产品名称
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.productName,
          value: 'projectId',
          name: 'projectId',
          componentName: SelectProductName,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectProductName,
          labelWidth: labelWidth
        },
        // 期数
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.periodsNum,
          value: 'specialPlanPeriods',
          disabled: false,
          maxlength: '3',
          componentName: 'el-input',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.inputperiodsNum,
          labelWidth: labelWidth
        },
        // 核心企业
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.coreEnterprises,
          value: 'coreEnterpriseId',
          componentName: SelectCoreEnterprise,
          queryName: 'projectId',
          queryValue: 'projectId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectcoreEnterprises,
          labelWidth: labelWidth
        },
        // 计划管理人/再保理银行
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.refactorBank,
          value: 'planningManagerId',
          componentName: SelectFinancialInstitutions,
          queryName: 'projectId',
          queryValue: 'projectId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectrefactorBank,
          labelWidth: labelWidth
        },
        // 资料名称
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.materialName,
          value: 'assetCustomStampConfigId',
          componentName: SelectFileName,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectmaterialName,
          labelWidth: labelWidth
        },
        // 项目公司名称
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.projectCompanyName,
          value: 'debtorId',
          componentName: SelectProjectCompanyName,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectprojectCompanyName,
          labelWidth: labelWidth
        },
        // 总部名称
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.totalName,
          value: 'headquartersId',
          componentName: 'el-select',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selecttotalName,
          labelWidth: labelWidth
        },
        // 供应商名称
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.supplierName,
          value: 'creditorId',
          componentName: SelectSupplier,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectsupplierName,
          labelWidth: labelWidth
        },
        // 签章方
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.stampParty,
          value: 'participant',
          componentName: 'SelectDictionary',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectstampParty,
          labelWidth: labelWidth,
          dictTypeCode: 'SCRS0138',
          store: this.$store
        },
        // 状态
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.status,
          value: 'stampStatus',
          componentName: 'SelectDictionary',
          dictTypeCode: 'stamp_status',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: labelWidth
        }
      ],
      columns: [
        // 产品名称
        {
          prop: 'projectName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.productName,
          width: '200px'
        },
        // 核心企业
        {
          prop: 'coreEnterpriseName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.coreEnterprises,
          width: '150px'
        },
        // 原始权益人
        {
          prop: 'initialOwnersName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.primitivePerson,
          width: '150px'
        },
        // 计划管理人/再保理银行
        {
          prop: 'planningManagerName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.refactorBank,
          width: '200px'
        },
        // 期数
        {
          prop: 'specialPlanPeriods',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.periods,
          width: '60px',
          format: (row) => {
            if (!row.specialPlanPeriods || row.specialPlanPeriods.toString() === '0') return ''
            return row.specialPlanPeriods
          }
        },
        // 签章方
        {
          prop: 'stampParty',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.stampParty,
          width: '160px',
          slot: true
        },
        // 资料名称
        {
          prop: 'assetName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.materialName,
          width: '200px'
        },
        // 状态
        {
          prop: 'stampStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.status,
          width: '160px',
          format: (row) => {
            if (row.stampStatus && row.stampStatus.toString() === '0') return ''
            return format.formatDict(row.stampStatus, 'stamp_status')
          }
        }
      ]
    }
  },
  methods: {
    clearParam () {
      this.queryParas = {
        pageIndex: 1,
        pageSize: 10
      }
      this.selectChangeLocal('1')
    },
    selectChanged (a) {
      if (a.hasOwnProperty('projectIdInfo')) {
        if (a.projectIdInfo && a.projectIdInfo.keyId) {
          this.getTypeById(a.projectIdInfo.keyId)
        } else {
          this.selectChangeLocal('1')
        }
      }
    },
    // 改变选择信息、日期
    selectChangeLocal (isAbs) {
      this.componentList[1].disabled = isAbs !== '1'
      if (this.componentList[1].disabled) {
        this.componentList[1].placeholder = ' '
      } else {
        this.componentList[1].placeholder = this.$i18n.messages[this.$i18n.locale].common.pleaseInput
      }
    },
    // 根据ID获取产品类别
    getTypeById (projectId) {
      componentsApi.productenterprise.getclassify({ projectId: projectId }).then(res => {
        var a = res.data ? res.data.productType : '2'
        this.selectChangeLocal(a)
      })
    },
    handleFilter () {
      if (!this.UtilJs.isEmpty(this.queryParas.specialPlanPeriods) && !regExp.number.test(this.queryParas.specialPlanPeriods)) {
        return this.warning(this.$i18n.messages[this.$i18n.locale].expressDataList.specialPlanPeriodsCheck)
      }
      this.loadCount = this.loadCount + 1
    },
    handleClick (data, model) {
      // this.formItem = Object.assign({}, data)
      this.editModel = model
      if (model === 'E') {
        this.editVisible = true
        this.formItem = Object.assign({}, data)
      } else {
        this.editVisibleC = true
        this.formItem = Object.assign({ assetSources: [], participateList: [] }, data)
      }
    }
  }
}
</script>

<style scoped>
</style>
