<template>
  <a-modal
    centered
    :footer="null"
    :title="titleInfo"
    v-model="isShow"
    @cancel="isShow=false"
    width="50%">
    <a-spin :spinning="spinning" tip="Loading...">
      <s-table
        class="sTable fixPagination"
        ref="table"
        size="small"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :style="{height: '400px' }"
        :scroll="{ y: 330 }"
        :showPagination="true"
        :defaultLoadData="false"
        bordered>
      </s-table>
    </a-spin>
  </a-modal>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { STable } from '@/components'
import { outDetailList } from '@/api/reportData'
export default {
  name: 'VerifyModal',
  mixins: [commonMixin],
  components: { STable },
  props: {
    openModal: {
      type: Boolean,
      default: false
    },
    itemSn: {
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      spinning: false,
      isShow: this.openModal,
      titleInfo: '出库明细',
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.spinning = true
        const params = Object.assign(parameter, this.queryParam)
        return outDetailList(params).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            const no = (data.pageNo - 1) * data.pageSize
            for (var i = 0; i < data.list.length; i++) {
              data.list[i].no = no + i + 1
            }
            this.disabled = false
          }
          this.spinning = false
          return data
        })
      }
    }
  },
  computed: {
    columns () {
      const _this = this
      const arr = [{ title: '序号', dataIndex: 'no', width: '8%', align: 'center' },
        { title: '类型', width: '15%', dataIndex: 'customTypeDictValue', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '客户名称', dataIndex: 'customName', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '数量', dataIndex: 'outQty', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
      ]
      if (this.$hasPermissions('B_outDetailShow_salesPrice')) {
        arr.push({ title: '金额', dataIndex: 'outAmount', width: '15%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
      }
      return arr
    }
  },
  methods: {
    getAjaxData (obj, titObj) {
      this.queryParam = obj
      if (titObj && Object.keys(titObj).length != 0) {
        this.titleInfo = titObj.tit + '（产品编码：' + titObj.code + '，原厂编码：' + (titObj.origCode || '--') + '，产品尺寸：' + (titObj.size || '--') + '）'
      } else {
        this.titleInfo = '出库明细'
      }
      this.$nextTick(() => {
        this.$refs.table.refresh()
      })
    }
  },
  watch: {
    openModal (nVal, oVal) {
      this.isShow = nVal
    },
    isShow (nVal, oVal) {
      if (!nVal) {
        this.$emit('close')
        this.$refs.table.clearTable()
      }
    }
  }
}
</script>

<style>
</style>
