<template>
  <div class="auto">
    <validator name='v'>
      <div class="form-horizontal" style="min-height: 400px">
        <h3 class="txtline">&nbsp;&nbsp;功能信息</h3>
        <h3 class="txtline">&nbsp;&nbsp;上一级【{{parent.name}}】</h3>

        <div class="row">
          <div class="col-sm-3"></div>
          <div class="col-sm-3">
            <label class="font_normal_body" >功能名称</label>
            <input type="text" v-if="model.id==''" v-model="model.name" style="width:60%" class="input_search full-with" id="f_userid" placeholder="功能名称">
            <input type="text" v-if="model.id!=''" v-model="model.name"  readonly style="width:60%" class="input_search full-with" id="f_userid" placeholder="功能名称">
          </div>
          <div class="col-sm-3">
            <label class="font_normal_body" >功能连接</label>
            <input type="text"  v-model="model.link" style="width:60%" class="input_search full-with" placeholder="功能连接">
          </div>
        </div>

        <div class="row">
          <div class="col-sm-3"></div>
          <div class="col-sm-3">
            <label class="font_normal_body" >页面连接</label>
            <input type="text"  v-model="model.navigate" style="width:60%" class="input_search full-with" placeholder="页面连接">
          </div>
          <div class="col-sm-3">
            <label class="font_normal_body" >&nbsp;&nbsp;&nbsp;图标&nbsp;&nbsp;&nbsp;</label>
            <input type="text" v-model="model.icon" style="width:60%" class="input_search full-with" id="f_userid" placeholder="图标路径">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-3"></div>
          <div class="col-sm-6">
            <label class="font_normal_body" >&nbsp;&nbsp;&nbsp;描述&nbsp;&nbsp;&nbsp;</label>
            <textarea class="ver-textarea" style="width:80%" rows="4" v-model="model.f_description"></textarea>
          </div>
        </div>

        <button @click="confirm()" class="btn button_search col-sm-1 col-sm-offset-5" style="width: 70px" :disabled="!$v.valid">
          <span class="glyphicon glyphicon-floppy-disk"></span>保存
        </button>
        <button @click='$back()' class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px">
          <span class=" glyphicon glyphicon-log-out"></span>返回
        </button>
      </div>
    </validator>
  </div>
</template>

<script>
import co from 'co'

let saveGen = function * (self) {
  self.model.showmodel = self.model.showmodel[0]
  //let msg = yield self.$post('rs/data/save', {data:self.model},{resolveMsg:null, rejectMsg:null})
  let msg = yield self.$http.post('rs/data/save', {data:self.model},{resolveMsg:null, rejectMsg:null})
  console.log(msg)
  //yield self.$showMessage(msg.data)
  if(Number.isNaN(Number(msg.bodyText))){
    yield self.$showMessage(msg.bodyText)
  }else {
    yield self.$showMessage("添加成功")
  }
  self.flush()
  self.$back('refresh')
}

export default {
  title: '修改功能',
  props: ['parent', 'data'],
  data () {
    return {
      model: {
        loginid:this.$login.f.id,
        id: '',
        f_parentname: '',
        name: '',
        link: '',
        navigate: '',
        showmodel: '',
        icon: '',
        f_description: '',
        parentid: '',
        resourcetype: 'function'
      },
      showmodels: [
        {label: '右边', value: '右边'},
        {label: '弹出', value: '弹出'}
      ]
    }
  },
  ready() {
    this.model.f_parentname = this.parent.name
    this.model.parentid = this.parent.id
    this.model = Object.assign({}, this.model, this.data)
    this.model.showmodel = this.model.showmodel.length === 0 ? ['右边'] : [this.model.showmodel]
  },
  methods: {
    flush(){
      this.$parent.$parent.$parent.$parent.flush()
    },
    confirm () {
      let gen = saveGen(this)
      return co(gen)
    }
  }
}

</script>

<style media="screen">
  .full-with {
    width: 100%;
  }
</style>
