<template>
  <div class="flex-row">
    <div @keyup.enter="search" class="basic-main">
      <criteria-paged :model="model" v-ref:paged>
        <criteria partial='criteria'@condition-changed='$parent.selfSearch' v-ref:cri>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <res-select-group :initres="$parent.$parent.initres" :show-component="$parent.$parent.initcompent" @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户编号</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_code"
                       condition="f_userinfo_code = '{}'" placeholder='客户编号'>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户姓名</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                       condition="f_user_name = '{}'" placeholder='客户姓名'>
              </div>

              <div class="span" style="float:right;">
                  <button class="button_search button_spacing" @click="search()" v-el:cx>查询</button>
                    <button v-show="$parent.$parent.battchbtnshow" class="button_search button_spacing width-60" style="background-color: #ec971f;" @click="$parent.$parent.batchtax()">批量审核</button>
                <div
                  :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                  @click="$parent.$parent.hidden()"
                  class="button_spacing"
                  style="float: right"></div>
              </div>
            </div>
            <div class="row" v-if="$parent.$parent.criteriaShow">
              <div class="form-group col-sm-2">
                <label class="font_normal_body">操作时间</label>
                <datepicker id="startDate" placeholder="起始日期"
                            v-model="model.startDate"
                            :value.sync="model.startDate"
                            condition="f_canceloperate_date >'{}'"
                            :format="'yyyy-MM-dd'"
                            class="datepicker"
                            style="width:60%">
                </datepicker>
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <datepicker id="endDate" placeholder="结束日期"
                            v-model="model.endDate"
                            :value.sync="model.endDate"
                            condition="f_canceloperate_date <'{}'"
                            :format="'yyyy-MM-dd'"
                            class="datepicker"
                            style="width:60%">
                </datepicker>
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">审核时间</label>
                <datepicker id="startDate1" placeholder="起始日期"
                            v-model="model.startDate1"
                            :value.sync="model.startDate1"
                            condition="f_audit_date >'{}'"
                            :format="'yyyy-MM-dd'"
                            class="datepicker"
                            style="width:60%">
                </datepicker>
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <datepicker id="endDate1" placeholder="结束日期"
                            v-model="model.endDate1"
                            :value.sync="model.endDate1"
                            condition="f_audit_date <'{}'"
                            :format="'yyyy-MM-dd'"
                            class="datepicker"
                            style="width:60%">
                </datepicker>
              </div>
              <div  class="form-group col-sm-2">
                <label class="font_normal_body">审核状态</label>
                <v-select :options='$parent.$parent.isauditoptions3' :value.sync="model.f_isaudit"
                          close-on-select condition="f_isaudit='{}'" @change="$parent.$parent.battchshows(model.f_isaudit)"
                          placeholder='审核状态' v-model="model.f_isaudit"></v-select>
              </div>
              <div  class="form-group col-sm-2">
                <label class="font_normal_body">审核结果</label>
                <v-select :options='$parent.$parent.isauditoptions2' :value.sync="model.f_audit_state"
                          close-on-select condition="f_audit_state='{}'"
                          placeholder='审核状态' v-model="model.f_audit_state"></v-select>
              </div>
            </div>
          </div>
        </criteria>
        <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
          <template partial='head'>
            <tr>
              <th>序号</th>
              <th>客户编号</th>
              <th>客户姓名</th>
              <th>地址</th>
              <th>用户电话</th>
              <th>用户类型</th>
              <th>用气性质</th>
              <th>用户状态</th>
              <th>表具状态</th>
              <th>销户操作人</th>
              <th>销户操作时间</th>
              <th>销户原因</th>
              <th>审核状态</th>
              <th>审核结果</th>
              <th>审核人</th>
              <th>审核时间</th>
              <th>审核备注</th>
              <th>所属组织</th>
              <th>操作</th>
            </tr>
          </template>
          <template partial='body'>
            <td style="text-align: center;">{{$index+1}}</td>
            <td style="text-align: center;">{{row.f_userinfo_code}}</td>
            <td style="text-align: center;">{{row.f_user_name}}</td>
            <td style="text-align: center;">{{row.f_address}}</td>
            <td style="text-align: center;">{{row.f_user_phone}}</td>
            <td style="text-align: center;">{{row.f_user_type}}</td>
            <td style="text-align: center;">{{row.f_user_state}}</td>
            <td style="text-align: center;">{{row.f_gasproperties}}</td>
            <td style="text-align: center;">{{row.f_table_state}}</td>
            <td style="text-align: center;">{{row.f_canceloperator}}</td>
            <td style="text-align: center;">{{row.f_canceloperate_date}}</td>
            <td style="text-align: center;">{{row.f_cancelcomments}}</td>
            <td style="text-align: center;">{{row.f_isaudit}}</td>
            <td style="text-align: center;">{{row.f_audit_state}}</td>
            <td style="text-align: center;">{{row.f_audit_operator}}</td>
            <td style="text-align: center;">{{row.f_audit_date}}</td>
            <td style="text-align: center;">{{row.f_audit_comments}}</td>
            <td style="text-align: center;">{{row.f_orgname}}</td>
            <td style="text-align: center;">
              <button type="button" name="button" class="button_search button_spacing width-60" style="background-color: #ec971f;"
                      v-if="row.f_state == '销户'  && row.f_isaudit=='未审核' "
                      @click.stop="$parent.$parent.$parent.auditcancel(row)">审核
              </button>
            </td>

          </template>
        </data-grid>
      </criteria-paged>
      <!--批量审核弹框-->
      <modal :show.sync="arrshow"  width="600px"  v-ref:modal large backdrop="false"  title="批量审核" >
        <article slot="modal-body" class="modal-body">
          <div class="row">
            <h5>本次批量审核户数：{{battchuserlen}}</h5>
          </div>
          <h5 class="page-header" style="margin-top: 0px"></h5>
            <div class="row">
              <div  class="form-group col-sm-6" >
                <label class="font_normal_body" style="line-height: 20px">审核结果</label>
                <v-select :options='isauditoptions' :value.sync="auditinfo.isaudit" value-single
                          placeholder='审核结果' v-model="auditinfo.isaudit"></v-select>
              </div>
              <div  class=" form-group col-sm-6">
                <label class="font_normal_body" style="line-height: 20px">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</label>
                <input class="input_search"
                       placeholder='备注'
                       type="text" v-model="auditinfo.auditcomments">
              </div>
            </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <button v-show="arrshow" type="button" class="btn btn-default" @click='close'>取消</button>
          <button v-show="arrshow" type="button" class="btn btn-success" @click='battchaudit()'>确认</button>
        </footer>
      </modal>
