<!-- 资料特殊性--一览 -->
<template>
  <div class="crm-main">
    <data-table :api="api" :headTitle="$t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfoHeadTitle')" :operateBtnLayout="operateBtnLayout"
                :queryParas="queryParas" :sourceData.sync="sourceData" :showSelection="showSelection" :loadCount.sync="loadCount"
                :menuFlag="false" @selectRowChange="selectRowChange" :columns="columns" :showPage="false"
                :selectTable="selectTable" @getTableData="getTableData">
      <template slot="headButton">
        <el-row>
          <el-col :span="24" class="btn-right">
            <auth-button type="primary" icon="iconfont iconxinzeng" :label="$t('enterpriseInfoManage.supplierInfoManage.create')"
                         size="medium" @click="showCreate"
                         :menuCode="menuId" perms="dataCreate" :openPerms="true"></auth-button>
            <auth-button type="danger" icon="iconfont iconshanchu"
                         :label="$t('enterpriseInfoManage.supplierInfoManage.del')" size="medium" @click="delBatch"
                         :menuCode="menuId" perms="dataDelete" :openPerms="true"></auth-button>
            <btn-export btnSize="medium" templateCode="fincrm002" :xhr="$xhr" :queryParas="materialList"
                        :menuCode="menuId" perms="import" :openPerms="true"></btn-export>
          </el-col>
        </el-row>
      </template>
      <!-- 操作 -->
      <el-table-column :label="$t('common.operate')" align="center" width="135px" fixed="right">
        <template slot-scope="scope">
          <auth-button v-if="scope.row.publishStatus === '否' || scope.row.publishStatus === '0'" class="iconCircle" icon="iconfont iconbianji"
                       :title="$t('common.edit')" @click="updateEvent(scope.row)"
                       :menuCode="menuId" perms="dataEdit" :openPerms="true"></auth-button>
          <btn-download v-if="scope.row.assetFileId && scope.row.assetFileId !== '0'" :xhr="$xhr" :store="$store" :fileID="scope.row.assetFileId"
                        :menuCode="menuId" perms="dataDownload" :openPerms="true"></btn-download>
        </template>
      </el-table-column>
    </data-table>
    <!-- 新增/编辑-->
    <data-specificity-info-edit :visible.sync="showContact" :menuId="menuId" :form="item" :editType="editType"
                                :editModel="editModel" @handleFilter="handleFilter"></data-specificity-info-edit>
  </div>
</template>

