<template>
  <a-modal
    centered
    :footer="null"
    :title="titleInfo"
    v-model="isShow"
    @cancel="isShow=false"
    width="60%">
    <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: '300px' }"
        :scroll="{ y: 600 }"
        :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 () {
    const _this = this
    return {
      spinning: false,
      isShow: this.openModal,
      titleInfo: '出库明细',
      queryParam: {},
      columns: [{ 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 : '--') } },
        { title: '金额', dataIndex: 'outAmount', width: '15%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } }],
      // 加载数据方法 必须为 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
        })
      }
    }
  },
  methods: {
    getAjaxData (obj, tit) {
      this.queryParam = obj
      this.titleInfo = tit || '出库明细'
      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>
