<template>
  <!-- 弹出框表单 -->
  <el-drawer
    :title="title"
    :visible.sync="open"
    :direction="direction"
    :destroy-on-close="true"
    size="50%"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <Field
          :span="20"
          label="图片名称"
          prop="imageName"
          v-model="form.imageName"
          placeholder="请输入图片名称"
        />

        <Field
          :span="20"
          label="图片类型"
          prop="imageType"
          v-model="form.imageType"
          type="select"
          :enum-data="dict.imageType"
          placeholder="请选择图片类型"
        />
        <Field :span="20" label="图片" prop="url" placeholder="请传入图片"
          ><imageUpload
            v-model="form.url"
            prePath="/file/preview"
            :slotP="'请上传2MB以内的图片'"
          />
        </Field>
      </el-row>

      <form-buttons
        @submit="submitForm"
        v-if="pageInfo.type != 'view'"
        noCancelBtn
      />
    </el-form>
  </el-drawer>
</template>

<script>
import form from "@/assets/mixins/formdialog";
export default {
  name: "FavoritesProductDetail",
  mixins: [form],
  components: {},
  created() {
    this.changePath("favorites/product");
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "收藏产品",
      // 是否显示弹出层
      open: false,
      direction: "rtl",
      toString: ["imageType"],
      toDate: ["favoriteTime"],
      // 表单校验
      rules: {
        imageName: [{ required: true, message: "请输入图片名称" }],
        url: [{ required: true, message: "请上传图片" }],
      },
    };
  },

  methods: {
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "resourceImage/edit";
      this.getData();
      this.pageInfo.type = "edit";
      this.title = "修改名片背景";
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "resourceImage/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增名片背景";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "resourceImage/view";
      this.getData();
      this.pageInfo.type = "view";
      this.title = "名片背景详细";
    },
    /**取消按钮 */
    cancel() {
      this.open = false;
    },
    /**获取数据后弹框 */
    afterRender(data) {
      this.open = true;
    },

    afterSubmit(data) {
      this.open = false;
      this.$emit("ok");
    },

    // 表单重置
    reset() {
      this.form = {
        imageName: null,
        imageType: null,
        url: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
