<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='search' 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">开始时间</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 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-4 " style="width: auto; margin-top: 8px">
              <button class="button_search button_spacing" @click="search">查询</button>
            </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>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center"><nobr>{{row.f_userinfo_code}}</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_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-if="showModal" :userinfome.sync="userInformation" :info.sync="info" :type="type" ></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 {
      showModal: false,
      model: model,
      info: {},
      userinfo:{},
      context: {},
      excessive:false,
      userInformation:{},
      f_approval_states:this.$appdata.getParam('审核状态'),
      type: ''
    }
  },
  methods: {
    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, type) {
      this.type = type
      //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',JSON.parse(JSON.stringify(row)))
        this.showModal = true
      })

    },
    checkVal(row){
      //检查一些必要信息是否未填
      let checked={ischeck:true,msg:''}
      if(!row.f_pcd_id){
        checked={ischeck:false,msg:'请选择省市区！'}
      }
      if(!row.f_street_id){
        checked={ischeck:false,msg:'请选择街道！'}
      }
      if(!row.f_address){
        checked={ischeck:false,msg:'新地址不能为空！'}
      }
      if(row.f_special != 1){
        if(!row.f_residential_area_id){
          checked={ischeck:false,msg:'请选择集收单位！'}
        }
        if(!row.f_room){
          checked={ischeck:false,msg:'请输入用户门牌号！'}
        }
      }
      return checked
    },
    async todo(row){
      let r = confirm("确认修改该资料？")
      console.log('row=', JSON.stringify(row))
      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_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_gasmodel_id){
          this.userInformation.meterinfo[0].f_gasmodel_id = row.f_gasmodel_id
        }
        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}}},{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
                  this.$refs.paged.$refs.cri.search()
                }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>
