<template>
    <div class="order-wraper">
        <div class="search-confirm-wrap">
            <div class="search-wrap">
                <div class="search-item">
                    <div class="search-label">仓库</div>
                    <div class="filter_input_wraper">
                        <el-select v-model="value1" filterable clearable placeholder="请选择">
                            <el-option
                              v-for="item in options1"
                              :key="item.stor_id"
                              :label="item.stor_name"
                              :value="item.stor_id">
                          </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="search-item">
                    <div class="search-label search-label_1">日期</div>
                    <div class="filter_input_wraper filter_input_wraper_1">
                        <el-date-picker
                        v-model="date"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                      </el-date-picker>
                    </div>
                </div>
                <div class="search-item">
                    <div class="search-label">单据类型</div>
                    <div class="filter_input_wraper">
                        <el-select v-model="value2" filterable clearable placeholder="请选择">
                            <el-option
                              v-for="item in options2"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                          </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="search-item">
                    <div class="search-label">物料</div>
                    <div class="filter_input_wraper">
                        <input type="text" class="filter-input">
                    </div>
                </div>
                <div class="search-item">
                    <div class="search-label">载具号</div>
                    <div class="filter_input_wraper">
                        <input type="text" class="filter-input">
                    </div>
                </div>
                <div class="search-item flexend">
                    <button class="button button--primary" @click="_getAll">查询</button>
                    <button class="button button--primary" :disabled="disabled1" :class="{'button--defalut': pkId === ''}" @click="toSure">强制确认</button>
                </div>
            </div>
        </div>
        <div class="grid_wraper">
            <table class="filter-table">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>单据号</th>
                        <th>状态</th>
                        <th>类型</th>
                        <th>物料编号</th>
                        <th>物料规格</th>
                        <th>数量(个)</th>
                        <th>单重(g)</th>
                        <th>重量(kg)</th>
                        <th>载具号</th>
                        <th>入库点</th>
                        <th>货位</th>
                        <th>创建时间</th>
                        <th>创建人</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(e, i) in dataList" :key="i" :class="{'selected_icon': pkId === e.bill_code}" @click="toRadio(e)">
                        <td>{{ i+1 }}</td>
                        <td>{{e.bill_code}}</td>
                        <td v-if="e.bill_status === '10'">生成</td>
                        <td v-if="e.bill_status === '20'">分配中</td>
                        <td v-if="e.bill_status === '30'">分配完</td>
                        <td v-if="e.bill_status === '99'">完成</td>
                        <td>{{e.bill_type}}</td>
                        <td>{{e.material_code}}</td>
                        <td>{{e.material_spec}}</td>
                        <td>{{e.qty}}</td>
                        <td>{{e.unit_weight}}</td>
                        <td>{{e.plan_qty}}</td>
                        <td>{{e.storagevehicle_code}}</td>
                        <td>{{e.point_code}}</td>
                        <td>{{e.struct_code}}</td>
                        <td>{{e.create_time}}</td>
                        <td>{{e.create_name}}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>

<script>
import {getBcpStor, getBillType, getAll, bcpInConfirm} from '@config/getData2.js'
export default {
  data () {
    return {
      options1: [],
      value1: '',
      date: [new Date((new Date().getTime() - 24 * 60 * 60 * 1000)), new Date((new Date().getTime() + 24 * 60 * 60 * 1000))],
      options2: [],
      value2: '',
      material_code: '',
      storagevehicle_code: '',
      dataList: [],
      disabled1: false,
      pkId: '',
      pkObj: {}
    }
  },
  methods: {
    // 仓库下拉框
    async _getBcpStor () {
      let res = await getBcpStor()
      this.options1 = [...res.data]
    },
    // 单据类型下拉框
    async _getBillType () {
      let res = await getBillType()
      this.options2 = [...res.data]
    },
    // grid
    async _getAll () {
      let res = await getAll(this.value1, this.date[0], this.date[1], this.material_code, this.storagevehicle_code, this.value2)
      this.dataList = [...res.data]
    },
    toRadio (e) {
      this.pkId = this.pkId === e.bill_code ? '' : e.bill_code
      this.pkObj = this.pkId === e.bill_code ? e : {}
    },
    async toSure () {
      this.disabled1 = true
      if (!this.pkId) {
        this.disabled1 = false
        return
      }
      try {
        let res = await bcpInConfirm(this.pkObj)
        this.toast(res.message)
        this._getAll()
        this.pkId = ''
        this.disabled1 = false
      } catch (e) {
        this.disabled1 = false
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
.grid_wraper
    height calc(100% - 95px)
.filter_input_wraper_1
    width calc(100% - 45px)
.search-label_1
    width 45px
</style>
