<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row type="flex">
          <a-col :span="12">
            <a-form-model-item label="订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-input v-model="model.tenantId" placeholder="请输入关联租户"  ></a-input> -->
              {{model.code}}
            </a-form-model-item>
            <a-form-model-item label="付款类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-input v-model="model.hotelId" placeholder="请输入关联酒店"  ></a-input> -->
              {{model.payType==1?'到店支付':'微信支付'}}
            </a-form-model-item>
            <a-form-model-item label="下单时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-input-number v-model="model.userId" placeholder="请输入用户ID" style="width: 100%" /> -->
              {{model.createTime}}
            </a-form-model-item>
            <a-form-model-item label="预定时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-input-number v-model="model.messageType" placeholder="请输入留言类型 1 投诉 2建议" style="width: 100%" /> -->
              {{model.createTime}}
            </a-form-model-item>
            <a-form-model-item label="会员编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-textarea v-model="model.images" rows="4" placeholder="请输入图片逗号分隔" /> -->
              {{model.memberCardId}}
            </a-form-model-item>
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-textarea v-model="model.contentBody" rows="4" placeholder="请输入内容" /> -->
              {{model.contactName}}
            </a-form-model-item>
            <a-form-model-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-input v-model="model.userName" placeholder="请输入姓名"  ></a-input> -->
              {{model.mobile}}
            </a-form-model-item>
            <a-form-model-item label="身份证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-input v-model="model.userMobile" placeholder="请输入手机号"  ></a-input> -->
            </a-form-model-item>
            <a-form-model-item label="预定天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
              <!-- <a-input v-model="model.roomNo" placeholder="请输入房号"  ></a-input> -->
              {{model.day}}
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
              <a-card title="订单信息" :bordered="false" style="width: 100%">
                <!-- <p> -->
                  <a-form-model-item label="订房状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
                    {{roomStatusFilter(model.status)}}
                  </a-form-model-item>
                <!-- </p> -->
                <!-- <p> -->
                  <a-form-model-item label="付款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
                    {{model.money}}
                  </a-form-model-item>
                <!-- </p> -->
                <!-- <p> -->
                  <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
                    {{model.remark}}
                  </a-form-model-item>
                <!-- </p> -->
                <!-- <p> -->
                  <a-form-model-item label="积分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
                    {{'0'}}
                  </a-form-model-item>
                  <a-form-model-item label="会员折扣" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
                    {{model.memberZk}}
                  </a-form-model-item>
                  <a-form-model-item label="优惠券" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
                    {{model.couponMoney}}
                  </a-form-model-item>
                  <a-form-model-item label="免房券" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="" style="margin-bottom:0px;">
                    {{'--'}}
                  </a-form-model-item>
                <!-- </p> -->
              </a-card>
          </a-col>
          <a-col :span="24">
            <h2>订单详情</h2>
            <a-table :columns="columns" :dataSource="[model]"></a-table>
          </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: 'CesOrderMessageForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        columns: [
          {
            title: "名称",
            align: "center",
            dataIndex: "layoutName",
          },
          {
            title: "价格",
            align: "center",
            dataIndex: "",
            customRender: function (text) {
              return Number(text.money) + Number(text.memberZk) + Number(text.couponMoney)
            }
          },
          {
            title: "入住时间",
            align: "center",
            dataIndex: "startDate",
          },
          {
            title: "离店时间",
            align: "center",
            dataIndex: "endDate",
          },
        ],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           tenantId: [
              { required: true, message: '请输入关联租户!'},
           ],
           hotelId: [
              { required: true, message: '请输入关联酒店!'},
           ],
           messageType: [
              { required: true, message: '请输入留言类型 1 投诉 2建议!'},
           ],
           createDate: [
              { required: true, message: '请输入创建时间!'},
           ],
        },
        url: {
          add: "/order/cesOrderMessage/add",
          edit: "/order/cesOrderMessage/edit",
          queryById: "/order/cesOrderMessage/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        console.log(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;
            })
          }
         
        })
      },
      roomStatusFilter(status){
        switch (status) {
          case 1:
            return '未付款';
          case 2:
            return '已付款';
          case 3:
            return '已取消';
          case 4:
            return '已完成';
          case 5:
            return '待入住';
          case 6:
            return '已入住';
          case 7:
            return '退款中';
          default: '--'
            break;
        }
      }
    }
  }
</script>