"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_net_projectApi = require("../../../common/js/net/projectApi.js");
const common_js_data = require("../../../common/js/data.js");
const common_js_cache_storage = require("../../../common/js/cache/storage.js");
const common_js_net_mainUrl = require("../../../common/js/net/mainUrl.js");
const containerLoadingVue = () => "../../../components/container-loading.js";
const _sfc_main = {
  components: {
    containerLoadingVue
  },
  setup() {
    const globalData = common_vendor.inject("globalData");
    return {
      globalData
    };
  },
  data() {
    return {
      primaryColor: this.globalData.primaryColor,
      msgHint: "",
      msgType: "",
      selPro: null,
      selType: null,
      files: [],
      proList: [],
      tempSelPro: null,
      typeList: common_js_data.kindList,
      showSelPro: false,
      showSelType: false,
      tempSelType: null,
      remark: "",
      proKeywords: "",
      proPageData: {
        page: 1,
        rows: 10,
        keywords: ""
      },
      listRefreshTrig: false,
      loadingState: "loading",
      hasMore: true,
      imageStyles: {
        width: 72,
        height: 72,
        border: {
          color: "#F5F5F5",
          width: 1,
          style: "solid",
          radius: "2px"
        }
      }
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "申请退款"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      // 必写项，字体颜色仅支持#ffffff和#000000
      backgroundColor: "#F0F0F0",
      // 传递的颜色值，仅支持十六进制颜色
      animation: {
        // 可选项
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    common_vendor.index.__f__("log", "at pages/copyright/applyRefund/applyRefund.vue:166", this.globalData.primaryColor);
  },
  methods: {
    inputRemark(e) {
      this.remark = e.detail.value;
    },
    inputSearchPro(e) {
      this.proKeywords = e.detail.value;
    },
    //显示补正软著选择
    showSelProDialog() {
      const _self = this;
      _self.doRefreshList();
      _self.tempSelPro = _self.selPro;
      _self.$refs.proDialog.open();
    },
    closeDialog() {
      this.$refs.proDialog.close();
    },
    confirmSelPro() {
      if (this.tempSelPro == null) {
        this.msgHint = "请选择退款项目";
        this.msgType = "error";
        this.$refs.msg.open();
      } else {
        this.$refs.proDialog.close();
        this.selPro = this.tempSelPro;
        this.tempSelPro = null;
      }
    },
    doSearchKeyWord() {
      this.doRefreshList();
    },
    //刷新
    doRefreshList() {
      const _self = this;
      _self.loadingState = "loading";
      _self.hasMore = "more";
      _self.isLoadMore = false;
      _self.proPageData.page = 1;
      _self.proPageData.keywords = _self.proKeywords;
      _self.getCanRefundList(true);
    },
    //加载更多
    doLoadMore() {
      const _self = this;
      if (_self.isLoadMore || _self.hasMore == "noMore") {
        return;
      }
      _self.isLoadMore = true;
      _self.hasMore = "loading";
      _self.proPageData.page = ++_self.proPageData.page;
      _self.proPageData.keywords = _self.proKeywords;
      _self.getCanRefundList(false);
    },
    getCanRefundList(isRefresh) {
      const _self = this;
      _self.proList = isRefresh ? [] : _self.proList;
      _self.loadingState = isRefresh ? "loading" : "";
      common_js_net_projectApi.ProApi.doGetCanRefundProList(_self.proPageData).then((res) => {
        common_vendor.index.__f__("log", "at pages/copyright/applyRefund/applyRefund.vue:228", res);
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.loadingState = isRefresh ? status : "";
        _self.proList = _self.proList.concat(res.rows);
        _self.isLoadMore = false;
        _self.hasMore = _self.proList.length < res.total ? "more" : "noMore";
      }).catch((err) => {
        _self.loadingState = "error";
        _self.isLoadMore = false;
        _self.hasMore = "more";
      });
    },
    choosePro(e) {
      this.tempSelPro = e.currentTarget.dataset.value;
    },
    //删除图片
    delImgs(e) {
      common_vendor.index.__f__("log", "at pages/copyright/applyRefund/applyRefund.vue:247", "删除凭证", e);
      this.files.splice(e.index, 1);
    },
    //上传图片
    async uploadImgToNet(e) {
      common_vendor.index.showLoading({
        title: "上传中..."
      });
      const tempFilePaths = e.tempFilePaths;
      const token = common_js_cache_storage.get("token");
      const header = token ? {
        Auth: `Bearer ${token}`
      } : {};
      const that = this;
      try {
        const results = [];
        for (let i = 0; i < tempFilePaths.length; i++) {
          const filePath = tempFilePaths[i];
          const result = await new Promise((resolve, reject) => {
            common_vendor.index.uploadFile({
              url: common_js_net_mainUrl.uploadImgUrl,
              header,
              filePath,
              name: "image",
              success(res) {
                if (res.statusCode === 200) {
                  let data = res.data;
                  if (typeof data === "string") {
                    data = JSON.parse(data);
                  }
                  resolve(data.data);
                } else {
                  reject(new Error("上传失败，状态码非200"));
                }
              },
              fail(err) {
                reject(err);
              }
            });
          });
          result.url = common_js_net_mainUrl.previewUrl + result.fileId;
          result.name = result.fileName;
          let lastDot = result.fileName.lastIndexOf(".");
          result.extname = result.fileName.substring(lastDot + 1);
          results.push(result);
        }
        that.files = that.files.concat(results);
        common_vendor.index.hideLoading();
      } catch (error) {
        common_vendor.index.hideLoading();
        that.msgHint = "凭证上传失败,请稍后重试";
        that.msgType = "error";
        that.$refs.msg.open();
        that.$refs.imgPicker.clearFiles();
        common_vendor.index.__f__("error", "at pages/copyright/applyRefund/applyRefund.vue:308", "上传错误:", error);
      }
    },
    //提交
    doApply() {
      const legal = this.checkParams();
      if (legal) {
        const _self = this;
        common_vendor.index.showLoading({
          title: "提交中..."
        });
        const ids = _self.files.map((item) => item.fileId).join(",");
        const data = {
          projId: _self.selPro.projId,
          refundReason: _self.remark,
          refundVoucher: ids
        };
        common_js_net_projectApi.ProApi.doApplyRefundPro(data).then((res) => {
          common_vendor.index.hideLoading();
          _self.msgHint = "提交操作已顺利完成,我们会尽快审核,还请耐心等待";
          _self.msgType = "success";
          _self.$refs.msg.open();
          setTimeout(() => {
            common_vendor.index.navigateBack({
              success: function() {
                let pages = getCurrentPages();
                let prevPage = pages[pages.length - 2];
                if (prevPage && typeof prevPage.doRefreshList === "function") {
                  prevPage.doRefreshList();
                }
              }
            });
          }, 1500);
        }).catch((err) => {
          wx.hideLoading();
          _self.msgHint = err.msg ? err.msg : "提交失败,请稍后重试";
          _self.msgType = "error";
          _self.$refs.msg.open();
        });
      }
    },
    //校验参数
    checkParams() {
      const _self = this;
      if (_self.selPro == null) {
        _self.msgHint = "请选择退款软著";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return false;
      }
      if (_self.remark == "") {
        _self.msgHint = "请输入退款原因";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return false;
      }
      if (_self.files.length <= 0) {
        _self.msgHint = "请上传退款凭证";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return false;
      }
      return true;
    }
  }
};
if (!Array) {
  const _easycom_uni_file_picker2 = common_vendor.resolveComponent("uni-file-picker");
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _component_containerLoadingVue = common_vendor.resolveComponent("containerLoadingVue");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  (_easycom_uni_file_picker2 + _easycom_uni_load_more2 + _component_containerLoadingVue + _easycom_uni_popup2 + _easycom_uni_popup_message2)();
}
const _easycom_uni_file_picker = () => "../../../uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.js";
const _easycom_uni_load_more = () => "../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
const _easycom_uni_popup_message = () => "../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
if (!Math) {
  (_easycom_uni_file_picker + _easycom_uni_load_more + _easycom_uni_popup + _easycom_uni_popup_message)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: $setup.globalData.locImg + "/banner_1.png",
    b: $setup.globalData.locImg + "/banner_2.png",
    c: common_vendor.t($data.selPro == null ? "选择需要退款的软著" : $data.selPro.projName),
    d: common_vendor.n($data.selPro == null ? "text-hint" : "text-sel"),
    e: common_vendor.o((...args) => $options.showSelProDialog && $options.showSelProDialog(...args)),
    f: common_vendor.o((...args) => $options.inputRemark && $options.inputRemark(...args)),
    g: $data.remark,
    h: common_vendor.sr("imgPicker", "8fd51228-0"),
    i: common_vendor.o($options.delImgs),
    j: common_vendor.o($options.uploadImgToNet),
    k: common_vendor.p({
      value: $data.files,
      ["del-icon"]: true,
      limit: "4",
      fileMediatype: "image",
      ["auto-upload"]: false,
      ["image-styles"]: $data.imageStyles
    }),
    l: common_vendor.o((...args) => $options.doApply && $options.doApply(...args)),
    m: $data.proKeywords,
    n: common_vendor.o((...args) => $options.inputSearchPro && $options.inputSearchPro(...args)),
    o: common_vendor.o((...args) => $options.doSearchKeyWord && $options.doSearchKeyWord(...args)),
    p: common_vendor.o((...args) => $options.closeDialog && $options.closeDialog(...args)),
    q: common_vendor.f($data.proList, (item, index, i0) => {
      return {
        a: $data.tempSelPro != null && $data.tempSelPro.projId == item.projId,
        b: common_vendor.t(item.projName),
        c: common_vendor.t(item.authorName),
        d: common_vendor.t(item.gmtCreate),
        e: item,
        f: index,
        g: item
      };
    }),
    r: common_vendor.o((...args) => $options.choosePro && $options.choosePro(...args)),
    s: common_vendor.p({
      status: $data.hasMore
    }),
    t: common_vendor.o((...args) => $options.doRefreshList && $options.doRefreshList(...args)),
    v: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    w: common_vendor.p({
      loadingVisible: $data.loadingState
    }),
    x: common_vendor.o((...args) => $options.confirmSelPro && $options.confirmSelPro(...args)),
    y: common_vendor.sr("proDialog", "8fd51228-1"),
    z: common_vendor.p({
      type: "bottom",
      ["background-color"]: "#fff",
      ["border-radius"]: "15rpx 15rpx 0rpx 0rpx"
    }),
    A: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    B: common_vendor.sr("msg", "8fd51228-4"),
    C: common_vendor.p({
      type: "message"
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-8fd51228"]]);
tt.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-toutiao/pages/copyright/applyRefund/applyRefund.js.map
