<template>
  <div class="auto select-overspread">
    <div class="panel panel-info">
      <div class="panel-heading">
        <h3 class="panel-title">添加用户信息</h3>
      </div>
    </div>
    <validator name="v">
      <form class="form-horizontal">
        <div class="col-sm-12 form-group" style="margin-top: 100px;">
          <div class="col-sm-4" :class="[$v.f_gasmun.required ? 'has-error': '']">
            <label class="col-sm-6 control-label">供气量:</label>
            <div class="col-sm-4">
              <input type="text"  onkeyup="value=value.replace(/[^\.\d]/g,'')"  onblur="value=value.replace(/[^\.\d]/g,'')" onblur="this.v();"  class="form-control" v-model="model.f_gasmun" v-validate:f_gasmun='{required: true }'/>
            </div>
          </div>
          <div class="col-sm-4" :class="[$v.f_gasunits.required ? 'has-error': '']">
            <label class="col-sm-6 control-label">供气单位:</label>
            <div class="col-sm-4">
              <input type="text" class="form-control" v-model="model.f_gasunits" v-validate:f_gasunits='{required: true }'/>
            </div>
          </div>
          <!--<div class="col-sm-4"  :class="[$v.fcredentials.required ? 'has-error select-error': '']">-->
            <!--<label class="col-sm-6 control-label">证件类型:</label>-->
            <!--<div class="col-sm-4">-->
              <!--<input type="text" v-show="false" v-model="$refs.fcredentials.selectedItems" v-validate:fcredentials='{required: true }'>-->
              <!--<v-select :value.sync="model.f_credentials" v-model="model.f_credentials" v-ref:fcredentials :options='credentials'-->
              <!--placeholder='请选择' close-on-select></v-select>-->
            <!--</div>-->
          <!--</div>-->
          <div class="col-sm-4"  :class="[$v.f_gasdate.required ? 'has-error select-error': '']">
          <label for="startDate" class="col-sm-6 control-label">供气时间:</label>
            <div class="col-sm-4" >
          <datepicker id="startDate" placeholder="开始日期"
                      v-model="model.f_gasdate"
                      :value.sync="model.f_gasdate"
                      :disabled-days-of-Week="[]"
                      :format="'yyyy-MM-dd HH:mm:ss'"
                      :show-reset-button="reset">
          </datepicker>
            </div>
          </div>
        </div>
        <div class="col-sm-12 form-group">
          <div class="col-sm-4" :class="[$v.f_department.required ? 'has-error': '']">
            <label class="col-sm-6 control-label">操作部门:</label>
            <div class="col-sm-4">
              <input type="text" class="form-control" v-model="model.f_department" v-validate:f_department='{required: true }'/>
            </div>
          </div>
        </div>
        <!--<div class="col-sm-12 form-group">-->
          <!--<div class="col-sm-4"  :class="[$v.finputtortype.required ? 'has-error select-error': '']">-->
            <!--<label class="col-sm-6 control-label">操作部门:</label>-->
            <!--<div class="col-sm-4">-->
              <!--<input type="text" v-show="false" v-model="$refs.finputtortype.selectedItems" v-validate:finputtortype='{required: true }'>-->
              <!--<v-select :value.sync="model.f_inputtor_type" v-model="model.f_inputtor_type" v-ref:finputtortype :options='inputtortype'-->
              <!--placeholder='请选择' close-on-select></v-select>-->
            <!--</div>-->
          <!--</div>-->

        <!--</div>-->
        <div class="col-sm-12 form-group">
          <div class="col-sm-4">
            <label class="col-sm-6 control-label">分公司:</label>
            <div class="col-sm-4">
              <input type="text" class="form-control" v-model="model.f_filiale" disabled/>
            </div>
          </div>
          <div class="col-sm-4">
            <label class="col-sm-6 control-label">操作时间:</label>
            <div class="col-sm-4">
              <input type="text" class="form-control" v-model="model.f_date" disabled/>
            </div>
          </div>
          <div class="col-sm-4">
            <label class="col-sm-6 control-label">操作人:</label>
            <div class="col-sm-6">
              <input type="text" class="form-control" v-model="model.f_operator" disabled/>
            </div>
          </div>
        </div>
      </form>
    </validator>
    <div class="col-sm-12 form-group" style="margin-top: 40px;">
      <center>
        <button type="button" @click="confirm()" class="btn btn-primary" style="width:80px; margin-left:40px;" :disabled='$v.invalid'>
          保存
        </button>
        <button  type="button" @click="reset()" class="btn btn-warning" style="width:80px; margin-left:40px;">
          撤销
        </button>
        <button type="button" @click="openFile" class="btn btn-primary" style="width:80px; margin-left:40px;">
          导入
        </button>

      </center>
    </div>
  </div>
  <modal :show.sync="showFile" v-ref:modal backdrop="false">
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="closeFile"><span>&times;</span></button>
      <h4 class="modal-title">档案导入</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="form-group">
        <file-upload class="my-file-uploader" name="recordExcel"
                     action="rs/file/uploadFile" tagname="文件导入" :headers="headers" v-ref:file></file-upload>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer"></footer>
  </modal>
