<template>
  <a-modal
    centered
    class="record-detail-modal"
    :footer="null"
    :maskClosable="false"
    v-model="isShow"
    :title="modalTit"
    @cancel="isShow=false"
    width="60%">
    <a-spin :spinning="spinning" tip="Loading...">
      <div class="common-main">
        <a-descriptions :column="2">
          <a-descriptions-item label="调拨单号">
            {{ tipData&&tipData.allocateNo }}
          </a-descriptions-item>
          <a-descriptions-item label="调拨类型">
            <span v-if="tipData&&tipData.allocateSortName">{{ tipData.allocateSortName || '--' }}</span>
            <span v-if="tipData&&tipData.allocateTypeName">/{{ tipData.allocateTypeName || '--' }}</span>
          </a-descriptions-item>
          <a-descriptions-item label="调往对象">
            {{ tipData&&tipData.targetName }}
          </a-descriptions-item>
          <a-descriptions-item label="调出仓库">
            {{ tipData&&tipData.warehouseName }}
          </a-descriptions-item>
          <a-descriptions-item label="收货客户名称">
            {{ tipData&&tipData.receiverName }}
          </a-descriptions-item>
        </a-descriptions>
        <div>
          <s-table
            class="sTable"
            ref="table"
            size="small"
            :rowKey="(record) => record.id"
            :columns="columns"
            :data="loadData"
            :defaultLoadData="false"
            :scroll="{ y: 240 }"
            bordered>
          </s-table>
        </div>
        <div class="btn-box">
          <a-button @click="handleCommonCancel" v-if="isCancel">{{ cancelText }}</a-button>
        </div>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
import { STable, VSelect } from '@/components'
import { printLogQueryPage } from '@/api/data'
export default {
  name: 'RecordModal',
  components: { STable, VSelect },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    modalTit: { // 弹框标题
      type: String,
      default: null
    },
    cancelText: { // 取消 按钮文字
      type: String,
      default: '关闭'
    },
    isCancel: { // 是否显示  取消 按钮
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      disabled: false,
      spinning: false,
      tipData: null,
      params: null,
      columns: [
        { title: '序号', dataIndex: 'no', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '打印时间', dataIndex: 'printDate', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '打印人', dataIndex: 'printPersonName', width: '25%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: 'IP', dataIndex: 'printIp', width: '25%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '打印方式', dataIndex: 'printType', width: '20%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        this.spinning = true
        return printLogQueryPage(Object.assign(parameter, this.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: {
    setData (data, params) {
      this.tipData = data
      this.params = params
      this.$nextTick(() => {
        this.$refs.table.refresh(true)
      })
    },
    // 取消
    handleCommonCancel () {
      this.$emit('cancel')
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('cancel')
      }
    }
  }
}
</script>

<style lang="less">
  .record-detail-modal{
    .common-main{
      .btn-box{
        text-align: center;
        margin-top: 30px;
        .ant-btn{
          margin:0 10px;
        }
      }
    }
  }
</style>
