<template>
  <div class="auto">
    <validator name='v'>
      <form class="form-horizontal">
        <div class="row">
          <div class="col-sm-4 form-group">
            <label for="f_reason" class="font_normal_body">停用原因</label>
            <v-select v-model="model.f_reason"
                      placeholder='停用原因'
                      :value.sync="model.f_reason"
                      :options='reason'
                      v-ref:reason
                      close-on-select ></v-select>
          </div>
          <div class="col-sm-4 form-group">
            <input type="checkbox" class="large-checkbox" id="f_valveState" v-model="valveStateChecked">
            <label for="f_operator" class="font-size-large">立即关阀</label>
          </div>
        </div>
        <div class="row" style="margin-top:1px;">
          <div class="col-sm-8 form-group">
            <label for="f_reason" class="font_normal_body">备&emsp;&emsp;注</label>
            <input class="input_search" style="width:80%" v-model="model.f_othereason"  placeholder="备注"/>
          </div>
        </div>
      </form>
      <div style="text-align:right;">
        <button class="button_search button_spacing" @click="confirm()"  :disabled='!$v.valid'>确认</button>
        <button class="button_clear" @click="clean()" >取消</button>
      </div>
    </validator>
  </div>
  <upload :blodid="blodid" v-if="false" isremark="true" fusetype="表具停用"></upload>
</template>
<script>
/**
 *综合业务
 表具停用组件
 */
export default {
  title: '表具停用',
  props: ['row'],
  data () {
    return {
      valveStateChecked: false,
      blodid: '',
      showupload: true,
      model: {},
      reason: this.$appdata.getParam('停用原因')
    }
  },
  ready () {
    this.blodid = this.row.f_userinfo_id
  },
  methods: {
    async confirm () {
      await this.$LogicService.meterDisable(this.model, this.row)
      let array = [{
        f_user_id: this.row.f_user_id,
        f_userfiles_id: this.row.f_userfiles_id,
        f_alias: this.row.f_alias,
        f_userinfo_id: this.row.f_userinfo_id,
        f_orgname: this.$login.f.orgs,
        f_orgid: this.$login.f.orgid,
        f_meternumber: this.row.f_meternumber
      }]
      if (this.row.f_meter_type === '物联网表' && this.valveStateChecked) {
        let data1 = {
          f_apply_type: '阀门控制',
          userid: array,
          nowDate: new Date(),
          f_apply_value: '关阀',
          f_apply_beizhu: '表具停用自动关阀',
          f_apply_operator: this.$login.f.name
        }
        // 根据复选框的状态添加条件
        if (this.valveStateChecked) {
          data1.f_valveState = 1
        }
        let data2 = {
          userid: array,
          instructtype: '阀门控制',
          isOpen: '关阀',
          instructTitle: '手动关阀',
          reasonInfo: '表具停用自动关阀',
          f_instruct_state: '待发送',
          inputtor: this.$login.f.name
        }
        await this.$resetpost('rs/logic/iot_instructUpdateAndDelect',
          {
            data: {
              data1: data1,
              data2: data2
            }
          })
      }
      this.$dispatch('success')
    },
    clean () {
      this.$dispatch('refresh')
    }
  }
}
</script>

<style>
.large-checkbox {
  width: 20px;
  height: 20px;
  transform: scale(1.4);
  margin-right: 14px;
  margin-top: 15px;
}

.font-size-large {
  padding-top: 10px;
  padding-left: 10px;
  font-size: 16px;
}
</style>
