<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="state">
              <j-dict-select-tag type="list" v-model="model.state" dictCode="order_state" placeholder="请选择订单状态" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title">
              <a-input v-model="model.title" placeholder="请输入订单标题"  disabled></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="type">-->
<!--              <j-dict-select-tag type="list" v-model="model.type" dictCode="order_type" placeholder="请选择类型" />-->
<!--            </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="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="open">-->
<!--              <j-dict-select-tag type="list" v-model="model.open" dictCode="is_qd_open" placeholder="请选择是否签到" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="溯源活动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="activityOrderId">-->
<!--              <j-search-select-tag v-model="model.activityOrderId" dict="popularize_activity,title,id"  />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="溯源旅行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="travelOrderId">-->
<!--              <j-search-select-tag v-model="model.travelOrderId" dict="popularize_travel,title,id"  />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="用户标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">-->
<!--              <j-search-select-tag v-model="model.userId" 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="payPrice">
              <a-input-number v-model="model.payPrice" 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="payTuiPrice">
              <a-input-number v-model="model.payTuiPrice" 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="payPrice">
              <a-input-number v-model="model.tuiPrice" placeholder="请输入退款金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="支付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payTime">-->
<!--              <j-date placeholder="请选择支付时间"  v-model="model.payTime" :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="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="isFp">-->
<!--              <j-switch v-model="model.isFp"  ></j-switch>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="是否已评价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPj">-->
<!--              <j-switch v-model="model.isPj"  ></j-switch>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="typePrice">-->
<!--              <a-input-number v-model="model.typePrice" placeholder="请输入类型" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">-->
<!--              <a-input v-model="model.name" 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-col :span="24">-->
<!--            <a-form-model-item label="邀请码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">-->
<!--              <a-input v-model="model.code" 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: 'PopularizeOrderForm',
    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: "/popularizeOrder/popularizeOrder/add",
          edit: "/popularizeOrder/popularizeOrder/edit",
          queryById: "/popularizeOrder/popularizeOrder/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>