<template>
  <work-busy :is-busy="excessive"></work-busy>
  <div class="basic-main" style="height: 100%">
    <criteria-paged :model="model" v-ref:paged>
      <criteria class="search_area" partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-2"  >
              <label class="font_normal_body">客户编号</label>
              <input type="text" class="input_search" v-model="model.f_userinfo_code"
                     style="width: 60%" placeholder="客户编号" condition="ui.f_userinfo_code='{}'">
            </div>
            <div class="form-group col-sm-2"  >
              <label class="font_normal_body">客户名称</label>
              <input type="text" class="input_search" v-model="model.f_username"
                     style="width: 60%" placeholder="客户名称" condition="ui.f_user_name like '%{}%'">
            </div>
            <div class="form-group col-sm-2"  >
              <label class="font_normal_body">提&nbsp;交&nbsp;人</label>
              <input type="text" class="input_search" v-model="model.f_modifier"
                     style="width: 60%" placeholder="提交人" condition="f_modifier like '%{}%'">
            </div>
            <div class="form-group col-sm-2"  >
              <label class="font_normal_body">审&nbsp;核&nbsp;人</label>
              <input type="text" class="input_search" v-model="model.f_approved_by"
                     style="width: 60%" placeholder="审核人" condition="f_approved_by like '%{}%'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">审核状态</label>
              <v-select id="f_approved"
                        placeholder='审核状态' style="width: 60%"
                        v-model='model.f_approved'
                        :value.sync="model.f_approved"
                        :options='$parent.$parent.f_approval_states'
                        condition="f_approved =  '{}'"
                        close-on-select clear-button></v-select>
            </div>
            <div class="col-sm-2 " style="width: auto; margin-top: 8px">
              <button class="button_search button_spacing" @click="search">查询</button>
              <export-excel-safe :data="$parent.$parent.searchData"
                                 :field="$parent.$parent.excelHeaders"
                                 :choose-col="true"
                                 sqlurl="rs/logic/SafeExportExcel" sql-name="用户档案审核查询" template-name='用户档案审核查询'></export-excel-safe>
              <!--<button class="button_new button_spacing" @click="$parent.$parent.verify()">审核</button>-->
              <!--<button class="button_export button_spacing" @click="$parent.$parent.verifyAll()">一键审核</button>-->

            </div>
          </div>
          <div class="row">
            <div class="form-group col-sm-2">
              <label class="font_normal_body">用户类型</label>
              <v-select
                placeholder='用户类型' style="width: 60%"
                v-model='model.f_user_nature'
                :value.sync="model.f_user_nature"
                :options='$parent.$parent.f_user_nature_arr'
                condition="ui.f_user_nature =  '{}'"
                close-on-select clear-button></v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">开始时间</label>
              <datepicker
                :value.sync="model.f_check_start"
                placeholder='开始时间'
                :disabled-days-of-week="[]" style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "model.f_check_start"
                condition="f_time > ='{} 00:00:00'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">结束时间</label>
              <datepicker
                :value.sync="model.f_check_end"
                placeholder='结束时间'
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'" style="width: 60%"
                :show-rest-button="reset"
                v-model = "model.f_check_end"
                condition="f_time <=  '{} 23:59:59'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">用户类型</label>
              <v-select
                        placeholder='用户类型' style="width: 60%"
                        v-model='model.f_user_nature'
                        :value.sync="model.f_user_nature"
                        :options='$parent.$parent.f_user_nature_arr'
                        condition="ui.f_user_nature =  '{}'"
                        close-on-select clear-button></v-select>
            </div>
          </div>

        </div>
      </criteria>
      <data-grid class="list_area table_sy" :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <!--<th><nobr></nobr></th>-->
            <th><nobr>用户编号</nobr></th>
            <th><nobr>用户类型</nobr></th>
            <th><nobr>用户名称</nobr></th>
            <th><nobr>提交人</nobr></th>
            <th><nobr>提交时间</nobr></th>
            <th><nobr>修改类型</nobr></th>
            <th><nobr>备注</nobr></th>
            <th><nobr>审核状态</nobr></th>
            <th><nobr>审核人</nobr></th>
            <th><nobr>审核时间</nobr></th>
            <th><nobr>审核</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <!--<td style="text-align: center"><nobr><input type="checkbox" v-model="row.checked" v-bind:checked="row.checked"  @click="$parent.$parent.$parent.addChecked(row)"></nobr></td>-->
          <td style="text-align: center"><nobr>{{row.f_userinfo_code}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_user_nature}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_user_name}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_modifier}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_time}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_modify_type}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_remark}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_approved}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_approved_by}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_approved_time}}</nobr></td>
          <td style="text-align: center"><nobr>
            <button class="button_search-1 button_spacing" @click="$parent.$parent.$parent.change(row)" v-if="row.f_approved == '未审核'">审核</button>
            <button class="button_new-1 button_spacing" @click="$parent.$parent.$parent.change(row)" v-if="row.f_approved != '未审核'">查看</button>
          </nobr></td>
        </template>
      </data-grid>
    </criteria-paged>
    <info-modify-modal v-show="showModal" :userinfome.sync="userInformation" :info.sync="info"  ></info-modify-modal>
  </div>
