<template>
  <div class="auto">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <p class="bg-info text-center" style="padding: 8px;font-size: 20px">已选择{{rowsdata.length}}块表</p>
        <div class="auto select-overspread form-horizontal">
          <div class="col-sm-4 form-group form-input-group" :class="[$v.f_warehouse_id_old.required ? 'has-error' : 'has-success']">
            <label class="control-label">调出仓库</label>
            <input type="text" v-show="false" v-model="model.f_warehouse_id_old" v-validate:f_warehouse_id_old='{required: true }'>
            <v-select :value.sync="model.f_warehouse_id_old" :value-single="true"
                      :options='warehouse' placeholder='请选择'
                      close-on-select search="true">
            </v-select>
          </div>
          <div class="col-sm-4 form-group form-input-group" :class="[$v.f_warehouse_id.required ? 'has-error' : 'has-success']">
            <label class="control-label">调入仓库</label>
            <input type="text" v-show="false" v-model="model.f_warehouse_id" v-validate:f_warehouse_id='{required: true }'>
            <v-select :value.sync="model.f_warehouse_id" :value-single="true"
                      :options='warehouse' placeholder='请选择'
                      close-on-select search="true">
            </v-select>
          </div>
          <div class="col-sm-4 form-group form-input-group">
            <label class="control-label">调拨信息</label>
            <input type="text"  v-model="model.f_operat_info" class="form-control" placeholder="调拨信息"/>
          </div >
        </div>
      </form>
      <div style="text-align:right;margin-top:6px;margin-right:50px;" class="col-sm-12">
        <button class="btn btn-success" @click="confirm()"  :disabled='!$v.valid'>调 拨</button>
      </div>
    </validator>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  export default {
    name: 'MeterAllocation',
    data () {
      return {
        model: {
          f_warehouse_id_old: '',
          f_warehouse_id: '',
          f_operat_type: '调拨',
          f_operat_info: '',

          f_state: '有效',
          f_operator: this.$login.f.name,
          f_filiale: this.$login.f.f_fengongsi,
          f_outlets: this.$login.f.f_parentname,
          f_orgstr:this.$login.f.orgpathstr,
          f_filialeids:this.$login.f.f_orgids
        },
        // 仓库列表
        warehouse: []
      }
    },
    props: {
      rowsdata: Array
    },
    created () {
    },
    ready () {
      this.getwarehouse()
      this.$showMessage("温提示: 请先选择调出仓库在进行表具选择")
    },
    methods: {
      // 获取仓库列表
      async getwarehouse(){
        let data = await this.$resetpost('rs/sql/saleSingleTable', {data: {tablename: 't_warehouse',condition: `f_filialeids = '${this.$login.f.f_orgids}'`}}, {resolveMsg: null, rejectMsg: null})
        let house = []
        for (let row of data.data){
          house.push({label: row.f_warehouse_name,value: row.id})
        }
        this.warehouse = house
      },
      async confirm(){
        if (!this.rowsdata.length){
          this.$showAlert("您还未选择表,请在选择表后在进行这个操作","warning", 1500)
          return
        }
        if (this.f_warehouse_id_old === this.f_warehouse_id){
          this.$showAlert("选择仓库错误,调入调出产库不能相同!","warning", 1500)
          return
        }
        // await this.$resetpost('rs/logic/sale_meterJoin', {model: this.model,rowsdata: this.rowsdata}, {resolveMsg: '入库操作成功', rejectMsg: '入库操作失败'})
        this.init()
      },
      init() {
        this.model.f_warehouse_id_old = ''
        this.model.f_warehouse_id = ''
        this.model.f_operat_info = ''
      }
    },
    watch: {
      'model.f_warehouse_id_old' () {
        this.$dispatch('idsearch',this.model.f_warehouse_id_old)
      }
    }
  }
</script>

<style lang="less">
</style>
