<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-collapse :activeKey="['1']">
          <a-collapse-panel key="1" header="基础信息">
            <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 ?tipData.receiverName:'--' }}
              </a-descriptions-item>
            </a-descriptions>
          </a-collapse-panel>
        </a-collapse>
      </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 class="btn-box">
        <a-button :id="'record-cancel'" @click="handleCommonCancel" v-if="isCancel">{{ cancelText }}</a-button>
      </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{
     margin-bottom:10px;
    }
    .btn-box{
      text-align: center;
      margin-top: 30px;
      .ant-btn{
        margin:0 10px;
      }
    }
  }
</style>
