<template>
  <div class="auto">
    <validator name='a' @valid="addressValid(true)" @invalid="addressValid(false)">
      <form class="form-horizontal">
        <div class="row">
          <div class="col-sm-4">
            <label class="font_normal_body">用户姓名</label>
            <input type="text" v-model="model.f_user_name" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">换表类型</label>
            <input type="text" v-model="model.f_type" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">换表费&emsp;</label>
            <input type="text" v-model="model.f_changemeter_fee" disabled=disabled style="width: 60%" class="input_search">
          </div>
        </div>

        <div class="row">
          <div class="col-sm-4">
            <label class="font_normal_body">旧表号&emsp;</label>
            <input type="text" v-model="model.f_meternumber" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">新表号&emsp;</label>
            <input type="text" v-model="model.f_newmeternumber" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">旧表品牌</label>
            <input type="text" v-model="model.f_meter_brand" disabled=disabled style="width: 60%" class="input_search">
          </div>
        </div>

        <div class="row">
          <div class="col-sm-4">
            <label class="font_normal_body">新表品牌</label>
            <input type="text" v-model="model.f_newmeter_brand" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">补气量&emsp;</label>
            <input type="text" v-model="model.f_remanent_gas" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">补气金额</label>
            <input type="text" v-model="model.f_remanent_money" disabled=disabled style="width: 60%" class="input_search">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-4">
            <label class="font_normal_body">旧表状态</label>
            <input type="text" v-model="model.f_table_state" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">新表状态</label>
            <!--            <v-select :value.sync="model.f_changemeter_state" v-model="model.f_changemeter_state"-->
            <!--                      :options='changestate' placeholder='换表状态'-->
            <!--                      :value-single="true"-->
            <!--                      :search="false"-->
            <!--                      close-on-select></v-select>-->
            <input type="text" v-model="model.f_newtable_state" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">换表状态</label>
            <input type="text" v-model="model.f_changemeter_state" disabled=disabled style="width: 60%" class="input_search">
            <!--            <v-select :value.sync="model.f_changemeter_state" v-model="model.f_changemeter_state"-->
            <!--                      :options='changestate' placeholder='换表状态'-->
            <!--                      :value-single="true"-->
            <!--                      :search="false"-->
            <!--                      close-on-select></v-select>-->

          </div>

        </div>
        <div class="row">
          <div class="col-sm-4">
            <label class="font_normal_body">换表人&emsp;</label>
            <input type="text" v-model="model.f_change_operator" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body" title="参数:操作人员查询">操作人员</label>
            <v-select :value.sync="model.f_operator"
                      v-model="model.f_operator"
                      :value-single="true"  @blur="selectoperator()"
                      :options='foperator'
                      close-on-select></v-select>
            <!--                      @click="selectoperator"-->
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">换表日期</label>
            <datepicker  placeholder="换表日期" style="width: 60%"
                         v-model="model.f_changemeter_date"
                         :value.sync="model.f_changemeter_date"
                         :format="'yyyy-MM-dd HH:mm:ss'">
            </datepicker>
          </div>
        </div>
        <div class="row">
          <div class="col-sm-8">
            <label class="font_normal_body">地&emsp;&emsp;址</label>
            <input type="text" v-model="model.f_address" disabled=disabled style="width: 80%" class="input_search">
          </div>
        </div>
        <!--        <div class="row">-->
        <!--          <div class="col-sm-4">-->
        <!--            <label class="font_normal_body">下发日期</label>-->
        <!--            <datepicker id="f_hand_date"-->
        <!--                        placeholder="下发日期"-->
        <!--                        style="width:60%"-->
        <!--                        v-model="model.f_hand_date"-->
        <!--                        :value.sync="model.f_hand_date"-->
        <!--                        :format="'yyyy-MM-dd HH:mm:ss'"-->
        <!--            >-->
        <!--            </datepicker>-->
        <!--          </div>-->
        <!--         -->

        <!--        </div>-->



      </form>
      <div style="float: right">
        <button class="button_search" @click="save">保存</button>
        <button class="button_clear" @click="cancel">取消</button>
      </div>
    </validator>
    <modal :show.sync="showfiles" width="80%"style="width:auto;"  v-ref:modal middle backdrop="false">
      <article slot="modal-body">
        <upload :blodid="model.f_userinfo_id"  :businessid="model.id" v-ref:upload  fusetype="换表" isremark="true" style="width:auto" ></upload>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
    <!--文件上传按钮-->
    <button class="button_search" style="width: max-content" @click="uploadFiles()">上传附件</button>
  </div>
