<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 for="f_userinfo_code" class="font_normal_body">用户编号</label>
            <input type="text"  v-model="model.f_userinfo_code"   class="input_search"
                   disabled=disabled    style="width:60%" placeholder="编号" >
          </div>

          <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 for="f_user_type" class="font_normal_body">用户类型</label>
            <input type="text" v-show="false" v-model="$refs.f_user_type.selectedItems" >
            <v-select :value.sync="model.f_user_type" :options='usertype'  :value-single="true"
                      placeholder='用户类型' close-on-select
                      v-model='model.f_user_type' v-ref:f_user_type></v-select>
          </div>

        </div>

        <div class="row">
          <div class="col-sm-4">
            <label class="font_normal_body">录入日期</label>
            <datepicker id="f_input_date"
                        placeholder="录入日期"
                        style="width:60%"
                        v-model="model.f_input_date"
                        :value.sync="model.f_input_date"
                        :format="'yyyy-MM-dd HH:mm:ss'"
            >
            </datepicker>
          </div>

          <div class="col-sm-4">
            <label class="font_normal_body">&nbsp;&nbsp;&nbsp;抄表员</label>
            <v-select :value.sync="model.f_inputtor" v-model="model.f_inputtor"  :value-single="true"
                      :options='inputtores' placeholder='　抄表员' close-on-select ></v-select>
          </div>
        </div>
   <!--     <div class="col-sm-4" >
          <label for="f_card_id" class="font_normal_body">&nbsp;&nbsp;&nbsp;卡号&nbsp;&nbsp;&nbsp;</label>
          <input type="text"  v-model="model.f_card_id" class="input_search" style="width:60%" placeholder="卡号" v-el:outpipe v-next-el="date">
        </div>  -->
        <div class="row">
          <div class="col-sm-4">
            <label class="font_normal_body">地&emsp;&emsp;址</label>
            <input type="text" v-model="model.f_address" disabled=disabled style="width: 60%" class="input_search">
          </div>
        </div>

        <!--<div class="col-sm-4">
          <label class="font_normal_body">用户编号</label>
          <input type="text" v-model="model.f_userinfo_code" disabled=disabled style="width: 60%" class="input_search">
        </div>-->
        <div class="row">
          <div class="col-sm-12">
            <label for="f_user_type" class="font_normal_body">备&emsp;&emsp;注</label>

            <div class="col-sm-8" id="f_comments" style="margin-left: 8px;margin-bottom: 5px;width: 86.333333%;">
              <textarea class="col-sm-3 form-control" type="text" v-model="model.f_comments"></textarea>
            </div>
          </div>
        </div>
      </form>
      <div style="float: right">
        <button class="button_search" @click="save">写卡</button>
        <button class="button_clear" @click="cancel">取消</button>
      </div>
      <split-price :showdata="model" :pricesplit="priceSplit" v-if="priceSplit" ></split-price>
    </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.f_userfiles_id" v-ref:upload  fusetype="抄表" isremark="true" style="width:auto" ></upload>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
  </div>
</template>
<script>
import Vue from 'vue'
import * as Util from "../../../Util";

var data
export default {
  title: '写卡调用',

  data () {
    return {
      // 构建数组来存储对象
      editbank: true,
      showfiles: false,
      priceSplit: false,
      recordList: [],
      // meterstate:[{label:'已抄',value:'已抄'},{label:'未抄',value:'未抄'}],
      // handstate:[{label:'有效',value:'有效'},{label:'冲正',value:'冲正'},{label:'作废',value:'作废'},{label:'待审核',value:'待审核'}],
      fileNameSet: {
        'f_inputtor': '抄表员',
        'f_input_date': '录入时间',
        'f_user_name': '客户姓名',
        'f_userinfo_code': '客户编号',
        'f_user_address': '客户地址',
        'f_user_type': '用户类型',
        'f_comments': '备注',
        'f_orgname': '所属公司',
        'f_depname': '所属部门'

      }
    }
  },
  props: {
    oldmodel: Object,
    model: Object
  },

  ready () {
    /* console.log('logininfo',this.$login.r) */
    if (this.$login.r.includes('维护银行转账信息')) {
      this.editbank = true
    }
    // console.log(this.props.model)
    this.oldmodel = JSON.parse(JSON.stringify(this.model))
  },
  created () {
  },
  methods: {

    cancel () {
      this.$dispatch('close')
    },

    addressValid (val) {
    },
    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_userfiles',
            oldvalue: this.oldmodel[item],
            newvalue: this.model[item],

            modifitime: Util.toStandardTimeString(),
            operator: this.$login.f.name,
            userfiles_id: this.model.f_userfiles_id
          }
          this.recordList.push(car)
          // 该方法并未对chinesename fieldname operator等进行判断赋值，此暂写为定值
          console.log('================================!!!!!!!!!!!1', car)
        }
      }

      await this.$resetpost('rs/logic/xieKaHis', {data: {recordlist: this.recordList, newData: this.model}})
      await this.$resetpost('rs/entity/t_userfiles', this.model, {
        resolveMsg: '写卡成功',
        rejectMsg: '未通过，写卡出错!!!'
      })
      console.log('this.model', this.model)
      this.$dispatch('close')
    }
  },
  computed: {

    meterstate () {
      return this.$appdata.getParam('抄表状态')
    },
    usertype () {
      return this.$appdata.getParam('用户类型')
    },
    handstate () {
      return this.$appdata.getParam('抄表单状态')
    },
    writePays () {
      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: {

  }
}
</script>
