<template>
  <div class="auto">
    <form  class="form-horizontal">
      <p class="bg-info text-center">更改抄表员</p>
    <validator name='v'>
      <div class="row">
        <div class="form-group form-input-group col-sm-4" :class="[$v.inputtor.required ? 'select-error' : '']">
          <label for="f_inputtor" class="col-sm-2 control-label">新抄表员:</label>
          <div class="col-sm-2" id="f_inputtor">
            <input type="text" v-show="false" v-model="$refs.inputtor.selectedItems" v-validate:inputtor='{required: true }'>
            <v-select id="f_inputtor"
                      v-model="model.f_inputtor"
                      placeholder='抄表员'
                      :value.sync="model.f_inputtor"
                      :options='inputtores'
                      close-on-select clear-button v-ref:inputtor>
            </v-select>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="form-group form-input-group col-sm-12">
          <label for="f_change_cause" class=" col-sm-2 control-label">修改原因:</label>
          <div class="col-sm-10" id="f_change_cause">
            <textarea class="form-control"  v-model="model.f_reason" rows="3" placeholder="请填写原因"></textarea>
          </div>
        </div>
      </div>
  </validator>
   </form>
   <div style="float:right">
     <button class="btn btn-success" @click="confirm()"  :disabled='!$v.valid'>确认</button>
     <button class="btn btn-default" @click="clean()" >取消</button>
   </div>
  </div>
</template>
<script>

  let updateInputtorGen = async function (self, data) {
    await self.$resetpost('rs/logic/updateBatch', data, {resolveMsg: '批量修改成功', rejectMsg: '批量抄表员变更失败'})
    self.$dispatch('success')
  }

export default {
  title: '批量操作',
  data () {
    return {
      model: {
        f_inputtor: [''],
        f_reason: '',

        meterReader: this.$appdata.getParam('抄表员')
      }
    }
  },
  props: ['data'],
  methods: {
    clean () {
      this.$info('取消操作')
      this.$dispatch('clean', '批量操作')
    },
    confirm () {
      let send = {
          f_change_content: this.model.f_inputtor[0],
          f_change_cause: this.model.f_reason,
          condition: this.data.condition,
          f_operator: this.$login.f.name,
          f_change_count: this.data.count,
          f_change_type: '抄表员变更',
          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
      }
      console.log('抄表员变更', send)
      updateInputtorGen(this, send)
    }
  },
  computed: {
    inputtores () {
      // return this.$login.f.f_gasman
      let rs = new Array()
      for (let i = 0; i < this.$login.f.f_gasman.length; i++) {
        let temp = {
          label: this.$login.f.f_gasman[i].name,
          value: this.$login.f.f_gasman[i].name
        }
        rs.push(temp)
      }
      return rs
    },
  }
}
</script>
