<template>
  <div class="makeInventory-wrap">
    <a-page-header :ghost="false" @back="handleBack" class="makeInventory-back">
      <!-- 自定义的二级文字标题 -->
      <template slot="subTitle">
        <a id="makeInventory-back-btn" href="javascript:;" @click="handleBack">返回列表</a>
      </template>
      <!-- 操作区，位于 title 行的行尾 -->
      <!-- <template slot="extra">
        <a-button key="1" type="primary" id="makeInventory-print-btn">快速打印</a-button>
        <a-button key="2" id="makeInventory-preview-btn">打印预览</a-button>
        <a-button key="3" type="danger" @click="handleExport" :loading="exportLoading" id="makeInventory-export-btn">导出</a-button>
        <a-button key="4" @click="handleImport" id="makeInventory-import-btn">导入</a-button>
        <a-button key="5" type="link" @click="handleDownImport" id="makeInventory-down-import-btn">下载导入模板</a-button>
      </template> -->
    </a-page-header>
    <!-- 详情 -->
    <a-card size="small" :bordered="false" class="makeInventory-cont">
      <!-- 筛选条件 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
          <a-row :gutter="15">
            <a-col :md="6" :sm="24">
              <a-form-item label="产品编码">
                <a-input id="makeInventory-bundleName" v-model.trim="queryParam.bundleName" allowClear placeholder="请输入产品编码"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="产品名称">
                <a-input id="makeInventory-bundleName" v-model.trim="queryParam.bundleName" allowClear placeholder="请输入产品名称"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="产品类别">
                <a-cascader :options="typeData" expand-trigger="hover" id="makeInventory-state" placeholder="请选择产品类别" allowClear v-model="queryParam.brand" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24" style="margin-bottom: 24px;">
              <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="makeInventory-refresh">查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="makeInventory-reset">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 列表 -->
      <s-table
        class="sTable"
        ref="table"
        size="default"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: 1070 }"
        bordered>
        <!-- 盘点数量 -->
        <template slot="outOfStockNum" slot-scope="text, record">
          <a-input-number
            id="makeInventory-outOfStockNum"
            :value="record.outOfStockNum"
            :precision="0"
            :min="0"
            :max="999999"
            placeholder="请输入" />
        </template>
      </s-table>
    </a-card>
    <a-affix :offset-bottom="0">
      <div style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
        <a-button type="primary" id="makeInventory-submit" size="large" class="button-primary" @click="handleSubmit" style="padding: 0 60px;">提交</a-button>
      </div>
    </a-affix>
  </div>
</template>

<script>
import { STable, VSelect } from '@/components'
export default {
  components: { STable, VSelect },
  data () {
    return {
      queryParam: {
        dataSourceNo: undefined
      },
      exportLoading: false, // 导出loading
      disabled: false, //  查询、重置按钮是否可操作
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
        { title: '产品编码', dataIndex: 'creatDate', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'custName', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '单位', dataIndex: 'mementPay', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '仓库', dataIndex: 'memsentPay', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '仓位', dataIndex: 'memendtPay', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '库存数量', dataIndex: 'tostalP', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '盘点数量', scopedSlots: { customRender: 'outOfStockNum' }, width: 150, align: 'center' },
        { title: '盈亏数量', dataIndex: 'totalNums', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        // return customerBundleDelayList( Object.assign(parameter, this.queryParam) ).then(res => {
        //   const 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
        //   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
          }
          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
          resolve(data)
        })
      },
      typeData: []
    }
  },
  methods: {
    //  返回列表
    handleBack () {
      this.$router.push({ path: '/inventoryManagement/inventoryChecking/list' })
    },
    //  导入
    handleImport () {},
    //  下载导入模板
    handleDownImport () {},
    //  提交
    handleSubmit () {},
    //  重置
    resetSearchForm () {},
    //  导出
    handleExport () {
      const params = this.queryParam
      if (this.oldTime && this.oldTime.length > 0) {
        params.beginOldExpiryDate = moment(this.oldTime[0]).format('YYYY-MM-DD')
        params.endOldExpirydDate = moment(this.oldTime[1]).format('YYYY-MM-DD')
      } else {
        params.beginOldExpiryDate = ''
        params.endOldExpirydDate = ''
      }
      if (this.newTime && this.newTime.length > 0) {
        params.beginDate = moment(this.newTime[0]).format('YYYY-MM-DD')
        params.endDate = moment(this.newTime[1]).format('YYYY-MM-DD')
      } else {
        params.beginDate = ''
        params.endDate = ''
      }
      this.exportLoading = true
      customerBundleExportDelay(params).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()
    }
  }
}
</script>

<style lang="less">
  .makeInventory-cont, .makeInventory-back{
    margin-bottom: 15px;
  }
</style>
