<!-- 联系人履历 -->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :form="form" :editModel="editModel" :api="api" :appendToBody="appendToBody"
                 :title="$t('enterpriseInfoManage.supplierInfoManage.contactRecord')">
      <div class="leftText">
        <span>{{$t('enterpriseInfoManage.supplierInfoManage.modifyTitle')}}</span>
      </div>
      <data-table :operateBtnLayout="operateBtnLayout" :queryParas="queryParas" :sourceData="modifyData"
                  :toolMenuFlag="toolMenuFlag" :columns="modifyColumns" :showPage="showPage" :menuFlag="menuFlag"
                  :headTitle="$t('enterpriseInfoManage.supplierInfoManage.modifyTitle')">
      </data-table>
      <div class="leftText10px">
        <span>{{$t('enterpriseInfoManage.supplierInfoManage.contactTitle')}}</span>
      </div>
      <data-table :operateBtnLayout="operateBtnLayout" :queryParas="queryParas" :sourceData="contactData"
                  :toolMenuFlag="toolMenuFlag" :columns="contactColumns" :showPage="showPage" :menuFlag="menuFlag"
                  :headTitle="$t('enterpriseInfoManage.supplierInfoManage.contactTitle')">
      </data-table>
    </dialog-edit>
  </div>
</template>

<script>
import BaseEdit from '@/pages/baseEditPage'
import * as format from '@/filters/index.js'
import { DialogEdit, DataTable } from 'newepoch-components'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
export default {
  extends: new BaseEdit(),
  name: 'contactRecordEdit',
  components: {
    DialogEdit,
    DataTable
  },
  data () {
    return {
      showPage: false,
      appendToBody: true,
      toolMenuFlag: true,
      menuFlag: false,
      operateBtnLayout: '',
      queryParas: {},
      modifyData: [],
      contactData: [],
      // 修改人联系信息
      modifyColumns: [
        // 修改内容
        {
          prop: 'operateName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.modifyContent,
          width: '1'
        },
        // 原信息
        {
          prop: 'operateBefore',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.primeInfo,
          width: '2'
        },
        // 修改后
        {
          prop: 'operateAfter',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.modified,
          width: '2'
        },
        // 操作人
        {
          prop: 'operateUserName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.operator,
          width: '1'
        },
        // 操作时间
        {
          prop: 'modifyTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.operateTime,
          width: '1',
          format: (row) => { return format.formatDatetime(row.modifyTime, 'yyyy-MM-dd hh:mm') }
        }
      ],
      // 新增联系人信息
      contactColumns: [
        // 修改内容
        {
          prop: 'operateName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.modifyContent,
          width: '1'
        },
        // 原信息
        {
          prop: 'operateBefore',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.primeInfo,
          width: '2'
        },
        // 修改后
        {
          prop: 'operateAfter',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.modified,
          width: '2'
        },
        // 操作人
        {
          prop: 'operateUserName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.operator,
          width: '1'
        },
        // 操作时间
        {
          prop: 'modifyTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.operateTime,
          width: '1',
          format: (row) => { return format.formatDatetime(row.modifyTime, 'yyyy-MM-dd hh:mm') }
        }
      ]
    }
  },
  computed: {
    api () {
      return {}
    }
  },
  methods: {
    // 加载修改联系人Table数据 todo
    loadModifyData (parmes) {
      let that = this
      let employeeKeyIds = []
      parmes.employeeDtoList.forEach(it => {
        employeeKeyIds.push(it.keyId)
      })
      supplierInfoManageApi.invoiceListApi.getRecordList({ employeeIds: employeeKeyIds }).then(res => {
        if (res && res.data) {
          if (res.data.updateRecord) {
            res.data.updateRecord.forEach(it => {
              if (it.operateField === 'birthday') {
                if (it.operateBefore) {
                  it.operateBefore = format.formatDateNull(it.operateBefore)
                } else {
                  it.operateBefore = ''
                }
                if (it.operateAfter) {
                  it.operateAfter = format.formatDateNull(it.operateAfter)
                }
              }
              if (it.operateField === 'gender') {
                it.operateBefore = format.formatDict(it.operateBefore, 'ZD0031')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZD0031')
              }
              if (it.operateField === 'constellation') {
                it.operateBefore = format.formatDict(it.operateBefore, 'ZDC0108')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZDC0108')
              }
              if (it.operateField === 'maritalStatus') {
                it.operateBefore = it.operateBefore.toString() === '-1' ? '' : it.operateBefore
                it.operateAfter = it.operateAfter.toString() === '-1' ? '' : it.operateAfter
                it.operateBefore = format.formatDict(it.operateBefore, 'ZD0003')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZD0003')
              }
              if (it.operateField === 'constellation') {
                it.operateBefore = it.operateBefore.toString() === '0' ? '' : it.operateBefore
                it.operateAfter = it.operateAfter.toString() === '0' ? '' : it.operateAfter
                it.operateBefore = format.formatDict(it.operateBefore, 'ZDC0108')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZDC0108')
              }
              // 生日日历
              if (it.operateField === 'calendarType') {
                it.operateBefore = format.formatDict(it.operateBefore, 'ZDC0107')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZDC0107')
              }
            })
          }
          if (res.data.addRecord) {
            res.data.addRecord.forEach(it => {
              if (it.operateField === 'birthday') {
                if (it.operateBefore) {
                  it.operateBefore = format.formatDateNull(it.operateBefore)
                } else {
                  it.operateBefore = ''
                }
                if (it.operateAfter) {
                  it.operateAfter = format.formatDateNull(it.operateAfter)
                }
              }
              if (it.operateField === 'gender') {
                it.operateBefore = format.formatDict(it.operateBefore, 'ZD0031')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZD0031')
              }
              if (it.operateField === 'constellation') {
                it.operateBefore = format.formatDict(it.operateBefore, 'ZDC0108')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZDC0108')
              }
              if (it.operateField === 'maritalStatus') {
                it.operateBefore = it.operateBefore.toString() === '-1' ? '' : it.operateBefore
                it.operateAfter = it.operateAfter.toString() === '-1' ? '' : it.operateAfter
                it.operateBefore = format.formatDict(it.operateBefore, 'ZD0003')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZD0003')
              }
              if (it.operateField === 'constellation') {
                it.operateBefore = it.operateBefore.toString() === '0' ? '' : it.operateBefore
                it.operateAfter = it.operateAfter.toString() === '0' ? '' : it.operateAfter
                it.operateBefore = format.formatDict(it.operateBefore, 'ZDC0108')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZDC0108')
              }
              // 生日日历
              if (it.operateField === 'calendarType') {
                it.operateBefore = format.formatDict(it.operateBefore, 'ZDC0107')
                it.operateAfter = format.formatDict(it.operateAfter, 'ZDC0107')
              }
            })
          }
          that.modifyData = res.data.updateRecord
          that.contactData = res.data.addRecord
        }
      })
    }
  },
  watch: {
    visible (val) {
      let $this = this
      if (val) {
        $this.loadModifyData(this.form)
      }
    }
  }
}
</script>

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