<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 form-group">
            <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 form-group">
            <label class="font_normal_body" title="参数:收费状态">收费状态</label>
            <input type="text" v-model="model.f_state" disabled=disabled style="width: 60%" class="input_search">

            <!--            <input type="text" v-model="model.f_charge_state" disabled=disabled style="width: 60%" class="input_search">-->
<!--            <v-select :value.sync="model.f_state" v-model="model.f_state"-->
<!--                      :value-single="true"-->
<!--                      :search="false"-->
<!--                      disabled=disabled-->
<!--                      :options='positions' placeholder='收费状态'-->
<!--                      close-on-select>-->
<!--            </v-select>-->
          </div>
          <div class="col-sm-4 form-group">
            <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 class="col-sm-4 form-group">
            <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="col-sm-4 form-group">
            <label class="font_normal_body" title="参数:付款方式查询">付款方式</label>
<!--            <input type="text" v-model="model.f_payment" style="width: 60%" class="input_search">-->
            <v-select :value.sync="model.f_payment" v-model="model.f_payment"
                      :options='payments' placeholder='付款方式'
                      :value-single="true"
                      :search="false"
                      close-on-select>
            </v-select>
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body" title="参数:写卡状态">写卡状态</label>
            <input type="text" v-model="model.f_write_card" disabled=disabled style="width: 60%" class="input_search">

            <!--            <input type="text" v-model="model.f_write_card" style="width: 60%" class="input_search">-->
<!--            <v-select :value.sync="model.f_write_card" v-model="model.f_write_card"-->
<!--                      :options='writeCards' placeholder='写卡状态'-->
<!--                      :value-single="true"-->
<!--                      :search="false"-->
<!--                      close-on-select>-->
<!--            </v-select>-->
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">收款金额</label>
            <input type="text" v-model="model.f_collection" disabled=disabled  style="width: 60%" class="input_search">
          </div>
          <!--<div class="col-sm-4 form-group">-->
            <!--<label class="font_normal_body">收据类型</label>-->
            <!--<input type="text" v-model="model.f_bill_style" style="width: 60%" class="input_search">-->
          <!--</div>-->
        </div>
        <div class="row">
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">转账单位</label>
            <input type="text" v-model="model.f_banktransfer_person" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">转账金额</label>
            <input type="text" v-model="model.f_banktransfer_money" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">转账日期</label>
            <input type="text" v-model="model.f_banktransfer_date" disabled=disabled style="width: 60%" class="input_search">
<!--            <datepicker id="f_banktransfer_date" placeholder="转账日期" style="width:60%"-->
<!--                        v-model="model.f_banktransfer_date"-->
<!--                        :value.sync="model.f_banktransfer_date"-->
<!--                        :format="'yyyy-MM-dd HH:mm:ss'"-->
<!--                        :show-reset-button="true">-->
<!--            </datepicker>-->
          </div>
        </div>
        <div class="row">
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">操作时间</label>
            <input type="text" v-model="model.f_delivery_date" disabled=disabled  style="width: 60%"  class="input_search">
<!--            <datepicker id="f_delivery_date" placeholder="操作时间" style="width:60%"-->
<!--                        v-model="model.f_operate_date"-->
<!--                        :value.sync="model.f_operate_date"-->
<!--                        :format="'yyyy-MM-dd HH:mm:ss'"-->
<!--                        :show-reset-button="true">-->
<!--            </datepicker>-->
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">购气气量</label>
            <input type="text" v-model="model.f_pregas" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">购气金额</label>
            <input type="text" v-model="model.f_preamount" disabled=disabled style="width: 60%" class="input_search">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-4 form-group">
            <label class="font_normal_body" title="参数:操作人员查询">操作人员</label>
            <input type="text" v-model="model.f_operator" disabled=disabled style="width: 60%" class="input_search">

<!--            <v-select :value.sync="model.f_operator"-->
<!--                      v-model="model.f_operator"-->
<!--                      :value-single="true"  @change="selectoperator()"-->
<!--                      :options='foperator'-->
<!--                      close-on-select></v-select>-->
            <!--                      @click="selectoperator"-->
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">所属部门</label>
            <input type="text" v-model="model.f_depname" disabled=disabled style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4 form-group">
            <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-4 form-group">
            <label class="font_normal_body" title="打印格式">收据类型</label>
            <input type="text" v-model="model.f_bill_style" disabled=disabled style="width: 60%" class="input_search">

