<template>
  <a-modal
    title="操作"
    style="top: 20px;"
    :width="800"
    v-model="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
  >
    <a-form :form="form">
      <a-form-item style="display:none">
        <a-input v-decorator="['id']"/>
      </a-form-item>
      <a-form-item style="display:none">
        <a-input v-decorator="['version']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="展厅编码">
        <a-input placeholder="展厅编码" v-decorator="['showroomCode']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="展厅名称">
        <a-input placeholder="展厅名称" v-decorator="['meetingName']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="容纳人数">
        <a-input placeholder="容纳人数" v-decorator="['capacityNum']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="扩充人数">
        <a-input placeholder="扩充人数" v-decorator="['expandNum']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="室内图片url">
        <a-input placeholder="室内图片url" v-decorator="['indoorPicUrl']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="地址">
        <a-input placeholder="地址" v-decorator="['address']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="是否展示">
        <a-input placeholder="是否展示" v-decorator="['isShow']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="负责人姓名">
        <a-input placeholder="负责人姓名" v-decorator="['headName']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="负责人手机号">
        <a-input placeholder="负责人手机号" v-decorator="['headPhone']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="会议描述">
        <a-input placeholder="会议描述" v-decorator="['content']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="创建者">
        <a-input placeholder="创建者" v-decorator="['createBy']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="更新者">
        <a-input placeholder="更新者" v-decorator="['updateBy']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="版本">
        <a-input placeholder="版本" v-decorator="['version']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="房间id">
        <a-input placeholder="房间id" v-decorator="['roomId']"/>
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="展厅面积">
        <a-input placeholder="展厅面积" v-decorator="['area']"/>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
    import {saveShowroom} from '@/api/admin/meeting/showroom'
    import pick from 'lodash.pick'

    export default {
  name: 'ShowroomModal',
  props: {
  },
  components: {
  },
  data () {
    return {
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      mdl: {},
      form: this.$form.createForm(this)
    }
  },
  beforeCreate () {
  },
  created () {
  },
  methods: {
    add () {
      this.form.resetFields()
      this.edit({ id: 0 })
    },
    edit (record) {
      this.mdl = Object.assign(record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.mdl, 'id', 'showroomCode', 'meetingName', 'capacityNum', 'expandNum', 'indoorPicUrl', 'address', 'startTime', 'endDate', 'isShow', 'headName', 'headPhone', 'content', 'createBy', 'createTime', 'updateBy', 'updateTime', 'version', 'deleteFlag', 'roomId', 'area'))
      })
    },
    handleSubmit (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('Received values of form: ', values)
          this.confirmLoading = true
          saveShowroom(values).then(res => {
            if (res.code === 0) {
              this.$message.success('保存成功')
              this.$emit('ok')
              this.visible = false
            } else {
              this.$message.error(res.msg)
            }
          }).catch(() => {
            this.$message.error('系统错误，请稍后再试')
          }).finally(() => {
            this.confirmLoading = false
          })
        }
      })
    }
  },
  watch: {
    /*
      'selectedRows': function (selectedRows) {
        this.needTotalList = this.needTotalList.map(item => {
          return {
            ...item,
            total: selectedRows.reduce( (sum, val) => {
              return sum + val[item.dataIndex]
            }, 0)
          }
        })
      }
      */
  }
}
</script>
