<template>
  <a-modal
    centered
    class="unique-code-modal"
    :footer="null"
    :maskClosable="false"
    v-model="isShow"
    @cancel="isShow=false"
    :width="960">
    <solt>
      <div class="unique-code-tit">查看唯一码（产品编码：Y1602GN，唯一码数量：11）</div>
    </solt>
    <a-card size="small" :bordered="false" class="unique-code-con">
      <!-- 列表 -->
      <s-table
        class="sTable"
        ref="table"
        size="small"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :scroll="{ y: 360 }"
        bordered>
      </s-table>
    </a-card>
    <div class="btn-cont">
      <a-button id="unique-code-modal-back" @click="isShow = false" style="margin-left: 15px;">关闭</a-button>
    </div>
  </a-modal>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { STable } from '@/components'
import { sparePartsDetailList } from '@/api/spareParts'
export default {
  name: 'BulkWarehousingOrderDetailModal',
  mixins: [commonMixin],
  components: { STable },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemSn: {
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return sparePartsDetailList(Object.assign(parameter, { sparePartsSn: 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
            }
          }
          return data
        })
      }
    }
  },
  computed: {
    columns () {
      const arr = [
        { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
        { title: '唯一码', dataIndex: 'productCode', width: '15%', align: 'left', customRender: function (text) { return text || '--' } }
      ]
      return arr
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    }
  }
}
</script>

<style lang="less">
  .unique-code-modal{
    .unique-code-tit{
      padding-bottom:20px;
      margin-bottom:20px;
      border-bottom:1px solid #e8e8e8;
    }
    .btn-cont {
      text-align: center;
      margin: 5px 0 10px;
    }
  }
</style>
