<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="enTitle">
              <a-input v-model="model.enTitle" placeholder="请输入英文-旅行标题"  ></a-input>
            </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="startTime">
              <j-date placeholder="请选择开始时间"  v-model="model.startTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文-旅行地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-input v-model="model.address" placeholder="请输入中文-旅行地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="英文-旅行地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enAddress">
              <a-input v-model="model.enAddress" placeholder="请输入英文-旅行地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="活动人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sum">
              <a-input-number v-model="model.sum" placeholder="请输入活动人数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报名人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
              <a-input-number v-model="model.num" placeholder="请输入报名人数" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="虚拟订单下单人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNum">
              <a-input-number v-model="model.orderNum" placeholder="虚拟订单下单人数" style="width: 100%"/>
            </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="adminUser">
              <j-search-select-tag v-model="model.adminUser" dict="han_hai_member,nick_name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否上架" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isOpen">
              <j-switch v-model="model.isOpen"  ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="活动状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
              <j-dict-select-tag type="list" v-model="model.state" dictCode="no_state" placeholder="请选择活动状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="详情图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="iconImage">
              <j-editor v-model="model.iconImage" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文-介绍说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="js">
              <j-editor v-model="model.js" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="英文-介绍说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enJs">
              <j-editor v-model="model.enJs" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文-路线说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lx">
              <j-editor v-model="model.lx" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="英文-路线说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enLx">
              <j-editor v-model="model.enLx" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文-费用说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fy">
              <j-editor v-model="model.fy" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="英文-费用说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enFy">
              <j-editor v-model="model.enFy" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文-需知说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xz">
              <j-editor v-model="model.xz" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="英文-需知说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enXz">
              <j-editor v-model="model.enXz" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文-代理说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dl">
              <j-editor v-model="model.dl" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="英文-代理说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enDl">
              <j-editor v-model="model.enDl" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="签到人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="doNum">
              <a-input-number v-model="model.doNum" placeholder="请输入签到人数" style="width: 100%" disabled/>
            </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: 'PopularizeTravelForm',
    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: {
           adminUser: [
              { required: true, message: '请输入主理人!'},
           ],
        },
        url: {
          add: "/popularizeTravel/popularizeTravel/add",
          edit: "/popularizeTravel/popularizeTravel/edit",
          queryById: "/popularizeTravel/popularizeTravel/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>