<template>
  <div class="app-container">
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
      <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px">
        <el-form-item label="订单号" prop="orderNo">
          <el-input v-model="formData.orderNo" placeholder="请输入订单号"/>
        </el-form-item>
        <el-form-item label="服务名称" prop="goodsTitle">
          <el-input v-model="formData.goodsTitle" placeholder="请输入服务名称"/>
        </el-form-item>
        <el-form-item label="消费类型1会员充值2维修服务" prop="goodsType">
          <el-select v-model="formData.goodsType" placeholder="请选择消费类型1会员充值2维修服务">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="formData.userId" placeholder="请输入用户id"/>
        </el-form-item>
        <el-form-item label="客户id" prop="cusId">
          <el-input v-model="formData.cusId" placeholder="请输入客户id"/>
        </el-form-item>
        <el-form-item label="客户姓名" prop="cusName">
          <el-input v-model="formData.cusName" placeholder="请输入客户姓名"/>
        </el-form-item>
        <el-form-item label="客户手机号" prop="cusPhone">
          <el-input v-model="formData.cusPhone" placeholder="请输入客户手机号"/>
        </el-form-item>
        <el-form-item label="商品原价 元" prop="goodsPrice">
          <el-input v-model="formData.goodsPrice" placeholder="请输入商品原价 元"/>
        </el-form-item>
        <el-form-item label="实付金额 元" prop="payMoney">
          <el-input v-model="formData.payMoney" placeholder="请输入实付金额 元"/>
        </el-form-item>
        <el-form-item label="下单时间" prop="orderTime">
          <el-date-picker clearable v-model="formData.orderTime" type="date" value-format="timestamp"
                          placeholder="选择下单时间"/>
        </el-form-item>
        <el-form-item label="会员优惠金额" prop="reduceMoney">
          <el-input v-model="formData.reduceMoney" placeholder="请输入会员优惠金额"/>
        </el-form-item>
        <el-form-item label="使用会员储值卡的金额" prop="balance">
          <el-input v-model="formData.balance" placeholder="请输入使用会员储值卡的金额"/>
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable v-model="formData.payTime" type="date" value-format="timestamp"
                          placeholder="选择支付时间"/>
        </el-form-item>
        <el-form-item label="支付方式" prop="payType">
          <el-select v-model="formData.payType" placeholder="请选择支付方式">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="支付信息备注" prop="payRemark">
          <el-input v-model="formData.payRemark" placeholder="请输入支付信息备注"/>
        </el-form-item>
        <el-form-item label="线上或者线下 1线上 0线下" prop="isOnline">
          <el-input v-model="formData.isOnline" placeholder="请输入线上或者线下 1线上 0线下"/>
        </el-form-item>
        <el-form-item label="收款账号" prop="receivablesAccount">
          <el-input v-model="formData.receivablesAccount" placeholder="请输入收款账号"/>
        </el-form-item>
        <el-form-item label="订单状态0待支付1已支付" prop="orderStatus">
          <el-radio-group v-model="formData.orderStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="评价详情" prop="commentDesc">
          <el-input v-model="formData.commentDesc" placeholder="请输入评价详情"/>
        </el-form-item>
        <el-form-item label="星级" prop="commentStar">
          <el-input v-model="formData.commentStar" placeholder="请输入星级"/>
        </el-form-item>
        <el-form-item label="评论时间" prop="commentTime">
          <el-date-picker clearable v-model="formData.commentTime" type="date" value-format="timestamp"
                          placeholder="选择评论时间"/>
        </el-form-item>
        <el-form-item label="核销码" prop="accessCode">
          <el-input v-model="formData.accessCode" placeholder="请输入核销码"/>
        </el-form-item>
        <el-form-item label="核销时间" prop="validationTime">
          <el-date-picker clearable v-model="formData.validationTime" type="date" value-format="timestamp"
                          placeholder="选择核销时间"/>
        </el-form-item>
        <el-form-item label="核销人" prop="validationRealName">
          <el-input v-model="formData.validationRealName" placeholder="请输入核销人"/>
        </el-form-item>
        <el-form-item label="核销人id" prop="validationUserId">
          <el-input v-model="formData.validationUserId" placeholder="请输入核销人id"/>
        </el-form-item>
        <el-form-item label="是否使用优惠券 0 未使用 1使用" prop="isCoupon">
          <el-input v-model="formData.isCoupon" placeholder="请输入是否使用优惠券 0 未使用 1使用"/>
        </el-form-item>
        <el-form-item label="优惠券id" prop="couponId">
          <el-input v-model="formData.couponId" placeholder="请输入优惠券id"/>
        </el-form-item>
        <el-form-item label="优惠券代码" prop="couponCode">
          <el-input v-model="formData.couponCode" placeholder="请输入优惠券代码"/>
        </el-form-item>
        <el-form-item label="优惠金额" prop="couponDiscount">
          <el-input v-model="formData.couponDiscount" placeholder="请输入优惠金额"/>
        </el-form-item>
        <el-form-item label="创建人所在部门" prop="deptId">
          <el-input v-model="formData.deptId" placeholder="请输入创建人所在部门"/>
        </el-form-item>
        <el-form-item label="服务id或工单id" prop="goodsId">
          <el-input v-model="formData.goodsId" placeholder="请输入服务id或工单id"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as OrderInfoApi from '@/api/repair/orderinfo';

