<template>
  <a-card :bordered="false" class="inventoryQueryWarehouseDetail-wrap">
    <!-- 搜索条件 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
        <a-row :gutter="48">
          <a-col :lg="6" :sm="12">
            <a-form-item label="变动类型">
              <a-select id="inventoryQueryWarehouseDetail-bundleNames" placeholder="请选择产品品牌" allowClear v-model="queryParam.brand">
                <a-select-option v-for="item in brandData" :key="item.stationNo" :value="item.stationNo">{{ item.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :sm="12">
            <a-form-item label="单据类型">
              <a-select id="inventoryQueryWarehouseDetail-bundleNames" placeholder="请选择产品品牌" allowClear v-model="queryParam.brand">
                <a-select-option v-for="item in brandData" :key="item.stationNo" :value="item.stationNo">{{ item.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :sm="12">
            <a-form-item label="仓库">
              <a-select id="inventoryQueryWarehouseDetail-bundleNames" placeholder="请选择产品品牌" allowClear v-model="queryParam.brand">
                <a-select-option v-for="item in brandData" :key="item.stationNo" :value="item.stationNo">{{ item.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :sm="12">
            <a-form-item label="单据审核时间">
              <a-range-picker
                  style="width:100%"
                  id="inventoryQueryWarehouseDetail-bundleNamesss"
                  :disabledDate="disabledDate"
                  v-model="queryParam.brand"
                  :format="dateFormat"
                  :placeholder="['开始时间', '结束时间']" />
              </a-form-item>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :sm="12">
            <a-form-item label="单位名称">
              <a-input id="inventoryQueryWarehouseDetail-orderBundleNo" v-model.trim="queryParam.orderBundleNo" allowClear placeholder="请输入单位名称"/>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :sm="12">
            <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="inventoryQueryWarehouseDetail-refresh">查询</a-button>
            <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="inventoryQueryWarehouseDetail-reset">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 合计 -->
    <a-alert type="info" showIcon style="margin-bottom:15px">
      <div class="ftext" slot="message">当前库存总数量（个）：<strong>998</strong>；当前库存总成本(￥)：<strong>2009.00</strong>。</div>
    </a-alert>
    <!-- 列表 -->
    <s-table
      ref="table"
      size="default"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      :showPagination="false"
      bordered>
    </s-table>
    <div class="footer-box">
      <!-- 返回列表 -->
      <a-button type="primary" @click="goList" id="inventoryQueryWarehouseDetail-goback-btn">返回列表</a-button>
    </div>
  </a-card>
</template>

<script>
import moment from 'moment'
// import { customerBundleDelayList, customerBundleExportDelay } from '@/api/FinancialManagement'
import { STable } from '@/components'
export default {
  components: { STable },
  data () {
    return {
      labelCol: { span: 10 },
      wrapperCol: { span: 14 },
      queryParam: { //  查询条件
        orderBundleNo: '', //  订单编号
        orderBundle: {
          custMobile: '' //  客户手机
        },
        bundleName: '', //  套餐名称
        itemName: '', //  服务名称
        brand: undefined,  //  产品品牌
        inventoryNum: false  //  库存数量是否为0
      },
      exportLoading: false, // 导出loading
      disabled: false, //  查询、重置按钮是否可操作
      brandData: [],  //  产品品牌下拉数据
      typeData: [],  //  产品类别下拉数据
      dateFormat: 'YYYY-MM-DD',
      columns: [
        { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
        { title: '产品编码', dataIndex: 'productNum', width: 160, align: 'center' },
        { title: '产品名称', dataIndex: 'productName', width: 200, align: 'center', ellipsis: true },
        { title: '原厂编码', dataIndex: 'productOldNum', width: 160, align: 'center' },
        { title: '入库批次时间', dataIndex: 'productBrand', width: 200, align: 'center' },
        { title: '单据类型', dataIndex: 'productBrand', width: 200, align: 'center' },
        { title: '单据审核时间', dataIndex: 'productBrand', width: 200, align: 'center' },
        { title: '单位名称', dataIndex: 'productBrand', width: 200, align: 'center' },
        { title: '仓库', dataIndex: 'productBrand', width: 200, align: 'center' },
        { title: '仓位', dataIndex: 'productBrand', width: 200, align: 'center' },
        { title: '数量', dataIndex: 'inventoryNum', width: 180, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '总成本', dataIndex: 'inventoryMoney', width: 180, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '总售价', dataIndex: 'inventoryMoneys', width: 180, 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){
          console.log(111)
          const data = {
            pageNo: 1,
            pageSize: 10,
            list: [
              { id: '1', productNum: 'jgqp11111111111', productName: '产品1', productOldNum: 'jgqp111123545', productBrand: '箭冠品牌', productType: '产品分类1', inventoryNum: '5', inventoryMoney: '122' }
            ]
          }
          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)
        })
      }
    }
  },
  methods: {
    // 不可选日期
    disabledDate (date, dateStrings) {
      return date && date.valueOf() > Date.now()
    },
    //  重置
    resetSearchForm () {
      this.queryParam.orderBundleNo = ''
      this.queryParam.orderBundle.custMobile = ''
      this.queryParam.bundleName = ''
      this.queryParam.itemName = ''
      this.oldTime = undefined
      this.newTime = undefined
      this.$refs.table.refresh(true)
    },
    //  返回库存查询列表
    goList(){
      this.$router.push({ path: '/inventoryManagement/inventoryQuery/list' })
    }
  }
}
</script>

<style lang="less">
  .inventoryQueryWarehouseDetail-wrap{
    .footer-box{
      margin: 50px auto 20px;
      text-align: center;
    }
  }
</style>