<template>
  <a-modal
    centered
    class="confirmationDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="详情"
    v-model="isShow"
    @cancel="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.id"
        :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 { commonMixin } from '@/utils/mixin'
import { STable } from '@/components'
import { stockPutDetailList } from '@/api/stockPut'
export default {
  name: 'ConfirmationDetailModal',
  mixins: [commonMixin],
  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, //  详情数据
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return stockPutDetailList(Object.assign(parameter, { sn: this.itemSn })).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
          }
          return data
        })
      }
    }
  },
  computed: {
    // 列表表头
    columns () {
      const arr = [
        { title: '序号', dataIndex: 'no', width: '7%', align: 'center' },
        { title: '产品编码', dataIndex: 'productCode', width: '20%', align: 'left', customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'productName', width: '45%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '入库数量(个)', dataIndex: 'putQty', width: '14%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
      ]
      if (this.$hasPermissions('B_warehousingConfirmationDetail_costPrice')) {
        arr.splice(4, 0, { title: '入库成本', dataIndex: 'putCost', width: '14%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') })
      }
      return arr
    }
  },
  methods: {},
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.$refs.table.clearTable()
        this.$store.state.app.curActionPermission = ''
      }else{
        this.$store.state.app.curActionPermission = 'B_warehousingConfirmationDetail'
        this.$nextTick(()=>{
          this.$refs.table.refresh(true)
        })
      }
    }
  }
}
</script>

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