<template>
  <a-modal
    centered
    class="checkingTipsEdit-modal"
    :footer="null"
    :maskClosable="false"
    title="提示"
    v-model="isShow"
    @cancle="isShow=false"
    width="80%">
    <div class="checkingTipsEdit-header">
      <strong>以下为影响出入库的未完成单据</strong>
      <a-button type="danger" @click="handleExport" :loading="exportLoading" id="checkingTipsEdit-export">导出</a-button>
    </div>
    <!-- 列表 -->
    <s-table
      class="sTable"
      ref="table"
      size="small"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      bordered>
    </s-table>
    <a-divider />
    <div class="checkingTipsEdit-explain">
      <strong>盘点说明：</strong>
      <ul class="checkingTipsEdit-explain-list">
        <li>1、以上影响出入库的未完成单据，不处理也可进行盘点，但建议处理完再进行盘点。</li>
        <li>2、开始盘点到盘点结束期间，所有出入库单据将不能操作。</li>
      </ul>
    </div>
    <div class="btn-cont">
      <a-button type="primary" id="checking-tips-edit-modal-check" @click="handleCheck">开始盘点</a-button>
      <a-button id="checking-tips-edit-modal-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
    </div>
    <checking-type-modal :openModal="openTypeModal" :nowData="nowTypeData" :itemId="itemId" @ok="handleOk" @close="closeModal" />
  </a-modal>
</template>

<script>
import { STable } from '@/components'
import checkingTypeModal from './checkingTypeModal.vue'
// import { checkingTipsSave } from '@/api/checkingTips'
export default {
  name: 'CheckingTipsEditModal',
  components: { STable, checkingTypeModal },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemId: {
      type: [Number, String],
      default: ''
    },
    nowData: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      exportLoading: false, // 导出loading
      columns: [
        { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
        { title: '创建时间', dataIndex: 'createDate', width: 160, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '单号', dataIndex: 'nsso', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '单据类型', dataIndex: 'sort', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '单据状态', dataIndex: 'name', width: 100, align: 'center', customRender: function (text) { return text || '--' } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        // return warehouseAllList( this.queryParam ).then(res => {
        //   const data = res.data
        //   this.disabled = false
        //   return data
        // })
        const _this = this
        return new Promise(function (resolve, reject) {
          const data = {
            pageNo: 1,
            pageSize: 10,
            list: [
              { id: '1', purchaseNo: 'jgqp11111111111', creatDate: '产品1', custName: 'jgqp111123545', totalP: '箭冠品牌', totalNums: '产品分类1', totalPrice: '5', payType: '122' }
            ],
            count: 10
          }
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = i + 1
          }
          _this.disabled = false
          resolve(data)
        })
      },
      openTypeModal: false, //  新增编辑  弹框
      nowTypeData: null //  当前记录数据
    }
  },
  methods: {
    //  详情
    getDetail () {

    },
    //  开始盘点
    handleCheck () {
      this.openTypeModal = true
    },
    //  新增/编辑  成功
    handleOk (type) {
      this.$emit('ok', type)
      this.isShow = false
    },
    //  关闭弹框
    closeModal () {
      this.openTypeModal = false
    },
    //  导出
    handleExport () {
      this.exportLoading = true
      customerBundleExportDelay({}).then(res => {
        this.exportLoading = false
        this.download(res)
      })
    },
    download (data) {
      if (!data) { return }
      const url = window.URL.createObjectURL(new Blob([data]))
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      const a = moment().format('YYYYMMDDHHmmss')
      const fname = '未完成单据_盘点' + a
      link.setAttribute('download', fname + '.xlsx')
      document.body.appendChild(link)
      link.click()
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      } else {
        this.form = {
          name: '',
          sort: ''
        }
      }
    },
    itemId (newValue, oldValue) {
      if (this.isShow && newValue) {
        this.getDetail()
      }
    }
  }
}
</script>

<style lang="less">
  .checkingTipsEdit-modal{
    .ant-modal-body {
    	padding: 40px 40px 24px;
    }
    .checkingTipsEdit-header{
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 20px;
      strong{
        font-size: 15px;
      }
    }
    .checkingTipsEdit-explain{
      strong{
        display: block;
        margin-bottom: 5px;
      }
      .checkingTipsEdit-explain-list{
        list-style: none;
        margin: 0;
        padding: 0;
        li{
          padding: 3px 0;
        }
      }
    }
    .btn-cont {
    	text-align: center;
    	margin: 35px 0 10px;
    }
  }
</style>
