<template>
  <div class="auto select-overspread">
    <ul class="nav nav-tabs">
      <li role="presentation" class="active" style="width: 100%">
        <a href="#" style="display: inline-block;">表具信息</a>
        <button class="button_search button_spacing" style="float: right;" type="button" @click="reSearch">返回</button>
      </li>
    </ul>
    <div class="row">
      <div class="col-sm-6 form-group">
        <label class="font_normal_body">表&emsp;&emsp;号</label>
        <input type="text" class="input_search" style="width: 60%" v-model="row.f_meternumber" placeholder="表号"/>
      </div>
      <div class="col-sm-6 form-group">
        <label class="font_normal_body">用气性质</label>
        <input type="text" class="input_search" style="width: 60%" v-model="row.f_gasproperties" placeholder="表号"/>
      </div>
      <div class="col-sm-6 form-group">
        <label class="font_normal_body">气表状态</label>
        <input type="text" class="input_search" style="width: 60%" v-model="row.f_table_state" placeholder="表具状态"/>
      </div>
      <div class="col-sm-6 form-group">
        <label class="font_normal_body">阀门状态</label>
        <input type="text" class="input_search" style="width: 60%" v-model="row.f_valvestate" placeholder="表具状态"/>
      </div>
      <div class="col-sm-6 form-group">
        <label class="font_normal_body">气表品牌</label>
        <input type="text" class="input_search" style="width: 60%" v-model="row.f_meter_brand" placeholder="表具状态"/>
      </div>
      <div class="col-sm-6 form-group">
        <label class="font_normal_body">气表型号</label>
        <input type="text" class="input_search" style="width: 60%" v-model="row.f_meter_style" placeholder="表具状态"/>
      </div>
    </div>
    <ul class="nav nav-tabs">
      <li role="presentation" class="active"><a href="#">表具操作</a></li>
    </ul>
    <button class="button_search button_spacing" type="button" @click="openUser">开户</button>
    <button v-if="row.f_meter_brand.includes('西美')&&row.f_meter_type.includes('物联网表')"
            class="button_search" type="button" @click="clearBarrier">清除障碍</button>
    <button class="button_search button_spacing" type="button" @click="valvecontrol">开关阀</button>
    <button class="button_search button_spacing" type="button" @click="zdfk">开关自动阀控</button>
    <!--阀控管理弹框-->
    <modal :show.sync="valve">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="close()"><span>&times;</span></button>
        <h4 class="modal-title" align="center">阀控管理</h4>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="form-group " style="padding-left: 8px">
          <label class="font_normal_body">操作原因</label>
          <textarea class="form-control" style="width:80%" v-model="operateReason" rows="3"
                    placeholder="请填写操作原因"></textarea>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button  type="button" class="btn btn-info btn-ln fr" style="margin-left:20px" @click='valveoperate("权限关阀")'>权限关阀</button>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="button_search btn-ln fr" @click='valveoperate("开阀")'>开阀</button>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-info btn-ln fr" @click='valveoperate("关阀")'>关阀</button>
      </footer>
    </modal>
  </div>
</template>

<script>
import Vue from 'vue'

export default {
  title: '操作详情',
  name: 'WebMeterBatchOperate',
  props: ['row'],
  data () {
    return {
      famenShow: '',
      valve: '',
      operateReason: '',
      famenShow1: ''
    }
  },
  ready () {
    console.log('进入操作详情')
  },
  methods: {
    clearBarrier(){
      // 地址
      // 127.0.0.1:8445
      // 参数
      let datas =  {
        moduleName:"XiMeiSystem", // 固定值
        content:{
          tradeCode:"3015",// 固定值
          appid: "yysf", // 固定值
          partner: "cqsemay_bcts", // 固定值
          version:"v1", // 固定值
          tasked:this.getuuid(), // 任务id
          notifyUrl:"http://192.168.2.10:8445/webmeter/rs/logic/XiMeiSystemCallBack", // 固定值
          meterNo: this.row.f_meternumber,// 表号
          signType:" MD5" //固定值
        },
        title: "清除异常", // 固定值
        type: "清除异常", // 固定值
        inputtor:this.row.f_operator, // 操作人
        userId:this.row.f_userfiles_id,   // 表档案ID
        dataId: null // 操作记录ID
      }
      this.$resetpost('/webmeter/rs/logic/syncSaveSetParamsTemplate', {data: datas},{resolveMsg: `清理成功`, rejectMsg: `清理失败`}).then(res => {
      })
    },
    getuuid(){
      let uuidA = '';
      var s = [];
      var hexDigits = '0123456789abcdef';
      for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
      }
      s[14] = '4';
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
      s[8] = s[13] = s[18] = s[23] = '-';
      uuidA = s.join('');
      return uuidA;
    },
    reSearch () {
      this.$dispatch('research')
    },
    // 阀控管理
    valvecontrol () {
      if (this.$login.r.includes('开关阀')) {
        this.valve = true
      } else {
        this.$showAlert('您没有开关阀权限,请联系管理员！！', 'warning', 3000)
      }
    },
    close () {
      this.valve = false
      this.operateReason = ''
    },
    async zdfk () {
      let data = {
        f_userfiles_id: this.row.f_userfiles_id
      }
      if (this.row.f_network_valve === '关闭') {
        await this.$resetpost('rs/logic/openzdfk', data, {resolveMsg: '开启自动阀控成功。', rejectMsg: '开启自动阀控失败!!!'})
      } else {
        await this.$resetpost('rs/logic/closezdfk', data, {resolveMsg: '关闭自动阀控成功。', rejectMsg: '关闭自动阀控失败!!!'})
      }
      await this.$dispatch('research')
    },
    // 开关阀操作
    async valveoperate (oper) {
      let msg = ''
      let nnum
      if (oper === '权限关阀'){
        msg = '权限关阀'
        nnum = 2
      } else if (oper === '关阀') {
        msg = '手动关阀'
        nnum = 0
      }else {
        msg = '手动开阀'
        nnum = 1
      }
      let datas = {
        instructType: '阀门控制',
        instructTitle: `手动${msg}`,
        condition: `t_userfiles.f_userfiles_id='${this.row.f_userfiles_id}'`,
        meterBrandName: this.row.f_alias,
        f_instruct_state: '待发送',
        inputtor: Vue.$login.f.name,
        reasonInfo: this.operateReason,
        meternumberf: this.row.f_meternumber,
        contentData: {isOpen: nnum}
      }
      await this.$resetpost('rs/logic/iot_saveInstruct', {data: datas},
        {warnMsg: `确定要进行${msg}操作吗？`, resolveMsg: `${msg}成功`, rejectMsg: `${msg}失败`}).then(res => {
          this.valve = false
          this.operateReason = ''
        })
      await this.$dispatch('research')
    },
    async openUser () {
      let data = {
        f_userfiles_id: this.row.f_userfiles_id
      }
      await this.$resetpost('rs/logic/startup', data)
      await this.$dispatch('research')
    }
  },
  computed: {
    // 界面细节权限
    jurisdiction () {
      return this.$login.r ? this.$login.r : []
    }
  },
  watch: {}
}
</script>

<style scoped>

</style>

