<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="title">
              <a-input v-model="model.title" 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-textarea v-model="model.brief" rows="4" placeholder="请输入简介" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="image">
              <j-image-upload isMultiple  v-model="model.image" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="原价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="priceOrigin">
              <a-input-number v-model="model.priceOrigin" placeholder="请输入原价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="优惠价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="priceDiscount">
              <a-input-number v-model="model.priceDiscount" placeholder="请输入优惠价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="列表标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tagList">
              <a-input v-model="model.tagList" placeholder="请输入列表标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="详情标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tagDetails">
              <a-input v-model="model.tagDetails" placeholder="请输入详情标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="已报名人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyNum">
              <a-input-number v-model="model.applyNum" placeholder="请输入已报名人数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行程亮点 " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="special">
              <j-editor v-model="model.special" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="课程目标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="target">
              <j-editor v-model="model.target" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="详细行程" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="process">
              <j-editor v-model="model.process" />
            </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-col :span="24">
            <a-form-model-item label="是否限时优惠" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDiscount">
              <j-dict-select-tag type="list" v-model="model.isDiscount" dictCode="is_true" placeholder="请选择是否限时优惠" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否口碑爆款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isHot">
              <j-dict-select-tag type="list" v-model="model.isHot" dictCode="is_true" placeholder="请选择是否口碑爆款" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否新上线路" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isNew">
              <j-dict-select-tag type="list" v-model="model.isNew" dictCode="is_true" placeholder="请选择是否新上线路" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addressId">
              <j-dict-select-tag type="list" v-model="model.addressId" dictCode="studytour_address,title,id" placeholder="请选择地点" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="适合年龄" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ageId">
              <j-dict-select-tag type="list" v-model="model.ageId" dictCode="studytour_age,title,id" placeholder="请选择适合年龄" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="活动时长" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="timeId">
              <j-dict-select-tag type="list" v-model="model.timeId" dictCode="studytour_time,title,id" placeholder="请选择活动时长" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="活动分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryId">
              <j-dict-select-tag type="list" v-model="model.categoryId" dictCode="studytour_category,title,id" placeholder="请选择活动分类" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否下架" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDel">
              <j-dict-select-tag type="list" v-model="model.isDel" dictCode="is_true" placeholder="请选择是否下架" />
            </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: 'StudytourActivityForm',
    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: {
           phone: [
              { required: false},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
           ],
        },
        url: {
          add: "/studytourActivity/studytourActivity/add",
          edit: "/studytourActivity/studytourActivity/edit",
          queryById: "/studytourActivity/studytourActivity/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>