"use strict";
const common_vendor = require("../../common/vendor.js");
const _sfc_main = {
  data() {
    return {
      types: ["设备故障", "收费问题", "使用建议", "其他"],
      selectedType: -1,
      description: "",
      images: [],
      contact: ""
    };
  },
  methods: {
    selectType(index) {
      this.selectedType = index;
    },
    chooseImage() {
      common_vendor.index.chooseImage({
        count: 3 - this.images.length,
        success: (res) => {
          this.images = [...this.images, ...res.tempFilePaths];
        }
      });
    },
    deleteImage(index) {
      this.images.splice(index, 1);
    },
    submitFeedback() {
      if (this.selectedType === -1) {
        common_vendor.index.showToast({
          title: "请选择问题类型",
          icon: "none"
        });
        return;
      }
      if (!this.description.trim()) {
        common_vendor.index.showToast({
          title: "请描述您的问题",
          icon: "none"
        });
        return;
      }
      if (!this.contact) {
        common_vendor.index.showToast({
          title: "请留下联系方式",
          icon: "none"
        });
        return;
      }
      const feedbackData = {
        type: this.types[this.selectedType],
        content: this.description,
        phone: this.contact,
        images: this.images
      };
      common_vendor.index.request({
        url: "/app/feedback/add",
        method: "POST",
        data: feedbackData,
        success: (res) => {
          if (res.statusCode === 200) {
            common_vendor.index.showToast({
              title: "提交成功",
              icon: "success"
            });
            this.selectedType = -1;
            this.description = "";
            this.contact = "";
            this.images = [];
          } else {
            common_vendor.index.showToast({
              title: "提交失败",
              icon: "none"
            });
          }
        },
        fail: () => {
          common_vendor.index.showToast({
            title: "提交失败",
            icon: "none"
          });
        }
      });
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: common_vendor.f($data.types, (type, index, i0) => {
      return {
        a: common_vendor.t(type),
        b: index,
        c: $data.selectedType === index ? 1 : "",
        d: common_vendor.o(($event) => $options.selectType(index), index)
      };
    }),
    b: $data.description,
    c: common_vendor.o(($event) => $data.description = $event.detail.value),
    d: common_vendor.t($data.description.length),
    e: common_vendor.f($data.images, (img, index, i0) => {
      return {
        a: img,
        b: common_vendor.o(($event) => $options.deleteImage(index), index),
        c: index
      };
    }),
    f: $data.images.length < 3
  }, $data.images.length < 3 ? {
    g: common_vendor.o((...args) => $options.chooseImage && $options.chooseImage(...args))
  } : {}, {
    h: $data.contact,
    i: common_vendor.o(($event) => $data.contact = $event.detail.value),
    j: common_vendor.o((...args) => $options.submitFeedback && $options.submitFeedback(...args))
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2aa7bac2"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/feedback/index.js.map
