<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>
        <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"  :businessid="randomBusinessId" isremark="true" :deleteimg="true" fusetype="停用"></upload>
</template>
<script>
  import LogicService from './plugins/LogicService'
  /**
   *综合业务
   表具停用组件
   */
  export default {
    title: '表具停用',
    props: ['row'],
    data () {
      return {
        blodid: '',
        showupload: true,
        model: {},
        randomBusinessId: '',
        reason: this.$appdata.getParam('停用原因')
      }
    },
    ready () {
      this.blodid = this.row.f_userinfo_id
      this.getRandomId()
    },
    methods: {
      getRandomId () {
        this.randomBusinessId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
          let res = Math.random() * 16 | 0
          let v = c == 'x' ? res : (res & 0x3 | 0x8)
          return v.toString(16)
        })
      },
      async confirm () {
        await 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 === '物联网表') {
          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: '关阀',
                  instructTitle: '手动关阀',
                  reasonInfo: '表具停用自动关阀',
                  f_instruct_state: '待发送',
                  inputtor: this.$login.f.name
                }
              }
            })
        }
        this.$dispatch('success')
      },
      clean () {
        this.$dispatch('refresh')
      }
    }
  }
</script>

<style>
</style>
