<template>
  <div class="auto">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <div class="row">
          <div class="col-sm-6  form-group">
            <label class="font_normal_body">封堵时间</label>
            <input type="text" class="input_search" v-model="plugging.f_operate_date" style="width:60%" disabled
                   placeholder="上次停用时间"/>
          </div>
          <div class="col-sm-6  form-group">
            <label class="font_normal_body">操作人</label>
            <input type="text" class="input_search" v-model="plugging.f_operator" style="width:60%" disabled
                   placeholder="操作人"/>
          </div>
          <div class="col-sm-12  form-group">
            <label class="font_normal_body">封堵原因</label>
            <input type="text" class="input_search" v-model="plugging.f_comments" style="width:60%" disabled
                   placeholder="停用原因"/>
          </div>
          <div class="col-sm-12  form-group">
            <label class="font_normal_body">其他原因</label>
            <input type="text" class="input_search" v-model="plugging.f_othereason" style="width:60%" disabled
                   placeholder="停用原因"/>
          </div>
        </div>
        <div class="row">
          <div class="col-sm-8 form-group" :class="[$v.f_comments.required || $v.f_comments.dctest? 'has-error' : 'has-success']">
            <label for="f_reason" class="font_normal_body">解除封堵原因</label>
            <input class="input_search"
                   style="width:80%"
                   v-model="model.f_comments"
                   v-validate:f_comments='{required: true }'
                   placeholder="解除封堵原因"/>
          </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>
</template>
<script>
/**
 *综合业务
 *表具启用组件
 */

let meterEnable = async function (self, model, row) {
  let params = {
    f_userfiles: {
      f_userfiles_id: row.f_userfiles_id,
      f_table_state: '正常',
      version: row.version
    },
    f_userinfo: {
      f_userinfo_id: row.f_userinfo_id,
      f_user_state: '正常',
      version: row.version
    },
    f_secure_plugging: {
      f_userfiles_id: row.f_userfiles_id,
      f_user_id: row.f_user_id,
      record_userinfo: row.f_userinfo_id,
      f_userinfo_id: row.f_userinfo_id,
      f_user_name: row.f_user_name,
      f_state: '有效',
      f_comments: model.f_comments,
      f_othereason: model.f_othereason,
      f_operat_type: '解除封堵',
      f_describe: `${self.$login.f.name}对客户${row.f_user_name}进行用户进行解除封堵`,
      f_operator: self.$login.f.name,
      f_operatorid: self.$login.f.id,
      f_orgid: self.$login.f.orgid,
      f_orgname: self.$login.f.orgs,
      f_depid: self.$login.f.depids,
      f_depname: self.$login.f.deps,
      f_zoneid: self.$login.f.zoneid,
      f_zones: self.$login.f.zones,
      f_operate_date: self.$login.toStandardTimeString()
    }
  }
  console.log('解除封堵。。。。。。。。。。')
  await self.$resetpost('rs/logic/sale_userSecurePlugging', {data: params}, {resolveMsg: '解除封堵成功', rejectMsg: '解除封堵失败'})
  self.$dispatch('success')
}

export default {
  title: '解除用户封堵',
  props: ['row'],
  data () {
    return {
      model: {},
      reason: this.$appdata.getParam('解除封堵原因'),
      plugging: {},
      kaifa: false
    }
  },
  ready () {
    this.deactivatedReason()
  },
  methods: {
    changeisuse (val) {
      if (val) {
        this.kaifa = true
      } else {
        this.kaifa = false
      }
    },
    // 查询封堵原因原因
    async deactivatedReason () {
      let data = {
        tablename: 't_disable',
        condition: `id = (select max(id) from t_disable where f_userfiles_id = '${this.row.f_userfiles_id}')`
      }
      let res = await this.$resetpost('rs/sql/saleSingleTable', {data: data}, {
        resolveMsg: null,
        rejectMsg: '获取上次停用原因失败'
      })
      this.plugging = res.data[0]
    },
    confirm () {
      meterEnable(this, this.model, this.row)
    },
    clean () {
      this.$dispatch('refresh')
    }
  }
}
</script>

<style>
</style>
