<template>
  <div class="auto">
    <validator name='v'>
      <div class="datapanel 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-6 form-group form-fix-width">
            <label class="control-label">功能名称：</label>
            <input type="text" v-model="model.name" class="form-control full-with" id="f_userid" placeholder="编号">

          </div>
          <div class="col-sm-6 form-group form-fix-width">
            <label class="control-label">功能连接：</label>
            <input type="text"  v-model="model.link" class="form-control full-with" placeholder="功能连接">
          </div>
          <div class="col-sm-6 form-group form-fix-width">
            <label class="control-label">页面连接：</label>
            <input type="text"  v-model="model.navigate" class="form-control full-with" placeholder="页面连接">
          </div>
          <div class="col-sm-6 form-group form-fix-width">
            <label class="control-label">显示方式：</label>
            <v-select :value.sync="model.showmodel" v-model='model.showmodel'
                      :options='showmodels' placeholder='请选择' close-on-select :clear-button='true'></v-select>
        </div>
          <div class="col-sm-6 form-group form-fix-width">
            <label class="control-label">图标：</label>
            <input type="text" v-model="model.icon" class="form-control full-with" id="f_userid" placeholder="图标路径">
          </div>
          <div class="col-sm-12 form-group form-fix-width">
            <label class="control-label">描述：</label>
            <textarea class="form-control" rows="3" style="width: 100%;" v-model="model.f_description"></textarea>
          </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>
    </validator>
  </div>
</template>

<script>
import co from 'co'
import {HttpResetClass} from "vue-client";
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 new HttpResetClass().load('POST', 'rs/data/save', {data:self.model},{resolveMsg:null, rejectMsg:null})
  console.log(msg)
  //yield self.$showMessage(msg.data)
  yield self.$showMessage(msg.bodyText)
  self.$back('refresh')
}

export default {
  title: '修改功能',
  props: ['parent', 'data'],
  data () {
    return {
      model: {
        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: {
    confirm () {
      let gen = saveGen(this)
      return co(gen)
    }
  }
}

</script>

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