<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="name">
          <!-- <el-input v-model="formData.name" placeholder="请输入商品分类名称" /> -->
           {{ formData.name}}
        </el-form-item>
        <el-form-item label="手机号" prop="phone	">
          <!-- <el-input v-model="formData.name" placeholder="请输入商品分类名称" /> -->
           {{ formData.phone	}}
        </el-form-item>
        <el-form-item label="地址" prop="address	">
          <!-- <el-input v-model="formData.name" placeholder="请输入商品分类名称" /> -->
           {{ formData.address	}}
        </el-form-item>
        <el-form-item label="下单时间" prop="useTime		">
          <!-- <el-input v-model="formData.name" placeholder="请输入商品分类名称" /> -->
           {{ formData.useTime}}
        </el-form-item>
        <el-form-item label="总金额" prop="priceVisable	  ">
          <!-- <el-input v-model="formData.name" placeholder="请输入商品分类名称" /> -->
           {{ formData.priceVisable}}
        </el-form-item>
        <el-form-item label="下单明细" prop="goodsList">
          <!-- {{ formData.goodsList	 }} -->
            <el-table :data="formData.goodsList" border style="width: 100%">
              <el-table-column prop="goodsName" label="商品名称" ></el-table-column>
              <el-table-column prop="priceVisable" label="商品价格" >
              </el-table-column>
              <el-table-column prop="num" label="商品数量" ></el-table-column>
            </el-table>
        </el-form-item>
      </el-form>
              <div slot="footer" class="dialog-footer">
        <el-button v-show="inspectFalg" type="warning" size="medium" style="font-size: 30px;" @click="refundForm" :disabled="formLoading">退款</el-button>
        <el-button v-show="inspectFalg" type="success" size="medium" style="font-size: 30px;" @click="submitForm" :disabled="formLoading">完成取餐</el-button>
        <el-button @click="dialogVisible = false" >取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as OrderApi from '@/api/restaurant/order';

      export default {
    name: "TypeForm",
    components: {
                    },
    data() {
      return {
        // 弹出层标题
        dialogTitle: "",
        // 是否显示弹出层
        dialogVisible: false,
        // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
        formLoading: false,
        // 表单参数
        formData: {
                            goodsTypeName: undefined,
        },
        // 表单校验
        formRules: {
        },
        inspectFalg:false
                        };
    },
    methods: {
      async inspect(id) {
        this.dialogVisible = true;
        this.inspectFalg= false
        this.reset();
        // 修改时，设置数据
        if (id) {
          this.formLoading = true;
          try {
            const res = await OrderApi.getOrder(id);
            this.formData = res.data;
            this.title = "修改商品分类";
          } finally {
            this.formLoading = false;
          }
        }
        this.title = "新增商品分类";
              },
      /** 打开弹窗 */
     async open(id) {
        this.dialogVisible = true;
        this.inspectFalg= true

        this.reset();
        // 修改时，设置数据
        if (id) {
          this.formLoading = true;
          try {
            const res = await OrderApi.getOrder(id);
            this.formData = res.data;
            this.title = "修改商品分类";
          } finally {
            this.formLoading = false;
          }
        }
        this.title = "新增商品分类";
              },
      async refundForm(){
        this.$modal.confirm('是否确认退款？').then(async() => {
          await OrderApi.updateOrder({id:this.formData.id,state:6});
          this.$modal.msgSuccess("退款成功");
          this.dialogVisible = false;
          this.$emit('success');
        })
      },
      /** 提交按钮 */
      async submitForm() {
        this.$modal.confirm('是否确认完成？').then(async() => {
          await OrderApi.updateOrder({id:this.formData.id,state:5});
          this.$modal.msgSuccess("完成成功");
          this.dialogVisible = false;
          this.$emit('success');
        })
      },
                      /** 表单重置 */
      reset() {
        this.formData = {
                            goodsTypeName: undefined,
        };
        this.resetForm("formRef");
      }
    }
  };
</script>
