<template>
  <div class="auto" style="overflow-y: scroll">
    <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" title="参数:抄表状态">抄表状态</label>
            <v-select :value.sync="model.f_meter_state" v-model="model.f_meter_state"  :value-single="true"
                      :options='meterstate' placeholder='抄表状态' close-on-select ></v-select>
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body" title="参数:抄表单状态">表单状态</label>
            <v-select :value.sync="model.f_hand_state" v-model="model.f_hand_state"  :value-single="true"
                      :options='handstate' placeholder='抄表单状态' close-on-select ></v-select>
          </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 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">截止日期</label>
            <input type="text" v-model="model.f_end_date" 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_meter_source" style="width: 60%" class="input_search">
          </div>
          <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="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-4">
            <label class="font_normal_body">上期结余</label>
            <input type="text" v-model="model.f_balance" 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_last_tablebase" 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_tablebase" 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_oughtamount" 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_oughtfee" disabled=disabled  style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body" title="参数:是否">是否缴费</label>
<!--            <input type="text" v-model="model.f_whether_pay"  style="width: 60%" class="input_search">-->
            <v-select :value.sync="model.f_whether_pay" v-model="model.f_whether_pay"
                      :options='writePays' 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">抄&ensp;表&ensp;员</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 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>
            <input type="text" v-model="model.f_depname" 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_orgname" disabled=disabled style="width: 60%" class="input_search">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-12">
              <label for="f_user_type" class="font_normal_body">&nbsp;&nbsp;&nbsp;备注&nbsp;&nbsp;&nbsp;</label>

            <div class="col-sm-10" 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 type="button" name="button" class="button_search"
                v-if="model.f_meter_state === '已抄表'  &&  model.f_whether_pay === '否'"
                @click.stop="fileterprice(row)">自定义划价
        </button>
        <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.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 {
        // 构建数组来存储对象
        editbank: true,
        showfiles: false,
        priceSplit: false,
        recordList: [],
        // meterstate:[{label:'已抄',value:'已抄'},{label:'未抄',value:'未抄'}],
        // handstate:[{label:'有效',value:'有效'},{label:'冲正',value:'冲正'},{label:'作废',value:'作废'},{label:'待审核',value:'待审核'}],
        fileNameSet: {
          'f_meter_state': '抄表状态',
          'f_hand_state': '抄表单状态',
          'f_meter_source': '抄表数据来源',
          'f_inputtor': '抄表员',
          'f_end_date': '截止日期',
          'f_input_date': '录入时间',
          'f_hand_date': '下发时间',
          'f_user_name': '客户姓名',
          'f_userinfo_code': '客户编号',
          'f_user_address': '客户地址',
          '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: {
      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)
          })
      },
      fileterprice (row) {
        this.priceSplit = true
        console.log('row==>', row)
      },
      cancel () {
        this.$dispatch('close')
      },
      uploadFiles () {
        this.showfiles = !this.showfiles
      },
      async getenddate () {
        var end_date = await this.$resetpost('rs/logic/getEndDate', {data: {f_userinfo_id: this.model.f_userinfo_id, f_input_date: this.model.f_input_date}})
        this.model.f_end_date = end_date.data
      },
      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] && this.model[item] !='s_timestamp') {
            var car = {
              chinesename: this.fileNameSet[item],
              fieldname: item,
              tablename: 't_handplan',
              oldvalue: this.oldmodel[item],
              newvalue: this.model[item],
              state: '有效',
              modifitime: Util.toStandardTimeString(),
              operator: this.$login.f.name,
              hand_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/saveHandRecord', {data: {recordlist: this.recordList, newData: this.model}})
        await this.$resetpost('rs/entity/t_handplan', this.model, {
          resolveMsg: '修改成功',
          rejectMsg: '未通过，修改出错!!!'
        })
        console.log('this.model', this.model)
        this.$dispatch('close')
      }
    },
    computed: {
      foperator () {
        return [...this.$appdata.getParam('操作人员')]
      },
      meterstate () {
        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: {
      'model.f_input_date' (val) {
        if (val) {
          this.getenddate()
        }
      },
      'model.f_user_name' () {
        if (this.model.f_operator) {
          this.selectoperator()
        }
      },
      'model.f_operator' () {
        if (this.model.f_operator) {
          this.selectoperator()
        }
      }
    }
  }
</script>
