<template>
  <div class="auto">
    <criteria-paged :model="model"  v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div partial>
          <form>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/用户ID.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户编号：</label>
              </div>
              <div class="col-xs-8" >
                <input class="search_input input-font"
                       v-model=model.f_userinfo_code condition="f_userinfo_code = '{}'" placeholder="请输入用户编号" />
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/用户ID.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">表 &nbsp;&nbsp; &nbsp;&nbsp; 号：</label>
              </div>
              <div class="col-xs-8" >
                <input class="search_input input-font"
                       v-model=model.f_meternumber condition="f_meternumber = '{}'" style="width: 70%" placeholder="请输入表号" />
                <button type="button" name="button" class="btn btn-primary" style="width: 25%" @click="$parent.$parent.scan">扫码</button>
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/用户姓名.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户名称：</label>
              </div>
              <div class="col-xs-8" >
                <input class="search_input input-font" v-model="model.f_username" placeholder="请输入用户名称（可模糊查询）">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/用户类型.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户类型：</label>
              </div>
              <div class="col-xs-8" >
                <v-select :value.sync="$parent.$parent.model.f_user_type" class="input-font"
                          :options='$parent.$parent.user_types' placeholder='请选择用户类型' :value-single="true"
                          v-model="$parent.$parent.model.f_user_type" close-on-select clear-button></v-select>
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">小区名称：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_districtname" placeholder="请输入用户小区（可模糊查询）">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_building" placeholder="请输入用户楼号">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;元：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_unit" placeholder="请输入用户单元">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户地址：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_address" placeholder="请输入用户地址（可模糊查询）">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">表&nbsp;&nbsp;封&nbsp;&nbsp;号：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_metertitles" placeholder="请输入表封号" condition="uf.f_metertitles='{}'">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">电&nbsp;&nbsp;话&nbsp;&nbsp;号：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_user_phone" placeholder="请输入电话号" condition="ui.f_user_phone like '%{}%'">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">卡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_card_id" placeholder="请输入卡号" condition="uf.f_card_id like '%{}%'">
              </div>
            </div>
            <div class="row text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 45%;" @click="search">查询</button>
            </div>
            <div style="height:30px;"></div>
          </form>
        </div>
      </criteria>

      <list :model="model" partial='list'>
        <div partial>
          <div class="auto app-text" style="margin-top: 5px;">
            <div class="panel" style="padding: 10px 10px 5px 10px;">
              <div class="panel-body panel-self">
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户编号</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_userinfo_code }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户名称</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_user_name }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">表号</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_meternumber }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户类型</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_user_type }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户电话</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone }}</p>
                </div>

                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">小区名称</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_residential_area }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户地址</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_address }}</p>
                </div>
                <div class="row" style="margin-top: 10px;">
                  <div class="col-xs-12 text-right">
                    <button class="btn btn-danger" @click="$parent.$parent.$parent.cancelAccount(row)">销户</button>
                  </div>
                </div>
              </div>
            </div>

          </div>
        </div>
      </list>
    </criteria-paged>
    <!-- 销户弹窗 -->
    <div class="modal" v-show="showModal">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title">销户</h4>
          </div>
          <div class="modal-body">
            <div class="form-group">
              <label>销户原因：</label>
              <textarea class="form-control" v-model="cancelReason" rows="3" placeholder="请输入销户原因"></textarea>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" @click="showModal = false">取消</button>
            <button type="button" class="btn btn-primary" @click="confirmCancel">确定</button>
          </div>
        </div>
      </div>
    </div>
    <!--<back-page :need-back='true'   @flag="$back()"></back-page>-->
  </div>
</template>

<script>
import {HttpResetClass, PagedList} from 'vue-client'
import Vue from 'vue'
import * as Util from '../Util'

