<template>
  <a-modal
    centered
    :footer="null"
    :maskClosable="false"
    title="变更记录"
    v-model="isShow"
    @cancel="isShow=false"
    width="50%">
    <a-collapse :activeKey="['1']">
      <a-collapse-panel key="1" header="记录基本信息">
        <a-descriptions size="small" :column="1">
          <a-descriptions-item label="产品编码">
            {{ detailData&&detailData.product.code || '--' }}
          </a-descriptions-item>
          <a-descriptions-item label="产品名称">
            {{ detailData&&detailData.product.name || '--' }}
          </a-descriptions-item>
        </a-descriptions>
      </a-collapse-panel>
    </a-collapse>
    <a-spin :spinning="spinning" tip="Loading..." style="margin-top:10px;">
      <s-table
        class="sTable fixPagination"
        ref="table"
        size="small"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :scroll="{ y: 500 }"
        :style="{ height: '300px' }"
        :showPagination="false"
        :defaultLoadData="false"
        bordered>
      </s-table>
    </a-spin>
  </a-modal>
</template>

<script>
import { STable } from '@/components'
import { stackPlaceListHistory } from '@/api/product'
export default {
  name: 'ChangeRecordModal',
  components: { STable },
  props: {
    openModal: {
      type: Boolean,
      default: false
    },
    detailData: {
      type: Object,
      default: function () {
        return null
      }
    }
  },
  data () {
    return {
      spinning: false,
      isShow: this.openModal,
      columns: [
        { title: '序号', dataIndex: 'no', width: '10%', align: 'center' },
        { title: '变更时间', dataIndex: 'updateDate', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '变更人', dataIndex: 'creatorName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '货位编号-变更前', dataIndex: 'oldStackPlaceCode', width: '25%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '货位编号-变更后', dataIndex: 'newStackPlaceCode', width: '25%', align: 'center', customRender: function (text) { return text || '--' } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.spinning = true
        delete parameter.tableId
        delete parameter.index
        return stackPlaceListHistory({ productSn: this.detailData.product.productSn, newWarehouseSn: this.detailData.warehouseSn }).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            const no = 0
            for (var i = 0; i < data.length; i++) {
              data[i].no = no + i + 1
            }
            this.disabled = false
          }
          this.spinning = false
          return data
        })
      }
    }
  },
  watch: {
    openModal (nVal, oVal) {
      this.isShow = nVal
    },
    isShow (nVal, oVal) {
      if (!nVal) {
        this.$emit('close')
        this.$refs.table.clearTable()
      } else {
        this.$nextTick(() => {
          this.$refs.table.refresh()
        })
      }
    }
  }
}
</script>

<style>
</style>
