<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="角色类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roleId">
              <j-dict-select-tag type="list" v-model="model.roleId" dictCode="travel_category,category_name,id" placeholder="请选择角色类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="角色头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roleHead">
              <j-image-upload isMultiple  v-model="model.roleHead" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="角色名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roleName">
              <a-input v-model="model.roleName" placeholder="请输入角色名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="角色等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roleLevel">
              <a-input v-model="model.roleLevel" placeholder="请输入角色等级"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预约时间(1-金牌，2-专业)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="preTime">
              <a-input v-model="model.preTime" placeholder="请输入预约时间(1-金牌，2-专业)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预约价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input-number v-model="model.price" placeholder="请输入预约价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预约信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="preInfo">
              <a-input v-model="model.preInfo" placeholder="请输入预约信息"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="推荐度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recommend">
              <a-input v-model="model.recommend" placeholder="请输入推荐度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="专业擅长" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skill">
              <a-input v-model="model.skill" placeholder="请输入专业擅长"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="个人简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brief">
              <a-input v-model="model.brief" placeholder="请输入个人简介"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属用户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <j-dict-select-tag type="list" v-model="model.userId" dictCode="han_hai_member,nick_name,id" placeholder="请选择所属用户" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提前预约" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="adPre">
              <a-input v-model="model.adPre" placeholder="请输入提前预约"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开放时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openTime">
              <a-input v-model="model.openTime" placeholder="请输入开放时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TravelRoleInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/travelRoleInfo/travelRoleInfo/add",
          edit: "/travelRoleInfo/travelRoleInfo/edit",
          queryById: "/travelRoleInfo/travelRoleInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>