export default {
  name: "OrderInfoForm",
  components: {},
  data() {
    return {
      // 弹出层标题
      dialogTitle: "",
      // 是否显示弹出层
      dialogVisible: false,
      // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
      formLoading: false,
      // 表单参数
      formData: {
        orderNo: undefined,
        goodsTitle: undefined,
        goodsType: undefined,
        userId: undefined,
        cusId: undefined,
        cusName: undefined,
        cusPhone: undefined,
        goodsPrice: undefined,
        payMoney: undefined,
        orderTime: undefined,
        reduceMoney: undefined,
        balance: undefined,
        payTime: undefined,
        payType: undefined,
        payRemark: undefined,
        isOnline: undefined,
        receivablesAccount: undefined,
        orderStatus: undefined,
        commentDesc: undefined,
        commentStar: undefined,
        commentTime: undefined,
        accessCode: undefined,
        validationTime: undefined,
        validationRealName: undefined,
        validationUserId: undefined,
        isCoupon: undefined,
        couponId: undefined,
        couponCode: undefined,
        couponDiscount: undefined,
        deptId: undefined,
        id: undefined,
        goodsId: undefined,
      },
      // 表单校验
      formRules: {},
    };
  },
  methods: {
    /** 打开弹窗 */
    async open(id) {
      this.dialogVisible = true;
      this.reset();
      // 修改时，设置数据
      if (id) {
        this.formLoading = true;
        try {
          const res = await OrderInfoApi.getOrderInfo(id);
          this.formData = res.data;
          this.title = "修改维修模块 订单";
        } finally {
          this.formLoading = false;
        }
      }
      this.title = "新增维修模块 订单";
    },
    /** 提交按钮 */
    async submitForm() {
      // 校验主表
      await this.$refs["formRef"].validate();
      this.formLoading = true;
      try {
        const data = this.formData;
        // 修改的提交
        if (data.id) {
          await OrderInfoApi.updateOrderInfo(data);
          this.$modal.msgSuccess("修改成功");
          this.dialogVisible = false;
          this.$emit('success');
          return;
        }
        // 添加的提交
        await OrderInfoApi.createOrderInfo(data);
        this.$modal.msgSuccess("新增成功");
        this.dialogVisible = false;
        this.$emit('success');
      } finally {
        this.formLoading = false;
      }
    },
    /** 表单重置 */
    reset() {
      this.formData = {
        orderNo: undefined,
        goodsTitle: undefined,
        goodsType: undefined,
        userId: undefined,
        cusId: undefined,
        cusName: undefined,
        cusPhone: undefined,
        goodsPrice: undefined,
        payMoney: undefined,
        orderTime: undefined,
        reduceMoney: undefined,
        balance: undefined,
        payTime: undefined,
        payType: undefined,
        payRemark: undefined,
        isOnline: undefined,
        receivablesAccount: undefined,
        orderStatus: undefined,
        commentDesc: undefined,
        commentStar: undefined,
        commentTime: undefined,
        accessCode: undefined,
        validationTime: undefined,
        validationRealName: undefined,
        validationUserId: undefined,
        isCoupon: undefined,
        couponId: undefined,
        couponCode: undefined,
        couponDiscount: undefined,
        deptId: undefined,
        id: undefined,
        goodsId: undefined,
      };
      this.resetForm("formRef");
    }
  }
};
</script>
