<!--
 * @Description: 新增/编辑弹框
 * @Author: Sugar.
 * @Date: 2023-11-24 13:55:00
 * @LastEditors: Sugar.
 * @LastEditTime: 2023-11-24 13:55:00
 * @FilePath: \cattle_webui\src\views\otaMr\dialog\dataEdit.vue
 * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
-->
<template>
  <el-dialog
    :title="title"
    :visible.sync="open"
    width="600px"
    append-to-body
    :close-on-click-modal="false"
    @close="cancel"
  >
    <div class="dialog">
      <el-form :model="form" ref="form" :rules="rules" label-width="80px">
        <el-form-item label="票务名称:">
          <el-input
            disabled
            type="number"
            v-model="form.priceAmount"
            placeholder="票务名称"
            clearable
            style="width: 260px;"
          />
        </el-form-item>
        <el-form-item label="座位类型:">
          <el-input
            disabled
            type="number"
            v-model="form.priceAmount"
            placeholder="座位类型"
            clearable
            style="width: 260px;"
          />
        </el-form-item>
        <el-form-item label="市场价:">
          <el-input
            disabled
            type="number"
            v-model="form.priceAmount"
            placeholder=""
            clearable
            style="width: 260px;"
          >
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="销售价:">
          <el-input
            disabled
            type="number"
            v-model="form.priceAmount"
            placeholder=""
            clearable
            style="width: 260px;"
          >
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="结算价:" prop="priceAmount">
          <el-input
            :disabled="isDisabled"
            type="number"
            v-model="form.priceAmount"
            placeholder=""
            clearable
            @change="changePriceAmount"
            style="width: 260px;"
          >
            <template slot="append">元</template>
          </el-input>
        </el-form-item>

      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button  @click="cancel">取消</el-button>
      <el-button
        type="primary"
        @click="submitForm"
        v-loading.fullscreen.lock="loading"
        element-loading-text="提交中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
      >
        <span v-if="loading">提交中...</span>
        <span v-else>保存</span>
      </el-button>
    </span>
  </el-dialog>
</template>

<script>
import { saveAndEdit } from "@/api/ticketMr/priceMr";
import Editor from "@/components/Editor";
import { getToken } from "@/utils/auth";
export default {
  name: "dataEdit",
  props: {
    dict: {
      type: Object,
      default: () => [],
    },
  },
  components: {
    Editor,
  },
  data() {
    return {
      title: "编辑",
      model: "EDIT",
      open: false,
      loading: false,
      tableType: false,
      isDisabled: false,
      form: {
        id: undefined,
        priceType: '2'
      },
      rules: {
        venueId: [{ required: true, message: "请选择场馆", trigger: ["change","blur"] }],
        auditoriumId: [{ required: true, message: "请选择演出厅", trigger: ["change","blur"] }],
        performId: [{ required: true, message: "请选择剧目", trigger: ["change","blur"] }],
        goodsId: [{ required: true, message: "请选择票务", trigger: ["change","blur"] }],
        seatTypeId: [{ required: true, message: "请选择座位类型", trigger: ["change","blur"] }],
        priceType: [{ required: true, message: "请选择结算方式", trigger: ["change","blur"] }],
        priceAmount: [{ required: true, message: "请输入价格", trigger: ["change","blur"] }],
      },
      uploadObj: {
        url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
        Headers: { Authorization: "Bearer " + getToken() },
      },
      theatreList: [],
      goodsList: [],
      merchantList: [],
      editType: false,
      ticketList: [],
      seatList: []
    };
  },
  methods: {
    /**
     * 打开弹框
     * @date 2023-11-22
     * @param {any} obj
     * @returns {any}
     */
    openDialog(title, obj, type) {
      this.open = true;
      if (obj){
        this.title = "编辑商品信息";
        this.$nextTick(() => {
          this.$set(this.form, 'id', obj.id);
          this.$set(this.form, 'goodsId', obj.goodsId);
          this.$set(this.form, 'seatTypeId', obj.seatTypeId);
          this.$set(this.form, 'performId', obj.performId);
          this.$set(this.form, 'auditoriumId', obj.auditoriumId);
          this.$set(this.form, 'priceType', obj.priceType ? obj.priceType.toString():obj.priceType);
          this.$set(this.form, 'priceAmount', obj.priceAmount);
        });
      }else{
        this.title = "新增商品信息";
        this.$nextTick(() => {
          this.$refs["form"].clearValidate();
        });
      }
    },
    /** 价格输入事件 */
    changePriceAmount(val) {
      if(val * 1 < 0){
        this.$message.error("输入需大于或等于0!");
        this.$set(this.form, 'priceAmount', '');
        return false
      }
    },
    /**
     * 保存
     * @date 2023-11-22
     * @returns {any}
     */
    submitForm() {
      this.$refs["form"].validate(async (valid) => {
        if (valid) {
          // try {
          //   this.loading = true;
          //   const { code } = await saveAndEdit({ ...this.form });
          //   if (code === 200) {
          //     this.$message.success("操作成功!");
          //     this.$emit("getList");
          //     this.cancel();
          //   }
          // } catch (error) {
          // } finally {
          //   this.loading = false;
          // }
        }
      });
    },
    /**
     * 重置
     * @date 2023-11-22
     * @returns {any}
     */
    reset() {
      this.$set(this.form, 'id', '');
      this.$set(this.form, 'goodsId', '');
      this.$set(this.form, 'venueId', '');
      this.$set(this.form, 'seatTypeId', '');
      this.$set(this.form, 'performId', '');
      this.$set(this.form, 'auditoriumId', '');
      this.$set(this.form, 'priceType', '2');
      this.$set(this.form, 'priceAmount', '');
    },
    /**
     * 关闭弹框
     * @date 2023-11-22
     * @returns {any}
     */
    cancel() {
      this.reset();
      this.open = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog {
  padding: 0 30px;
  max-height: 65vh;
  overflow-y: auto;
}
.dialog {
  padding: 0 30px;
  .upload-btn {
    width: 100px;
    height: 100px;
    background-color: #fbfdff;
    border: dashed 1px #c0ccda;
    border-radius: 5px;
    i {
      font-size: 30px;
      margin-top: 20px;
    }
    &-text {
      margin-top: -10px;
    }
  }
  .avatar {
    cursor: pointer;
  }
}
</style>
