<template>
  <dialog-edit :visible.sync="dialogVisible" :editModel="editModel" :title="$t('ladingNoticeHandle.dialogHead')"
               width="800px" :api="api" :form="form" :footerBtnShow="false" :appendToBody="true">
    <div>
      <data-table :deleteApi="api"
                  :handleFlag.sync="handleFlag"
                  :queryParas="queryParas"
                  :sourceData.sync="sourceData"
                  :loadCount.sync="loadCount"
                  :columns="columns"
                  :showPage ="false"
                  operateBtnLayout="">
        <template slot="headButton">
          <span align="left">{{$t('ladingNoticeHandle.updateInfo')}}</span>
        </template>
      </data-table>
    </div>
    <template slot="footer">
      <auth-button class="upButton" type= "" size=""
                   :menuCode="menuCode" perms="handleDetailClose" :openPerms="true"
                   :label="$t('common.close')" @click="dialogVisible = false"></auth-button>
    </template>
  </dialog-edit>
</template>

<script>
import { DataTable, authButton, DialogEdit } from 'newepoch-components'
import BasePage from '@/pages/baseEditPage'
import ladingNoticeManageApi from '@/api/shouji/ladingNoticeManageApi'
import * as format from '@/filters/index'

export default {
  extends: new BasePage(),
  components: {
    DialogEdit,
    DataTable,
    authButton
  },
  props: {
    menuCode: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      loadCount: 0,
      handleFlag: true,
      queryParas: {
      },
      columns: [
        {
          // 更新时间
          prop: 'updateDate',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingNoticeHandle.updateDate
        },
        {
          // 更新项目
          prop: 'updateProject',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingNoticeHandle.updateProject
        },
        {
          // 更新前内容
          prop: 'beforeUpdate',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingNoticeHandle.beforeUpdate
        },
        {
          // 更新后内容
          prop: 'afterUpdate',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingNoticeHandle.afterUpdate
        },
        {
          // 更新人
          prop: 'modifyUserName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingNoticeHandle.modifyUserName
        }
      ],
      sourceData: []
    }
  },
  computed: {
    api () {
      return ladingNoticeManageApi.ladingNoticeManageListApi
    }
  },
  watch: {
    dialogVisible (n) {
      if (n) {
        this.api.getRecordBykeyId(this.form.handleId).then(res => {
          this.sourceData = []
          let temp = res.data
          temp.forEach(it => {
            it.detailList.forEach(it1 => {
              let oldValue = it1.oldValue
              let value = it1.value
              if (it1.fieldName === 'modifyTime' || it1.fieldName === 'createHistoryTime' ||
                it1.fieldName === 'planLadingEndTime' || it1.fieldName === 'planLadingBeginTime') {
                oldValue = format.formatCheckDatetime(oldValue)
                value = format.formatCheckDatetime(value)
                oldValue = oldValue.indexOf('1900') >= 0 ? '' : oldValue
                value = value.indexOf('1900') >= 0 ? '' : value
              } else if (it1.fieldName === 'planLadingEndAmount' || it1.fieldName === 'planLadingBeginAmount') {
                oldValue = format.thousandFilter(oldValue)
                value = format.thousandFilter(value)
              } else if (it1.fieldName === 'ifsLading') {
                oldValue = format.formatDict(oldValue, 'ZD0003')
                value = format.formatDict(value, 'ZD0003')
              }
              if (it1.fieldName.indexOf('Id') < 0) {
                this.sourceData.push({
                  updateDate: format.formatCheckDatetime(it1.createHistoryTime),
                  updateProject: it1.name,
                  beforeUpdate: oldValue,
                  afterUpdate: value,
                  modifyUserName: it1.modifyUserName
                })
              }
            })
          })
        })
      }
    }
  }
}
</script>
<style scoped lang="scss">
  @import '~@/styles/sj/ladingHandle/handleDetail.scss';
</style>