</template>
<script>
import * as Util from '../../../stores/Util'
import  {HttpResetClass} from 'vue-client'

export default {
  title: '添加人员信息',
  data () {
    return {
      model: {
        // f_filiale: Util.f.f_fengongsi,
        // f_operator: Util.f.name,
        //f_filiale: this.$login.f.name,
        f_operator: this.$login.f.name,
        f_date: Util.toStandardDateString(),
        f_filiale: this.$login.f.f_fengongsi,
        //f_filiale : null,
        f_gasdate :Util.toStandardTimeString()
      },
      showFile : false
    }
  },
  ready () {
    this.$dispatch('hiddenpaged')
  },
  methods: {
    closeFile (){
      this.showFile = false
    },
    openFile (){
      this.showFile = true
    },
    confirm() {
      //this.model.f_credentials = this.model.f_credentials ? this.model.f_credentials[0] : ''
      //this.model.f_inputtor_type = this.model.f_inputtor_type ? this.model.f_inputtor_type[0] : ''
      //this.model.f_parentname = this.model.f_parentname ? this.model.f_parentname[0] : ''
      //供气量，供气单位
      console.log(typeof this.model.f_filiale);
      console.log(this.model);

        this.model.f_gasdate //= this.model.startDate;//供气时间赋值
        //姓名相同所以不需要赋值
        this.model.f_department //=this.model.f_department;//操作部门
        this.model.f_filiale  //= this.model.f_fengongsi;//分公司赋值
        this.model.f_date  //= this.model.f_operator_date;//操作日期赋值
        this.$resetpost('rs/entity/t_supplygas', this.model).then(() => {
          this.reset()
        })


    },
    reset () {
      this.$dispatch('close')
    }
  },
  computed: {
    // credentials (){
    //   return AppData.getParam("证件类型")
    // },
    // inputtortype () {
    //   return AppData.getParam("角色类型")
    // },
    // parentname () {
    //   return AppData.getParam("营业网点")
    // }
  },
  events: {
    async onFileUpload (file, res) {
      let data = {
        tablename: 't_supplygas',
        filepath: res.f_downloadpath,
        f_filiale: this.model.f_filiale,
        f_date: this.model.f_date,
        f_operator: this.model.f_operator
      }
      var num = this.$parent.$refs.personquery.model.rows.length
      console.log('num',num)
      let http2 = new HttpResetClass()
      await http2.load('POST','rs/logic/recordImport', data, {resolveMsg: '上传成功', rejectMsg: '上传失败'}).then((res) => {
        // 刷新
        this.$parent.$refs.personquery.model.search('1=1').then((re) =>{
          var numNew = this.$parent.$refs.personquery.model.rows.length
          console.log('numNew',numNew)
          console.log('res.data',res.data)
          if (num + res.data != numNew){
            this.$showMessage("存在重复数据，已覆盖"+(num+res.data-numNew)+"条！")
          }
        })
        this.closeFile()
      })
    }
  }
}
</script>
