<template>
  <div class="basic-main">
    <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="col-sm-4" style="width: 20%">
            <label class="font_normal_body">用户姓名</label>
            <input type="text" class="input_search" placeholder="用户姓名" v-model="$parent.$parent.model.f_username" v-on:keyup.enter="search"
                   style="width: 60%"   condition="f_user_name like '%{}%'">
          </div>
          <div class="col-sm-4 " style="width: 20%">
            <label class="font_normal_body">开始时间</label>
            <datepicker
              :value.sync="$parent.$parent.model.f_check_start"
              placeholder='开始时间'
              :disabled-days-of-week="[]" style="width: 60%"
              :format="'yyyy-MM-dd'"
              :show-rest-button="reset"
              v-model = "$parent.$parent.model.f_check_start"
              condition="f_time > ='{} 00:00:00'">
            </datepicker>
          </div>
          <div class="col-sm-4 " style="width: 20%">
            <label class="font_normal_body">结束时间</label>
            <datepicker
              :value.sync="$parent.$parent.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="col-sm-4 form-group form-input-group" style="width: 20%">-->
            <!--<label class="font_normal_body">提&nbsp;交&nbsp;人</label>-->
            <!--<input type="text" class="input_search" placeholder="提交人" v-model="$parent.$parent.model.f_modifier" v-on:keyup.enter="search"-->
                   <!--style="width: 60%"   condition="f_modifier like '%{}%'">-->
          <!--</div>-->
          <div class="col-sm-4 " style="width: 20%">
            <label class="font_normal_body">审核状态</label>
            <v-select id="f_approved"
                      class="select_list select"
                      placeholder='审核状态' style="width: 60%"
                      v-model='model.f_approved'
                      :value.sync="$parent.$parent.model.f_approved"
                      :options='$parent.$parent.f_approval_states'
                      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="$parent.$parent.search()">查询</button>
            <!--<button class="button_new button_spacing" @click="$parent.$parent.verify()">审核</button>-->
            <!--<button class="button_export button_spacing" @click="$parent.$parent.verifyAll()">一键审核</button>-->

          </div>
        </div>
      </criteria>
      <data-grid class="list_area table_sy" style="overflow: hidden" :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>
          </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_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-show="showModal" :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('api/af-safecheck/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: {},
      f_approval_states:this.$appdata.getParam('审核状态'),
    }
  },
  methods: {
    search(){
     this.model.search('f_time= (select max(f_time) from t_modify_userinfo B where A.f_userinfoid = B.f_userinfoid)')
    },
    change(row) {
      this.showModal = true
      this.$set('info', row)
    },
    todo(row){
      let r = confirm("确认修改该资料？")
      if(r) {
        let _http = new HttpResetClass()
        _http.load('POST','api/af-safecheck/sql/查询用户原信息', {data: {id: this.info.f_userinfoid}},{resolveMsg: null, rejectMsg: null}).then((res) => {
          console.log('res==>',res)
          this.userinfo = res.data[0]
          row.f_approved = '已审核'
          row.f_approved_by = this.$login.f.name
          row.f_approved_time = Util.toStandardTimeString()
          let content = JSON.parse(row.f_content)
          console.log('content===>',content)
          let self = this
          if (row.f_modify_type == '用户档案') {
            this.context.f_userinfo_id = parseInt(row.f_userinfoid)
            this.context.f_user_name = this.isnull(content.f_user_name)
            this.context.f_userinfoid = row.f_userinfoid
            this.context.version = row.version
            this.context.f_residential_area = this.isnull(content.f_residential_area)
            this.context.f_user_phone = this.isnull(content.f_user_phone)
            this.context.f_street = this.isnull(content.f_street)
            this.context.f_area = this.isnull(content.f_area)
            this.context.f_unit = this.isnull(content.f_unit)
            this.context.f_building = this.isnull(content.f_building)
            this.context.f_floor = this.isnull(content.f_floor)
            this.context.f_room = this.isnull(content.f_room)
            this.context.f_address = this.isnull(content.f_address)
            this.context.f_userproperties = this.isnull(content.f_userproperties)
            this.context.f_comments = this.isnull(content.f_comments)
            row.f_residential_area = this.userinfo.f_residential_area
            row.f_user_name = this.userinfo.f_user_name
            row.f_user_phone = this.userinfo.f_user_phone
            row.area = this.userinfo.f_area
            row.f_street = this.userinfo.f_street
            row.f_unit = this.userinfo.f_unit
            row.f_building = this.userinfo.f_building
            row.f_floor = this.userinfo.f_floor
            row.f_room = this.userinfo.f_room
            row.f_address = this.userinfo.f_address
            row.f_userproperties = this.userinfo.f_userproperties
            row.f_comments = this.userinfo.f_comments
            this.$resetpost('api/af-safecheck/logic/UpdateUserinfo', {data: {row: this.context, tablename: 't_userinfo'}}).then((res) => {
              console.log('保存的row',row)
              self.$resetpost('rs/entity/t_modify_userinfo', row).then((res) => {
                window.alert('用户信息已保存')
                this.info = {}
                this.userinfo = {}
              })
            }).
            catch(
              (res) => {
                window.alert('信息保存失败')
              })
          }
        })
        if (row.f_modify_type == '表档案') {
          this.context.version = row.version
          this.context.id = content.id
          this.context.f_gaswatchbrand = content.f_maker
          this.context.f_metertype = content.f_diaphgram_size
          this.context.f_gasmeterstyle = content.f_meter_type
          this.context.lastinputgasnum = content.f_prior_reading
          this.context.f_meternumber = content.f_meter_no
          this.context.f_aroundmeter = content.f_flow_direction
          this.$resetpost('api/af-safecheck/logic/SaveEntity', {data: {row: this.context, tablename: 't_userinfo'}}).then((res) => {
            self.$resetpost('rs/entity/t_modify_userinfo', row).then((res) => {
            window.alert('用户信息已保存')
          this.reload()
        })
        }).catch(
            (res) => {
            window.alert('信息保存失败')
        })
        }
        this.showModal = false
      }
    },
    isnull(val){
      if(val == null){
        return ''
      }else{
        return val
      }
    },
    undo(row){
      let _http = new HttpResetClass()
      _http.load('POST','api/af-safecheck/sql/查询用户原信息', {data: {id: this.info.f_userinfoid}},{resolveMsg: null, rejectMsg: null}).then((res) => {
        this.userinfo = res.data[0]
        let r = confirm("确认修改内容不通过？")
        if(r) {
          console.log(this.$login.user)
          console.log(this.$login.f)
          row.f_approved = '未通过'
          row.f_approved_by = this.$login.f.name
          row.f_approved_time = Util.toStandardTimeString()
          this.$resetpost('rs/entity/t_modify_userinfo', row)
          this.showModal = false
          this.userinfo = {}
        }
      })

    }
  }
}
</script>