</template>
<script>
  import Vue from 'vue'
  import {HttpResetClass} from 'vue-client'
  import * as Util from "../../../../../Util";
  var data
  export default {
    title: '基本信息',

    data () {
      return {
        uploadText: '换表',
        // 构建数组来存储对象
        editbank: true,
        recordList: [],
        changestate: [{label: '有效', value: '有效'}, {label: '无效', value: '无效'}],
        showfiles: false,
        // meterstate:[{label:'已抄',value:'已抄'},{label:'未抄',value:'未抄'}],
        // handstate:[{label:'有效',value:'有效'},{label:'冲正',value:'冲正'},{label:'作废',value:'作废'},{label:'待审核',value:'待审核'}],
        fileNameSet: {
          // 'f_change_operator':'换表人',
          'f_changemeter_date': '换表日期'
          // 'f_changemeter_state':'换表状态',
          // 'f_table_state':'旧表状态',
          // 'f_newtable_state':'新表状态'
        }
      }
    },
    props: {
      oldmodel: Object,
      model: Object
    },

    ready () {
      this.oldmodel = JSON.parse(JSON.stringify(this.model))
    },
    created () {
    },
    methods: {
      selectoperator () {
        let f_operator = this.model.f_operator
        console.log('处理签的this.f_operatorid', this.f_operatorid)
        let http = new HttpResetClass()
        http.load('POST', 'rs/logic/findOperator',
          {f_operator: f_operator},
          {resolveMsg: null, rejectMsg: null}).then((res) => {
            console.log('kanak,res', res)
            this.model.f_operatorid = res.data[0].id
            console.log('this.f_operatorid', this.f_operatorid)
          })
      },
      cancel () {
        this.$dispatch('close')
      },

      uploadFiles () {
        this.showfiles = !this.showfiles
      },
      async save () {
        for (var item in this.model) {
          if (this.model[item] instanceof Array) {
            this.model[item] = this.model[item].length > 0 ? this.model[item][0] : ''
          }
          if (this.model[item] != this.oldmodel[item]) {
            var car = {
              chinesename: this.fileNameSet[item],
              fieldname: item,
              tablename: 't_changemeter',
              oldvalue: this.oldmodel[item],
              newvalue: this.model[item],
              state: '有效',
              modifitime: Util.toStandardTimeString(),
              operator: this.$login.f.name,
              changemeter_id: this.model.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
            }
            this.recordList.push(car)
            // 该方法并未对chinesename fieldname operator等进行判断赋值，此暂写为定值
            console.log(car)
          }
        }

        await this.$resetpost('rs/logic/saveChangeMeterRecord', {data: {recordlist: this.recordList, newData: this.model}})
        // if(this.model.f_operat_type==='换表'||this.model.f_operat_type==='换表撤销'){
        //   await this.$resetpost('rs/entity/t_changemeter', this.model, {
        //     resolveMsg: '修改成功',
        //     rejectMsg: '未通过，修改出错!!!'
        //   })
        //   await this.$resetpost('rs/entity/t_changetables', this.model, {
        //     resolveMsg: '修改成功',
        //     rejectMsg: '未通过，修改出错!!!'
        //   })
        console.log('this.model', this.model)
        this.$dispatch('close')
      }
    },
    computed: {
      foperator () {
        return [...this.$appdata.getParam('操作人员')]
      },
      meterstate () {
        return this.$appdata.getParam('抄表状态')
      },

      inputtores () {
        // 获取抄表员
        console.log('获取抄表员', this.$login.f)
        let rs = new Array()
        if (this.$login.f.f_gasman.length > 0) {
          for (let i = 0; i < this.$login.f.f_gasman.length; i++) {
            let temp = {
              label: this.$login.f.f_gasman[i].name,
              value: this.$login.f.f_gasman[i].name
            }
            rs.push(temp)
          }
        }
        // let rs = this.$appdata.getParam('抄表员')
        return rs
      }

    },
    watch: {
      'model.f_user_name' () {
        if (this.model.f_operator) {
          this.selectoperator()
        }
      },
      'model.f_operator' () {
        if (this.model.f_operator) {
          this.selectoperator()
        }
      }
    }
  }
</script>