<!--      单户审核-->
      <modal :show.sync="showauditflag" width="800px" title="单户审核" v-ref:modal large backdrop="false">
        <article slot="modal-body" class="modal-body" style="height: auto;">
          <div class="row">
            <div class="form-group col-sm-6">
              <label class="font_normal_body" style="line-height: 20px">销户原因</label>
              <input class="input_search"
                     placeholder='销户原因' disabled readonly
                     type="text" v-model="cancelinfo.f_cancelcomments">
            </div>
            <div class="form-group col-sm-6">
              <label class="font_normal_body" style="line-height: 20px">销户时间</label>
              <input class="input_search"
                     placeholder='销户时间' disabled readonly
                     type="text" v-model="cancelinfo.f_canceloperate_date">
            </div>
            <div class="form-group col-sm-6">
              <label class="font_normal_body" style="line-height: 20px">销&nbsp;&nbsp;户&nbsp;人</label>
              <input class="input_search"
                     placeholder='销户人' disabled readonly
                     type="text" v-model="cancelinfo.f_canceloperator">
            </div>
          </div>
          <h5 class="page-header" style="margin-top: 20px"></h5>
          <div class="row">
            <div  class="form-group col-sm-6" >
              <label class="font_normal_body" style="line-height: 20px">审核结果</label>
              <v-select :options='isauditoptions' :value.sync="auditinfo.isaudit" value-single
                        placeholder='审核结果' v-model="auditinfo.isaudit"></v-select>
            </div>
            <div  class=" form-group col-sm-6">
              <label class="font_normal_body" style="line-height: 20px">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</label>
              <input class="input_search"
                     placeholder='备注'
                     type="text" v-model="auditinfo.auditcomments">
            </div>
          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <button class="button_search button_spacing" type="button" @click="batchCancellation()">确认</button>
          <button class="button_search button_spacing" type="button" @click="closeaudit()">取消</button>
        </footer>
      </modal>

    </div>
  </div>
</template>