<script>
import BasePage from '@/pages/basePage'
import storage from '@/utils/storage'
import * as format from '@/filters/index.js'
import { upDownLayout, DataTable, authButton, btnExport, btnDownload } from 'newepoch-components'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
import SelectArea from '@/components/element/enterpriseInfoManage/SelectArea.vue'
import DataSpecificityInfoEdit from '@/pages/enterpriseInfoManage/supplierInfoManage/dataSpecificityInfoEdit.vue'
export default {
  extends: new BasePage(),
  name: 'supplierInfoManageList',
  components: {
    upDownLayout,
    DataTable,
    authButton,
    SelectArea,
    DataSpecificityInfoEdit,
    btnExport,
    btnDownload
  },
  props: {
    editType: {
      type: String,
      default () {
        return '1'
      }
    }
  },
  data () {
    return {
      handleFlag: true,
      menuFlag: true,
      showContact: false,
      showSelection: true,
      accountFlag: false,
      showProfile: false,
      accountModel: '',
      profileModel: '',
      operateBtnLayout: '',
      sourceData: [],
      queryParas: {
        enterpriseId: '',
        enterpriseName: ''
      },
      materialList: {
        api: {
          sqlfig: []
        }
      },
      columns: [
        // 核心企业
        {
          prop: 'coreEnterpriseName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.coreEnterprise,
          width: '200px'
        },
        // 资料文件
        {
          prop: 'assetFileName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.dataFile,
          width: '200px'
        },
        // 审核特殊点
        {
          prop: 'approvePoint',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.auditSpecialPoints,
          width: '300px'
        },
        // 保理专员建议解决方式
        {
          prop: 'commissionerSolutions',
          align: 'left',
          label: this.editType === '1' ? this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.factoringSolution : this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.areaConSolution,
          width: '300px'
        },
        // 审核环节
        {
          prop: 'approveSegment',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.auditLink,
          width: '100px',
          format: (row) => {
            if (row.approveSegment === '0') {
              return ''
            } else {
              return format.formatDict(row.approveSegment, 'approve_segment')
            }
          }
        },
        // 单证解决方式
        {
          prop: 'documentSolution',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.documentSolution,
          width: '200px'
        },
        // 是否发布
        {
          prop: 'publishStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.whetherIssue,
          width: '100px',
          format: (row) => { return format.formatDict(row.publishStatus, 'ZD0003') }
        },
        // 备注
        {
          prop: 'memo',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.remarks,
          width: '300px'
        },
        // 时间
        {
          prop: 'addTime',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.time,
          width: '150px',
          format: (row) => { return format.formatDateMinute(row.addTime) }
        }
      ]
    }
  },
  computed: {
    api () {
      return supplierInfoManageApi.specialMaterial
    },
    menuId () {
      return storage.getLocal('params').menuId
    }
  },
  mounted () {
    this.queryParas.enterpriseId = storage.getLocal('params').enterpriseId
    this.handleFilter()
  },
  activated () {
    this.queryParas.enterpriseId = storage.getLocal('params').enterpriseId
    this.handleFilter()
  },
  methods: {
    getTableData (list) {
      let dataList = this.copyData(list)
      dataList.forEach(it => {
        it.approveSegment = format.formatDict(it.approveSegment, 'approve_segment')
        it.publishStatus = format.formatDict(it.publishStatus, 'ZD0003')
        it.addTime = format.formatDateMinute(it.addTime)
      })
      this.materialList.api.sqlfig = dataList
      this.materialList.api.userName = this.$store.getters.nikeName
    },
    copyData (data) {
      var obj = {}
      obj = JSON.parse(JSON.stringify(data))
      return obj
    },
    // 复选框勾选数据
    selectRowChange (val) {
      this.selectedRows = val
    },
    // 勾选框禁用
    selectTable (row) {
      return row.publishStatus === '否' || row.publishStatus === '0'
    },
    // 新增特殊资料
    showCreate () {
      this.editModel = 'C'
      this.item = {
        enterpriseId: this.queryParas.enterpriseId,
        enterpriseName: storage.getLocal('params').enterpriseName,
        publishStatus: '0'
      }
      this.showContact = true
    },
    // 修改特殊资料
    updateEvent (data) {
      this.editModel = 'E'
      if (data.approveSegment === '-1') {
        data.approveSegment = ''
      }
      this.item = Object.assign({}, data)
      this.showContact = true
    },
    // 批量删除
    delBatch () {
      if (this.selectedRows.length === 0) {
        this.warning(this.$i18n.messages[this.$i18n.locale].common.delSelectedTip)
        return
      }
      let arr = this.selectedRows.map(it => {
        return it.keyId
      })
      let $this = this
      $this.$confirm(this.$i18n.messages[this.$i18n.locale].common.confirmTip, this.$i18n.messages[this.$i18n.locale].common.warningTip, {
        type: 'warning'
      }).then(() => {
        $this.api.batchDel({ keyIds: arr }).then(res => {
          if (res && res.data) {
            $this.success(this.$i18n.messages[this.$i18n.locale].common.delSuccess)
            $this.handleFilter()
          } else {
            $this.error(this.$i18n.messages[this.$i18n.locale].common.delFailure)
          }
        })
      }).catch(() => {})
    }
  }
}
</script>

<style scoped lang="scss">
  @import '~@/styles/enterpriseInfoManage/supplierInfoManage/supplierInfoManageList.scss';
</style>
