<template>
  <a-modal
    centered
    class="financialPaymentDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="详情"
    v-model="isShow"
    @cancel="isShow=false"
    width="70%">
    <!-- 详情 -->
    <div class="mainContent">
      <a-spin :spinning="spinning" tip="Loading...">
        <a-collapse :activeKey="['1']">
          <a-collapse-panel key="1" header="基础信息">
            <a-descriptions :column="3">
              <a-descriptions-item label="销售单号">{{ (detailsData&&detailsData.salesBillNo) || '--' }}</a-descriptions-item>
            </a-descriptions>
          </a-collapse-panel>
        </a-collapse>
        <a-alert type="info" style="margin: 10px 0" v-if="detailsData">
          <div slot="message">
            缺货总款数 <strong>{{ (detailsData.totalCategory || detailsData.totalCategory==0) ? detailsData.totalCategory : '--' }}</strong> ，
            缺货总数量 <strong>{{ (detailsData.totalQty || detailsData.totalQty==0) ? detailsData.totalQty : '--' }}</strong>
            ，缺货总售价<strong>{{ (detailsData.totalAmount || detailsData.totalAmount==0) ? toThousands(detailsData.totalAmount,2) : '--' }}</strong>
          </div>
        </a-alert>
        <!-- 列表 -->
        <s-table
          class="sTable"
          ref="table"
          size="small"
          :rowKey="(record) => record.id"
          :columns="columns"
          :data="loadData"
          :defaultLoadData="false"
          bordered>
        </s-table>
      </a-spin>
    </div>
  </a-modal>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { salesOosQueryDetailList } from '@/api/reportData.js'
import { STable } from '@/components'
export default {
  name: 'FinancialPaymentDetailModal',
  mixins: [commonMixin],
  components: { STable },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    }
  },
  data () {
    const _this = this
    return {
      isShow: this.openModal, //  是否打开弹框
      spinning: false,
      columns: [
        { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
        { title: '产品编码', dataIndex: 'productCode', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'productName', width: '18%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
        // { title: '仓库', dataIndex: 'warehouseName', width: '18%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '原厂编码', dataIndex: 'origCode', width: '13%', align: 'center', customRender: function (text) { return text && text != ' ' ? text : '--' } },
        { title: '缺货数量', dataIndex: 'qty', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '缺货金额', dataIndex: 'totalAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
        { title: '单位', dataIndex: 'unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } }
      ],
      detailsData: null,
      loadData: parameter => {
        this.spinning = true
        const params = Object.assign(parameter, this.queryParam, { salesOosBillSn: this.detailsData.salesOosBillSn })
        return salesOosQueryDetailList(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.spinning = false
          return data
        })
      }
    }
  },
  methods: {
    //  获取详情
    getDetail (obj) {
      this.detailsData = obj
      this.$nextTick(() => {
        this.$refs.table.refresh()
      })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.detailsData = null
      }
    }
  }
}
</script>

<style lang="less">
  .financialPaymentDetail-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
    .printBox{
      width:100%;
      text-align:right;
      margin-bottom:10px;
    }
  }
</style>
