<template>
  <a-modal
    centered
    class="confirmationDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="详情"
    v-model="isShow"
    @cancle="isShow=false"
    :width="960">
    <div>
      <a-descriptions size="small" :column="3" style="margin-bottom: 10px;">
        <a-descriptions-item label="入库单号">{{ nowData&&nowData.stockPutNo || '--' }}</a-descriptions-item>
        <a-descriptions-item label="入库时间">{{ nowData&&nowData.putTime || '--' }}</a-descriptions-item>
        <a-descriptions-item label="入库类型">{{ nowData&&nowData.putBizTypeDictValue || '--' }}</a-descriptions-item>
      </a-descriptions>
      <s-table
        class="sTable"
        ref="table"
        size="small"
        :rowKey="(record) => record.stockPutSn"
        :columns="columns"
        :data="loadData"
        :defaultLoadData="false"
        bordered>
      </s-table>
      <div class="btn-cont"><a-button id="confirmationDetail-modal-back" @click="isShow = false">返回列表</a-button></div>
    </div>
  </a-modal>
</template>

<script>
import { STable } from '@/components'
import { stockPutDetailList } from '@/api/stockPut'
export default {
  name: 'ConfirmationDetailModal',
  components: { STable },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemSn: {
      type: [Number, String],
      default: ''
    },
    nowData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      detailsData: null, //  详情数据
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
        { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '入库数量(个)', dataIndex: 'putQty', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '入库成本(￥)', dataIndex: 'putCost', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return stockPutDetailList(Object.assign(parameter, { sn: this.itemSn })).then(res => {
          const 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
          return data
        })
      }
    }
  },
  methods: {},
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.$refs.table.clearTable()
      }
    },
    itemSn (newValue, oldValue) {
      if (this.isShow && newValue) {
        const _this = this
        setTimeout(() => {
          _this.$refs.table.refresh(true)
        }, 200)
      }
    }
  }
}
</script>

<style lang="less">
  .confirmationDetail-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .btn-cont {
      text-align: center;
      margin: 5px 0 10px;
    }
  }
</style>
