<template>
  <div class="auto">
    <div class="datapanel form-horizontal" style="min-height: 400px">
      <h3 class="txtline">&nbsp;&nbsp;用户信息</h3>
      <h3 class="txtline">&nbsp;&nbsp;上一级【{{parentname}}】</h3>
      <div class="row">
        <div class="col-sm-6 form-group form-fix-width">
          <label class="control-label">姓名：</label>
          <input type="text" required class="form-control"
                 placeholder="请输入姓名" v-model="model.name">
        </div>
        <div class="col-sm-6 form-group form-fix-width">
          <label class="control-label">登录名：</label>
          <input type="text" required class="form-control"
                 placeholder="请输入登录名" v-model="model.ename">
        </div>
        <div class="col-sm-6 form-group form-fix-width">
          <label class="control-label">电话号码：</label>
          <input type="text" required class="form-control"
                 placeholder="请输入电话号码" v-model="model.f_user_telephone">
        </div>
        <div class="col-sm-6 form-group form-fix-width">
          <label class="control-label">银行名称：</label>
          <v-select :value.sync="model.f_bankname"
                    :options='selects' placeholder='请选择'
                    close-on-select clear-button
          ></v-select>
        </div>
      </div>
      <button @click="confirm()" class="btn btn-success col-sm-1 col-sm-offset-2" :disabled="!$v.valid">
        <span class="glyphicon glyphicon-floppy-disk"></span>保存
      </button>
      <button @click='$back()' class="btn btn-default col-sm-1 col-sm-offset-1">
        <span class=" glyphicon glyphicon-log-out"></span>返回
      </button>
    </div>
  </div>
</template>

<script>
import co from 'co'
import {HttpResetClass} from "vue-client";
let saveGen = function * (self) {
  self.deliver.f_userid = self.model.f_userid
  self.deliver.lastinputdate = self.model.lastinputdate
  // self.model.f_fengongsi = self.model.f_fengongsi[0]
  // self.model.f_fengongsinum = self.model.f_fengongsinum[0]
  // self.model.f_fapiaotaitu = self.model.f_fapiaotaitu[0]
  // self.model.f_fgsshuihao = self.model.f_fgsshuihao[0]
  // self.model.f_fgsdizhi = self.model.f_fgsdizhi[0]
  // self.model.f_fgsdianhua = self.model.f_fgsdianhua[0]
  // self.model.operpage = self.model.operpage[0]
  if (typeof self.model.f_bankname === 'object' ) {
    if (self.model.f_bankname.length === 0) {
      self.model.f_bankname = ''
    } else {
      self.model.f_bankname = self.model.f_bankname[0]
    }
  }
  // yield new HttpResetClass().load('POST', '/rs/logic/errorhandle', {data: self.deliver})
  // let res = yield new HttpResetClass().load('POST', 'rs/data/save', {data: {ids: self.userids, roleid: self.data.id}})
  // console.log(self.model)
  let msg = yield new HttpResetClass().load('POST', 'rs/data/save', {data: self.model})
   // 通知项目保存成功。
  yield self.$showMessage(msg.bodyText)
  self.$back('refresh')
}
/* let readFile = function (self) {
  console.log(self)
  var fileiput = document.getElementById('fileiput')
  var file = fileiput.files[0]
  if (!/image\/\w+/.test(file.type)) {
      // alert ("请确保文件为图像类型")
    return false
  }
  var reader = new FileReader()
  reader.readAsDataURL(file)
  reader.onload = function (e) {
    self.img = 'this.result'
    self.img = '<img src="' + this.result + '" alt="" height="150" width="150"/>'
  }
}*/
export default {
  title: '项目编写',
  props: ['parent', 'data'],
  data () {
    return {
      model: {
        parentid: '',
        id: '',
        name: '',
        ename: '',
        touxiang: '',
        f_fengongsi: '',
        f_fengongsinum: '',
        f_fapiaotaitu: '',
        f_fgsshuihao: '',
        f_fgsdizhi: '',
        f_fgsdianhua: '',
        gonghao: '',
        f_invoicenum: '',
        operpage: '',
        f_bankname: '',
        maxgassellnum: '',
        myxgmax: '',
        hemax: '',
        gyxgmax: '',
        f_description: '',
        f_user_telephone: '',
        resourcetype: 'user'
      },
      deliver: {}, // 业务逻辑需要的参数
      img: '',
      parentname: ''
    }
  },
  methods: {
    confirm () {
      if (this.model.name === '') {
        this.$showMessage('姓名不能为空')
      } else if (this.model.ename === '') {
        this.$showMessage('登录名不能为空')
      } else {
        let gen = saveGen(this)
        return co(gen)
      }
    }
  },
  computed: {
    selects () {
      return [{label: '请选择', value: ''}, ...this.$appdata.getParam('银行名称')]
      // [{label: '', value: ''},
      //    {label: '湖北和芯科技', value: '湖北和芯科技'},
      //    {label: '奥枫科技', value: '奥枫科技'}
      // ]
    }
  },
  ready () {
    /* console.log('FileReader type is ' + typeof FileReader)
    let that = this
    var input = document.getElementById('fileiput')
    if (typeof FileReader === 'undefined') {
      that.img = '抱歉，你的浏览器不支持 FileReader'
      input.setAttribute('disabled', 'disabled')
    } else {
      input.addEventListener('change', function () { readFile(that) }, false)
    }*/
    // 将要修改的值设置默认值
    if (this.parent) {
      this.model.parentid = this.parent.id
      this.parentname = this.parent.name
      this.model = Object.assign({}, this.model, this.data)
    } else {
      console.log(this.data)
      this.model= Object.assign({}, this.model, this.data)
    }
  }
}

</script>