</template>

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

export default {
  components: {InfoModifyModal},
  title: '档案审核',
  data() {
    let model = new PagedList('rs/sql/用户档案审核查询', 20, {
      groupitem: '""', orderitem: '"f_time desc"', f_approved: 'this.f_approved[0]',filialestr:'this.filialestr'
    })
    model.filialestr = this.$login.f.orgid
    model.f_archive_date = ''
    model.f_approved = ['']
    return {
      searchData: {
        condition: "1=1",
        orderitem: "f_time desc",
        groupitem: "",
        f_approved: '',
        filialestr: this.$login.f.orgid
      },
      excelHeaders: {
        //searchData:searchData,
        'f_userinfo_code': '客户编号',
        'f_user_name': '客户姓名',
        'f_user_nature':'用户类型',
        'f_modifier':'提交人',
        'f_time': '提交时间',
        'f_modify_type': '修改类型',
        'f_remark': '备注',
        'f_approved': '审核状态',
        'f_approved_by': '审核人',
        'f_approved_time': '审核时间'
      },
      showModal: false,
      model: model,
      info: {},
      userinfo:{},
      context: {},
      excessive:false,
      userInformation:{},
      f_user_nature_arr:this.$appdata.getParam('用户类型'),
      f_approval_states:this.$appdata.getParam('审核状态'),
    }
  },
  methods: {
    selfSearch(args) {
      this.searchData.condition = args.condition
      this.model.search(args.condition, args.model, args.condValue)
    },
    search(args){
      args += 'f_time= (select max(f_time) from t_modify_userinfo B where A.f_userinfoid = B.f_userinfoid)'
     this.model.search(args)
    },
    change(row) {
      //tag)
      new HttpResetClass().load('post',`/rs/logic/filemanage_getFilesDetail`, {
        //f_userinfo_code:'12381344',
        f_userinfo_id:row.f_userinfoid
      }, {resolveMsg: null, rejectMsg: null}).then((res) => {
        //tag
        //this.userInformation=res.data
        this.$set('userInformation',res.data)
        //tag
        this.$set('info',row)
        this.showModal = true
      })

    },
    async todo(row){
      let r = confirm("确认修改该资料？")
      if(r) {
        this.excessive=true
        let userinfoms=Object.assign({},this.userInformation.baseinfo.base)
        //userinfoms.f_user_name=row.f_user_name
        userinfoms.f_operator_record=row.f_modifier
        userinfoms.f_user_phone=row.f_user_phone
        userinfoms.f_zuhu_phone=row.f_zuhu_phone
        userinfoms.f_operatorid_record=row.f_modifier_id
        //userinfoms.f_remark=row.f_remark
        //tag
        if(this.userInformation.meterinfo[0].f_meter_classify!='物联网表'){
          this.userInformation.meterinfo[0].f_meternumber=row.f_meternumber
        }
        if (row.f_defendcard){
          this.userInformation.meterinfo[0].f_defendcard = row.f_defendcard
        }
        userinfoms.userfiles=[]
        userinfoms.userfiles.push(this.userInformation.meterinfo[0])
        userinfoms.f_orgid_record=null
        userinfoms.f_orgname_record=null
        userinfoms.f_depid_record=null
        userinfoms.f_depname_record=null
        let useraddressms=Object.assign({},this.userInformation.addressinfo)
        useraddressms.f_pcd=row.f_pcd
        useraddressms.f_pcd_id=row.f_pcd_id
        useraddressms.f_street=row.f_street
        useraddressms.f_street_id=row.f_street_id
        useraddressms.f_residential_area=row.f_residential_area
        useraddressms.f_residential_area_id=row.f_residential_area_id
        useraddressms.f_building=row.f_building?row.f_building:null
        useraddressms.f_building_id=row.f_building_id
        useraddressms.f_unit=row.f_unit?row.f_unit:null
        useraddressms.f_floor=row.f_floor?row.f_floor:null
        useraddressms.f_room=row.f_room?row.f_room:null
        useraddressms.f_building_suffix= row.f_building_suffix?row.f_building_suffix:null
        useraddressms.f_unit_suffix= row.f_unit_suffix?row.f_unit_suffix:null
        useraddressms.f_floor_suffix= row.f_floor_suffix?row.f_floor_suffix:null
        useraddressms.f_room_suffix= row.f_room_suffix?row.f_room_suffix:null
        //useraddressms.f_slice_area=row.f_slice_area
        useraddressms.f_address=row.f_address
        useraddressms.f_special=row.f_special
        useraddressms.f_iscity=row.f_iscity
        useraddressms.f_operator=row.f_modifier
        useraddressms.f_operatorid=row.f_modifier_id
        try{
          let res1=await new HttpResetClass().load('POST','/rs/logic/filemanage_fileSave', {data: {userinfo: userinfoms,modifyReason:this.f_source?`${this.f_source}审核通过更改档案信息`:'',address:{id:this.userInformation.addressinfo.id,oldid:this.userInformation.addressinfo.id,address:row.f_address}}},{resolveMsg: null, rejectMsg: null})
          //tag)
          if(res1.data.status==200){
            let res2=await new HttpResetClass().load('POST','/rs/logic/address_updateuseraddress', useraddressms,{resolveMsg: null, rejectMsg: null})
            //tag)
            if(res2.data.id){
              //tag)
              this.info.f_approved='已审核'
              this.info.f_approved_by=this.$login.f.name
              this.info.f_approved_time=Util.toStandardTimeString()
              //tag)
              let res3=await new HttpResetClass().load('POST','/rs/logic/SaveEntity', {data:{row:this.info,tablename:'t_modify_userinfo'}},{resolveMsg: null, rejectMsg: null})
                //tag)
                if(res3.data.code==200){
                  this.$showMessage("审核成功,用户信息已更新！")
                  this.excessive=false
                }else{
                  this.$showMessage("审核失败！")
                  this.excessive=false
                }
            }else{
              this.$showMessage("更新地址信息失败！")
              this.excessive=false
            }
          }else{
            this.$showMessage("修改用户信息失败！")
            this.excessive=false
          }
        }catch(msg){
          if( typeof msg == 'object' && msg.data){
            this.$showMessage("修改用户信息失败！"+msg.data)
          }else{
            this.$showMessage("审核失败,可以尝试重新点击审核按钮再次进行审核！！")
          }
          this.excessive=false
        }
      }
    },
    isnull(val){
      if(val == null){
        return ''
      }else{
        return val
      }
    },
    undo(row){
      this.info.f_approved='未通过'
      this.info.f_approved_by=this.$login.f.name
      this.info.f_approved_time=Util.toStandardTimeString()
      new HttpResetClass().load('POST','/rs/logic/SaveEntity', {data:{row:this.info,tablename:'t_modify_userinfo'}},{resolveMsg: null, rejectMsg: null}).then((res3)=>{
        //tag)
        if(res3.data.code==200){
          this.$showMessage("审核成功,审核结果:未通过！")
        }else{
          this.$showMessage("审核失败！")
        }
      })

    }
  }
}
</script>
