<template>
  <a-form :form="form" ref="form">
    <a-modal
      title="业务操作编辑"
      v-model="visible"
      :maskClosable="false"
      class="cust-modal"
    >
      <template slot="footer">
        <a-button key="back" @click="close">返回</a-button>
        <a-button key="submit" type="primary" @click="handleOk">
          确认
        </a-button>
      </template>

        <a-form-item label='名称' :labelCol="{ span: 5 }" :wrapperCol="{ span: 17 }">
          <a-input v-decorator="['name',{rules: [{ required: true, message: '请输入名称' }]}]" placeholder="请输入名称"/>
        </a-form-item>
        <a-form-item label='key' :labelCol="{ span: 5 }" :wrapperCol="{ span: 17 }">
          <a-input style="width: 100%" v-decorator="['operateKey',{rules: [{ required: true, message: '请输入key' }]}]" placeholder="请输入key"/>
        </a-form-item>
    </a-modal>
  </a-form>
</template>
<script>
  import pick from 'lodash.pick'

  let initData = {
    name: '',
    operateKey: ''
  }
  let propertyList = mapKeyToList(initData);

  export default {
    name: 'SysBusinessOperateItemDetailCom',
    beforeCreate() {
      this.form = this.$form.createForm(this)
      for (let property of propertyList) {
        this.form.getFieldDecorator(property)
      }
    },
    data() {
      return {
        visible: false,
      }
    },
    methods: {
      show(data) {
        if (data) {
          this.form.setFieldsValue(pick(data, propertyList))
        } else {
          this.form.setFieldsValue(initData)
        }
        this.visible = true;
      },
      handleOk() {
        this.form.validateFieldsAndScroll((err, values) => {
          if (!err) {
            this.$emit('modifyItem', values)
          }
        })
      },
      close(){
          this.visible = false
      }

    }
  }
</script>