export default {
  title: '销户',
  data () {
    let model = new PagedList(`${this.$androidUtil.getProxyUrl()}/rs/sql/提取用户档案`, 20, { groupitem: '""', orderitem: '"f_residential_area,CAST(build as int),f_unit,CAST(floor1 as int),f_room"',f_check_type:'this.f_check_type[0]',
      f_user_name:'this.model.f_username',myCycle: 'this.myCycle',fyCycle: 'this.fyCycle', f_user_type:'this.f_user_type',f_sign: 'this.f_sign[0]', f_residential_area:'this.model.f_districtname', f_address:'this.model.f_address',f_user_state: 'this.f_user_state[0]',f_orgids:'this.f_orgids',f_unit:'this.model.f_unit',f_building:'this.model.f_building',f_filialeid:'this.f_filialeid'})
    model.f_sign = ['']
    model.f_user_type = ''
    model.f_user_state =['']
    model.f_check_type =['']
    model.myCycle = 0
    model.fyCycle = 0
    model.f_filialeid = Vue.user.orgid
    //model.f_filialeid = 287
    return {
      model: model,
      showModal: false,
      cancelReason: '',
      currentUser: null,
      signs: [
        {label:'请选择录入状态', value:''},
        {label:'录入', value:'1'},
        {label:'非录入', value:'0'},
      ],
      ischecks: [
      ],
      user_types: [
        {label: '请选择用户类型', value: ''},
        {label: '民用', value: '民用'},
        {label: '非民用', value: '非民用'},
      ],
      f_user_states: [
        {label:'请选择档案状态', value:''},
        {label:'正常', value:'正常'},
        {label:'点火', value:'点火'},
      ],
      f_check_types: [
        {label:'请选择安检类型', value:''},
        {label:'应检', value:'应检'},
        {label:'超期', value:'超期'},
      ],
    }
  },
  ready () {
    // this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/logic/getSafeCheckCycle`,{},{resolveMsg: null, rejectMsg: null}).then((res) => {
    //   //tag)
    //   if(res.data.code == 200){
    //     this.model.myCycle = res.data.civil.value
    //     this.model.fyCycle = res.data.civilian.value
    //   }else{
    //     //this.$showMessage(res.data.msg)
    //   }
    //
    // })
    // this.getCheckTime()
    // this.Mreadibook()
  },
  computed: {
    reload(){
      this.$refs.paged.loadPage(this.$refs.paged.model.pageIndex)
    },
    selected () {
      return this.$refs.paged.$refs.grid.selected
    }
  },
  methods:{
    scan(){
      HostApp.__this__=this,
        HostApp.scanCode({callback:"javascript:HostApp.__this__.getCode();"})
    },
    getCode(){
      let datapa = HostApp.getCode().data;
      let indexnum = datapa.indexOf("]C1")
      if(indexnum != -1){
        datapa = datapa.substring(indexnum+3,datapa.length)
      }
      this.$refs.paged.$refs.cri.model.f_meternumber=datapa
    },
    cancelAccount(row) {
      this.currentUser = row
      this.showModal = true
      this.cancelReason = ''
    },
    confirmCancel() {
      if (!this.cancelReason) {
        this.$showMessage('请输入销户原因')
        return
      }

      let data = {
        f_operat_type: '销户',
        f_describe: `${Vue.user.name}对客户${this.currentUser.f_user_name}进行销户`,
        f_user_id: this.currentUser.f_user_id,
        f_user_name: this.currentUser.f_user_name,
        f_state: '销户',
        f_comments: this.cancelReason,
        f_operator: Vue.user.name,
        f_operatorid: Vue.user.id,
        f_orgid: Vue.user.orgid,
        f_orgname: Vue.user.orgs,
        f_depid: Vue.user.depids,
        f_depname: Vue.user.deps,
        f_userinfo_id: this.currentUser.f_userinfo_id
      }

      new HttpResetClass().load('POST', `${this.$androidUtil.getProxyUrl()}/rs/logic/saveSingleCancellation`, {data}, {
        resolveMsg: '销户成功',
        rejectMsg: '销户失败'
      }).then(res => {
        if (res && res.data) {
          if (!(res.data.isaudit === null)) {
            if (res.data.isaudit === 1) {
              this.$showMessage('提交成功,等待管理审核!', 'success', 2000)
              return
            }
          }
          this.$showMessage('销户成功', 'success', 2000)
          this.showModal = false
          this.$refs.paged.loadPage(this.$refs.paged.model.pageIndex) // 刷新列表
        }
      }).catch(error => {
        if (error.state === 603) {
          this.$showMessage('重复提交')
          return
        }
        this.$showMessage('销户失败')
      })
    },
    batchOperate (model, type) {
      let operateType = type
      if (type === '启用') {
        operateType = '销户启用'
      }
      let data = {
        f_operat_type: operateType,
        f_describe: `${Vue.user.name}对客户${model.userinfo.f_user_name}进行销户`,
        f_user_id: model.userinfo.f_user_id,
        f_user_name: model.userinfo.f_user_name,
        f_state: type === '启用' ? '正常' : '销户',
        f_comments: model.f_reason,
        f_operator: Vue.user.name,
        f_operatorid: Vue.user.id,
        f_orgid: Vue.user.orgid,
        f_orgname: Vue.user.orgs,
        f_depid: Vue.user.depids,
        f_depname: Vue.user.deps,
        f_userinfo_id: model.userinfo.f_userinfo_id
      }
      let cancelUserGen = function * (data, type) {
        console.log('销户。。', data)
        if (type === '销户') {
          yield Vue.resetpost('api/af-revenue/logic/saveSingleCancellation', data, {resolveMsg: `${type}成功`, rejectMsg: `${type}失败`}).then(res => {
            if (res && res.data) {
              if (type === '销户') {
                if (!(res.data.isaudit === null)) {
                  if (res.data.isaudit === 1) {
                    Vue.showAlert('提交成功,等待管理审核!', 'success', 2000)
                    return
                  }
                }
              }
              Vue.showAlert('销户成功', 'success', 2000)
            }
          })
        } else {
          Vue.resetpost('api/af-revenue/logic/saveSingleCancellation', data, {resolveMsg: `${type}成功`, rejectMsg: `${type}失败`})
        }
      }
    }
  }
}
</script>
<style scoped>
.app-row {
  background-color: white;
  padding: 10px 10px 0 10px;
  border-bottom: 1px solid rgba(235, 235, 235, 0.5);
}
.search_input {
  border: 0;
  outline: none;
}
.font{
  font: 15px PingFang-SC-Medium;
  color: #666666;
}
.input-font{
  font: 15px PingFang-SC-Medium;
  color: #333333;
}
.btn-font{
  font:600 16px PingFang-SC-Bold;
  color: #499EDF;
}
.btn-color{
  background-color: #FFFFFF;
  border-radius: 10px ;
  border: 1px solid #499EDF;
}
.app-text {
  font-size: 12px;
}
.panel-self{
  border-radius: 10px;
  border:1px solid #499EDF;
  background-color: #F8F8F8;
}
.yybtn-color{
  border-radius: 4px ;
  border: 1px solid #499EDF;
}
.qxbtn-color{
  background-color: #FFFFFF;
  border-radius: 4px ;
  border: 1px solid #499EDF;
}
.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1050;
  display: block;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
  outline: 0;
  background-color: rgba(0,0,0,0.5);
}

.modal-dialog {
  position: relative;
  width: auto;
  margin: 10px;
  margin-top: 30%;
}

.modal-content {
  position: relative;
  background-color: #fff;
  border: 1px solid #999;
  border-radius: 6px;
  box-shadow: 0 3px 9px rgba(0,0,0,0.5);
  background-clip: padding-box;
  outline: 0;
}

.modal-header {
  padding: 15px;
  border-bottom: 1px solid #e5e5e5;
}

.modal-title {
  margin: 0;
  line-height: 1.42857143;
}

.modal-body {
  position: relative;
  padding: 15px;
}

.modal-footer {
  padding: 15px;
  text-align: right;
  border-top: 1px solid #e5e5e5;
}

.form-control {
  display: block;
  width: 100%;
  height: 34px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.42857143;
  color: #555;
  background-color: #fff;
  background-image: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
  transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}

textarea.form-control {
  height: auto;
}
</style>
