<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" v-if="this.row.f_meter_type ==='物联网表' && this.row.f_table_state !== '停用'">
            <label for="isInstruct" class="font_normal_body">是否关阀</label>
            <v-select v-model="model.isInstruct"
                      placeholder='请选择'
                      :value.sync="model.isInstruct"
                      :options='isInstructs'
                      close-on-select value-single></v-select>
          </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 {
        isInstruct:'',
        blodid: '',
        showupload: true,
        model: {},
        reason: this.$appdata.getParam('停用原因'),
        isInstructs: [{label: '否', value: '否'}, {label: '是', value: '是'}],
      }
    },
    ready () {
      this.blodid = this.row.f_userinfo_id
      if (this.row.f_table_state === '停用') {
        let data = {
          f_userfile_id: this.row.f_userfiles_id,
          f_user_id: this.row.f_user_id,
          f_userinfo_id: this.row.f_userinfo_id,
          f_user_phone: this.row.f_user_phone,
          f_user_name: this.row.f_user_name,
          f_comments: this.model.f_reason[0],
          f_othereason: this.model.f_othereason
        }
        this.$resetpost('rs/logic/getLastDisableReason', {data: data}, {
          resolveMsg: null,
          rejectMsg: null
        }).then((res) => {
          this.$set('model.f_othereason', res.data.f_othereason)
          this.$set('model.f_reason[0]', res.data.f_comments)
        })
      }
    },
    methods: {
      async confirm () {
        if (this.row.f_table_state === '停用') {
          let data = {
            f_userfiles_id: this.row.f_userfiles_id,
            f_user_id: this.row.f_user_id,
            f_userinfo_id: this.row.f_userinfo_id,
            f_user_name: this.row.f_user_name,
            f_user_phone: this.row.f_user_phone,
            f_comments: this.model.f_reason[0],
            f_othereason: this.model.f_othereason,
            f_operat_type: '停用',
            f_describe: `${this.$login.f.name}对客户${this.row.f_user_name}进行表具停用操作`,
            f_state: '有效',
            f_operator: this.$login.f.name,
            f_operatorid: this.$login.f.id,
            f_orgid: this.$login.f.orgid,
            f_orgname: this.$login.f.orgs,
            f_depid: this.$login.f.depids,
            f_depname: this.$login.f.deps,
            f_zoneid: this.$login.f.zoneid,
            f_zones: this.$login.f.zones
          }
          this.$resetpost('rs/logic/updateDisable', {data: data}, {
            resolveMsg: '更新停用原因成功',
            rejectMsg: '更新停用原因失败！！'
          })
          return
        }
        await this.$LogicService.meterDisable(this.model, this.row)
        let array = [{
          f_user_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
        }]
        console.log('this.isinstruct-------------->',this.model.isInstruct)
        if(this.row.f_meter_type ==='物联网表' && this.model.isInstruct == '是') {
          console.log('看看能不能进来关阀---->',this.model.isInstruct)
          await this.$resetpost('rs/logic/iot_instructUpdateAndDelect',
            {
              data: {
                data1: {
                  f_apply_type: '阀门控制',
                  userid: array,
                  nowDate: new Date(),
                  f_apply_value: '关阀',
                  f_apply_beizhu: '表具停用自动关阀',
                  f_apply_operator: this.$login.f.name
                },
                data2: {
                  userid: array,
                  instructtype: '阀门控制',
                  isOpen:  '关阀',
                  f_instruct_state: '待发送',
                  inputtor: this.$login.f.name
                }
              }
            })
        }
        this.$dispatch('success')
      },
      clean () {
        this.$dispatch('refresh')
      }
    }
  }
</script>

<style>
</style>
