<template>
  <dialog-edit
    :visible.sync="dialogVisible"
    :title="$t('chargeback.return_form')"
    :editModel="editModel"
    :form="form"
    :api="api"
  >
    <data-table
        :api="api"
        :headTitle="$t('chargeback.return_form_list')"
        operateBtnLayout
        :sourceData.sync="sourceData"
        :columns="columns"
        :loadCount.sync="loadCount"
        :showPage="false"
        :queryParas="queryParas"
      >
       <template slot="headButton">
           <dym-form
             style="margin-top: 16px"
            :menuCode="menuId"
            :formValue.sync="queryParas"
            :componentList="searchList"
          >
          </dym-form>
       </template>
      </data-table>
  </dialog-edit>
</template>

<script>
import BaseEditPage from '@/pages/baseEditPage'
import { DialogEdit, dymForm, DataTable } from 'newepoch-components'
import { setTimeout } from 'timers'
import * as format from '@/filters'
import chargebackApi from '@/api/chargeback'
export default {
  extends: new BaseEditPage(''),
  components: {
    DialogEdit,
    dymForm,
    DataTable
  },
  computed: {
    api () {
      return chargebackApi.dataApi
    }
  },
  data () {
    return {
      queryParas: {},
      sourceData: [],
      searchList: [
        {
        // 付款确认书编号
          label: this.$i18n.messages[this.$i18n.locale].chargeback.pay_code,
          value: 'assetCode',
          disabled: true,
          placeholder: '请输入',
          componentName: 'el-input',
          cols: [10, 10, 10, 10],
          labelWidth: '160px'
        },
        {
        // 资料名称
          label: this.$i18n.messages[this.$i18n.locale].chargeback.data_name,
          value: 'fileName',
          disabled: true,
          placeholder: '请输入',
          componentName: 'el-input',
          cols: [10, 10, 10, 10],
          labelWidth: '160px'
        } ],
      columns: [
        {
          // 快递公司
          prop: 'expressCompany',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .courier_company,
          format: row => format.formatDict(row.expressCompany, 'L0007')
        }, {
          // 快递单号
          prop: 'expressNumber',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .courier_number
        }, {
          // 接收类型
          prop: 'dataType',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .receiving_type,
          format: row => format.formatDict(row.dataType + '', 'L0001')
        }, {
          // 本次份数
          prop: 'validNum',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .current_num
        }, {
          // 来源
          prop: 'source',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .source,
          format: row => format.formatDict(row.source + '', 'L0006')
        }, {
          // 来源人
          prop: 'sourceUserId',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .source_person,
          format: row => format.formatValueNull(row.sourceUserId)
        }, {
          // 登记时间
          prop: 'registerTime',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .register_time,
          format: row => format.formatDateNull(row.registerTime, 'yyyy-MM-dd hh:mm:ss')
        }, {
          // 登记人
          prop: 'registerName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .register_person
        }, {
          // 备注
          prop: 'memo',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .remarks
        }
      ],
      loadCount: 0
    }
  },
  methods: {
    loadData () {
      const { fileName, assetCode } = this.form
      let Obj = { fileName, assetCode }
      let roles = this.$store.getters.sourceUSer
      this.api.getDetails(Obj).then(res => {
        this.sourceData = res.data
        this.sourceData.forEach(item => {
          roles.forEach((issue, index) => {
            if (item.source + '' === issue.roleName) {
              issue.userList.forEach(user => {
                if (item.sourceUserId === user.userId) {
                  item.sourceUserId = user.nickName
                }
              })
            }
          })
        })
      })
    }
  },
  watch: {
    visible (val) {
      if (val) {
        this.queryParas = this.form
        this.loadData()
      } else {
        setTimeout(() => {
          this.queryParas = {}
        }, 300)
      }
    }
  }
}
</script>