<!--            <v-select id="f_bill_style"-->
<!--                      placeholder='收据类型'-->
<!--                      :value-single="true"-->
<!--                      :value.sync="model.f_bill_style"-->
<!--                      :options='equipmentType'-->
<!--                      close-on-select clear-button>-->
<!--            </v-select>-->
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body" title="开票标识">开票标识</label>
            <v-select :value.sync="model.f_isbill" v-model="model.f_isbill"
                      :options='isbills' placeholder='开票标识'
                      :value-single="true"
                      :search="false"
                      close-on-select>
            </v-select>
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">开发票人</label>
            <input type="text" v-model="model.f_bill_operator" disabled=disabled  style="width: 60%" class="input_search">
          </div>

        </div>
        <div class="row">
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">发票时间</label>
            <!--            <datepicker id="f_bill_date" placeholder="开发票时间" style="width:60%"-->
            <!--                        v-model="model.f_bill_date"-->
            <!--                        :value.sync="model.f_bill_date"-->
            <!--                        :format="'yyyy-MM-dd'"-->
            <!--                        :show-reset-button="true">-->
            <!--            </datepicker>-->
            <input type="text" v-model="model.f_bill_date" disabled=disabled  style="width: 60%" class="input_search">
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">流&ensp;水&ensp;号</label>
            <input type="text" v-model="model.f_serial_id" style="width: 60%" class="input_search">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-12 form-group">
            <label class="font_normal_body">备注信息</label>
            <input type="text" v-model="model.f_comments"  style="width: 85%" class="input_search">
          </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  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 {
        equipmentType: this.$appdata.getParam('打印格式') ? [{label: '', value: ''}, ...this.$appdata.getParam('打印格式')] : [],
        // 构建数组来存储对象
        editbank: true,
        uploadText: '收费',
        showfiles: false,
        recordList: [],
        fileNameSet: {
          'f_payment': '收费形式',
          'f_isbill': '开票标识',
          'f_serial_id': '流水号'
        }
      }
    },
    props: {
      oldmodel: Object,
      model: Object
    },

    ready () {
      if (this.$login.r.includes('维护银行转账信息')) {
        this.editbank = true
      }
      this.oldmodel = JSON.parse(JSON.stringify(this.model))
      this.model.f_bill_state = [this.oldmodel]
      console.log('看看收费id', this.oldmodel)
    },
    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
      },
      addressValid (val) {
      },
      save () {
        // console.log(this.model.key)
        //
        for (var item in this.model) {
          if (this.model[item] != this.oldmodel[item] && this.model[item] !='s_timestamp') {
            var car = {
              chinesename: this.fileNameSet[item],
              fieldname: item,
              tablename: 't_sellinggas',
              oldvalue: this.oldmodel[item],
              newvalue: this.model[item],
              state: '有效',
              modifitime: Util.toStandardTimeString(),
              operator: this.$login.f.name,
              sellingas_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的值', car)
          }
        }
        if (this.model.f_bill_date !== '' || this.model.f_bill_date === undefined) {
          this.model.f_bill_operator = this.$login.f.name
        }
        this.$resetpost('rs/logic/saveing', {data: {recordlist: this.recordList, newData: this.model}}).then((res) => {
          console.log('this.model', this.model)
        })
        this.$dispatch('close')
      }
    },
    computed: {
      foperator () {
        return [...this.$appdata.getParam('操作人员')]
      },
      positions () {
        return this.$appdata.getParam('收费状态')
      },
      payments () {
        return this.$appdata.getParam('付款方式查询')
      },
      isbills () {
        return this.$appdata.getParam('开票标识')
      },
      writeCards () {
        return this.$appdata.getParam('写卡状态')
      },
      billStyles () {
        return this.$appdata.getParam('收据类型')
      }
    },
    watch: {
      'model.f_user_name' () {
        if (this.model.f_operator) {
          this.selectoperator()
        }
      },
      'model.f_operator' () {
        if (this.model.f_operator) {
          this.selectoperator()
        }
      }
    }
  }
</script>
