<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">单据类型</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">
                        <el-select v-model="value3" filterable clearable placeholder="请选择">
                          <el-option
                              v-for="item in options3"
                              :key="item.point_code"
                              :label="item.point_name"
                              :value="item.point_code">
                          </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" v-model="remark">
                    </div>
                </div>
                <div class="search-item_2 flexend">
                    <button class="button button--primary" @click="toInConfirm">确认入库</button>
                    <button class="button button--primary" @click="toSearch">作业查询</button>
                    <button class="button button--primary" @click="toAddBillMater">添加单据物料</button>
                    <button class="button button--primary" @click="toDel">删除一行</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>客户</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(e, i) in dataList" :key="i" :class="{'selected_icon': pkId === e.sale_code}" @click="toRadio(e)">
                        <td>{{i + 1}}</td>
                        <td>{{e.material_code}}</td>
                        <td>{{e.material_name}}</td>
                        <td>{{e.sale_qty}}</td>
                        <td>{{e.qty_unit_name}}</td>
                        <td>{{e.bucketunique}}</td>
                        <td>{{e.sale_code}}</td>
                        <td>{{e.cust_name}}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>

<script>
import { getBcpStor, getBillType, getPoint, confirmIn } from '../../../config/getData1.js'
export default {
  name: 'finishedinstore',
  data () {
    return {
      options1: [],
      value1: '',
      options2: [],
      value2: '',
      options3: [],
      value3: '',
      remark: '',
      dataList: [],
      pkId: '',
      pkObj: {},
      disabled1: false
    }
  },
  beforeRouteLeave (to, from, next) {
    if (to.path === '/home' || to.path === '/login') {
      this.$store.dispatch('setKeepAlive', [])
    }
    next()
  },
  activated () {
    if (this.$store.getters.materArr.length > 0) {
      this.dataList = [...this.dataList, ...this.$store.getters.materArr]
    }
  },
  created () {
    // if (this.$store.getters.materObj !== '') {
    //   this.dataList.push(JSON.parse(this.$store.getters.materObj))
    //   console.log(this.dataList, '2')
    // }
    this._getBcpStor()
    this._getBillType()
    this._getPoint()
  },
  methods: {
    // 仓库下拉框
    async _getBcpStor () {
      let res = await getBcpStor()
      this.options1 = [...res.data]
    },
    // 单据类型下拉框
    async _getBillType () {
      let res = await getBillType()
      this.options2 = [...res.data]
    },
    // 入库点下拉框
    async _getPoint () {
      let res = await getPoint()
      this.options3 = [...res.data]
    },
    toInConfirm () {
      this._confirmIn()
    },
    async _confirmIn () {
      try {
        let res = await confirmIn(this.value1, this.value2, this.value3, this.remark, this.dataList)
        this.toast(res.message)
      } catch (e) {
      }
    },
    toAddBillMater () {
      this.$router.push('/selectfinishedmater')
    },
    toSearch () {
      this.$router.push('/finishedinstoresearch')
    },
    toRadio (e) {
      this.pkId = this.pkId === e.sale_code ? '' : e.sale_code
      this.pkObj = this.pkId === e.sale_code ? e : {}
    },
    toDel () {
      console.log('del')
    }
  }
}
</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>