<script>
  /**
   *违约金减免页面
   */
  import Vue from 'vue'
  import {PagedList, HttpResetClass} from 'vue-client'

  export default {
    title: '批量销户界面',
    data () {
      return {
        criteriaShow: false,
        model: new PagedList('rs/sql/battchcancelauditQuery', 20),
        initres: {
          org:[this.$login.f.orgid],
          dep:[],
          user:[],
        },
        closeaccout: '',
        bathshow: false,
        arrshow: false,
        section_f_start_data: '',
        section_f_end_data: '',
        nowRowdate: '',
        nowUserfilesId: '',
        newUserId: '',
        newHandplanId: '',
        toDayDate: '',
        sectionShow: false,
        orgCondtionStr: '',
        initcompent:['company','department','operator'],
        cancelinfo:{},
        auditinfo:{},
        showauditflag:false,
        isauditoptions:[{label:'全部',value:''},{label:'通过',value:'通过'},{label:'未通过',value:'未通过'}],
        isauditoptions2:[{label:'全部',value:''},{label:'通过',value:'通过'},{label:'未通过',value:'未通过'}],
        isauditoptions3:[{label:'全部',value:''},{label:'已审核',value:'已审核'},{label:'未审核',value:'未审核'}],
        battchbtnshow:false,
        battchuserlen :0,
      }
    },
    ready () {
      this.$refs.paged.$refs.cri.model.startDate = this.$login.toStandardDateString() + ' 00:00:00'
      this.$refs.paged.$refs.cri.model.endDate = this.$login.toStandardDateString() + ' 23:59:59'
      this.$refs.paged.$refs.cri.search()
    },
    methods: {
      battchshows(val){
          this.search();
          if(val && val == '未审核'){
            this.battchbtnshow = true;
            return;
          }
          this.battchbtnshow = false;
      },
      //单户审核保存
      async batchCancellation(){
        if(this.auditinfo.isaudit==null && this.auditinfo.isaudit=='' ){
          this.$showAlert('请选择审核结果!','warning',2000);
          return;
        }
        if(this.auditinfo.isaudit == '未通过' && (this.auditinfo.auditcomments=='') ){
          this.$showAlert('审核结果为未通过需要输入备注,请输入备注后提交','warning',2000);
          return;
        }
        let auditparam = {
          f_isaudit:'已审核',
          f_audit_state: this.auditinfo.isaudit,
          f_audit_operator: this.$login.f.name,
          f_audit_comments: this.auditinfo.auditcomments,
          f_audit_operatorid: this.$login.f.id,
          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_user_name: this.auditinfo.f_user_name,
          auditid: this.auditinfo.auditid
        }
        try{
          await this.$resetpost('rs/logic/oneUserCancelAudit',auditparam,{resolveMsg:null,rejectMsg:null}).then(res=>{
            if(res){
              this.$showAlert('审核成功','success',2000);
              this.closeaudit();
              this.search();
            }
          })
        }catch(e){
          this.$showAlert('审核失败!','danger',2000);
          this.closeaudit();
          this.search();
        }
      },
      closeaudit(){
        this.showauditflag =false;
      },
      auditcancel(row){
        this.cancelinfo = {};
        this.auditinfo={
          isaudit:'通过',
          auditcomments: '',
          auditid:row.id,
          f_user_name: row.f_user_name
        };
        this.cancelinfo = {
          f_cancelcomments:row.f_cancelcomments,
          f_canceloperator:row.f_canceloperator,
          f_canceloperate_date:row.f_canceloperate_date
        };
        this.showauditflag =true;
      },
      getRes(condition) {
        this.orgCondtionStr = condition
      },
      dealmsg (val) {
        val.model = this.model.model
        this.$dispatch('deal-msg', val)
      },

      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      selfSearch(args) {
        console.log("--------------------?")
        args.condition = `${args.condition}` + this.orgCondtionStr
        this.model.search(args.condition, args.model)
      },
      search(){
        this.$refs.paged.$refs.cri.search()
      },
      // 批量审核按钮
      batchtax () {
        this.cancelinfo = {};
        this.auditinfo={
          isaudit:'通过',
          auditcomments: '',
        };
        this.battchuserlen = this.$refs.paged.model.count;
        this.arrshow = true
      },
      // 点击关闭
      close () {
        this.arrshow = false
      },
      // 批量审核
      battchaudit () {
        if(this.auditinfo.isaudit==null && this.auditinfo.isaudit=='' ){
          this.$showAlert('请选择审核结果!','warning',2000);
          return;
        }
        if(this.auditinfo.isaudit == '未通过' && (this.auditinfo.auditcomments=='') ){
          this.$showAlert('审核结果为未通过需要输入备注,请输入备注后提交','warning',2000);
          return;
        }
        // 组织数据
        let batch = {
          f_isaudit:'已审核',
          f_audit_state: this.auditinfo.isaudit,
          f_audit_operator: this.$login.f.name,
          f_audit_comments: this.auditinfo.auditcomments,
          f_audit_operatorid: this.$login.f.id,
          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,
          condition:   `${this.model.condition}` + this.orgCondtionStr
        }
        try{
          this.$resetpost('rs/logic/battchcancelaudit', batch, {
            resolveMsg: null,
            rejectMsg: '批量审核出错!!!'
          }).then((res) => {
            if(res && res.data){
              this.$showMessage(`本次批量审核成功${this.battchuserlen}户 `);
            }
            this.$refs.paged.$refs.cri.search()
            this.close();
            this.cancelinfo = {};
            this.auditinfo={};
            this.battchuserlen = 0;
          })
        }catch(e){
          this.close();
          this.cancelinfo = {};
          this.auditinfo={};
          this.battchuserlen = 0;
        }

      }

    },
    watch: {

    }
  }
</script>
<style lang="less" scoped>

</style>

