<template>
  <div class="flex-auto" style="overflow-y: scroll;height: 45%">
    <validator name='v'>
      <form novalidate class="form-horizontal select-overspread ">
        <ul class="nav nav-tabs">
          <li class="active a-tabs"><a href="#">用户拉黑</a></li>
        </ul>
        <div>
          <div class="row">
            <div class="col-sm-4" id="f_user_id" :class="[$v.f_userinfo_code.required ? 'has-error' : 'has-success']">
              <label for="f_userinfo_code" class="font_normal_body">用户编号</label>
              <input class="input_search" style="width:60%" type="text" class="input_search" style="width:60%"
                     v-model="model.f_userinfo_code" @blur.prevent="getinfo()" style="width: 100px"
                     v-validate:f_userinfo_code='{required: true }' :disabled='isEdit' placeholder="用户编号">
            </div>
            <div class="col-sm-4" id="name">
              <label for="f_user_name" class=" font_normal_body">用户姓名</label>
              <input class="input_search" style="width:60%" type="text" class="input_search" style="width:60%"
                     v-model="model.f_user_name" readonly style="width: 100px"
                     placeholder="用户姓名">

            </div>
            <div class="col-sm-4" id="phone">
              <label for="f_user_phone" class=" font_normal_body">联系方式</label>
              <input class="input_search" style="width:60%" type="text" class="input_search" style="width:60%"
                     v-model="model.f_user_phone" readonly style="width: 100px"
                     placeholder="联系方式">

            </div>
          </div>

          <div>
            <div class="col-sm-12" id="address">
              <label for="f_address" class=" font_normal_body">地&nbsp;&nbsp;&nbsp;&nbsp;址&nbsp;&nbsp;</label>
              <input class="input_search" type="text" class="input_search" style="width:87%" v-model="model.f_address"
                     readonly
                     placeholder="地址">
            </div>
            <div class="col-sm-12" id="f_comments" :class="[$v.f_comments.required ? 'has-error' : 'has-success']">
              <label for="f_comments" class=" font_normal_body">原&nbsp;&nbsp;&nbsp;&nbsp;因&nbsp;&nbsp;</label>
              <input class="input_search" type="text" class="input_search" style="width:87%" v-model="model.f_comments"
                     placeholder="原因" v-validate:f_comments='{required: true }' >
            </div>

          </div>

          <div style="text-align:right;height:auto;margin-top:6px;">
            <button class="button_search" type="button" style="width:80px;" @click="confirm('拉黑')" v-show="!isBlackList && model.isblacklist =='false'" :disabled='!$v.valid'>
              拉黑
            </button>
            <button class="button_search"  type="button"  style="width:80px;" @click="confirm('取消拉黑')"
                    v-show="isBlackList || model.isblacklist =='true'" :disabled='!$v.valid'>
              取消拉黑
            </button>
            <button class="button_export"  type="button"  style="width:80px;" @click="close()">取消</button>
          </div>
        </div>

      </form>


    </validator>

  </div>
</template>
<script>

  import {HttpResetClass} from 'vue-client'
  import Vue from "vue";
  let initGen = async function (self, val) {
//获取低保气价
    let http = new HttpResetClass()
    let res = await http.load('POST', 'rs/sql/sale_getUserAndVersion', {data: {f_userinfo_code: self.data.f_userinfo_code,f_orgid: self.$login.f.orgid}}, {
      resolveMsg: null,
      rejectMsg: null
    })
    console.log(res.data)
    self.model = Object.assign({}, self.model, val)
    self.model.f_userinfo_code = res.data[0].f_userinfo_code
    self.model.f_userinfo_id = res.data[0].f_userinfo_id
    self.model.f_user_phone = res.data[0].f_user_phone
    self.model.f_address = res.data[0].f_address
    self.model.f_user_phone = res.data[0].f_user_phone
    self.model.version= res.data[0].version
  }

  export default {
    title: '低保户',
    props: {
      f_islow_income: {
        type: String,
        default: '1'
      },
      data: {
        type: Object
      }
    },
    data() {
      return {
        pricename: [{value: '', label: ''}],
        model: {
          f_userinfo_code: '',
          f_userinfo_id: '',
          f_user_name: '',
          f_address: '',
          f_user_phone: '',
          f_comments:'',
          version:null,
          isblacklist:'false'
        },
        // 编辑控制
        isBlackList: false,
        f_filialeid: '',  // 所属公司
        f_filialename: ''  // 所属公司名称

      }
    },
    ready() {
      if (this.data) {
        this.isBlackList = true
        initGen(this, this.data)
      } else {
        this.initModel()
      }
    },
    watch:{
      'data'(val){
        if (val) {
          this.isBlackList = true
          initGen(this, val)
        } else {
          this.initModel()
        }
      }
    },
    methods: {
      getinfo() {

        this.$resetpost('rs/sql/sale_getUserAndVersion', {data: {f_userinfo_code: this.model.f_userinfo_code,f_orgid: this.$login.f.orgid}}, {
          resolveMsg: null,
          rejectMsg: null
        }).then((res) => {
          console.log(res.data[0])
          this.model = res.data[0]

        })
      },
      async confirm(type) {
        let data = {
          f_operat_type: type,
          f_state: '有效',
          f_user_id: this.model.f_user_id,
          f_user_name: this.model.f_user_name,
          f_comments: this.model.f_comments,
          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_describe : `${this.$login.f.name}对客户${this.model.f_user_name}进行${type}`,
          f_userinfo_id : {
            f_userinfo_id: this.model.f_userinfo_id,
            f_user_state: '正常',
            version:this.model.version
          }
        }
        await this.$resetpost('rs/logic/backlistOperate', data, {resolveMsg: `${type}成功`, rejectMsg: `${type}失败，请重试`})
        this.initModel()
        this.$dispatch('success')
      },
      getorg(id, name) {
        this.f_filialeid = id[0]
        this.f_filialename = name[0]
      },
      initModel() {
        this.model = {
          f_userinfo_code: '',
          f_userinfo_id: '',
          f_user_name: '',
          f_address: '',
          f_user_phone: '',
          f_comments: '',
          version:null,
          isblacklist:'false'
        }
      },
      close() {
        this.$dispatch('close')
      }
    }
  }
</script>
<style lang="less">
  #gas-price-form {
    .form-group {
      margin-left: 0px;
      margin-right: 0px;
    }
  }

</style>
