"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_net_projectApi = require("../../../common/js/net/projectApi.js");
const common_js_net_mainUrl = require("../../../common/js/net/mainUrl.js");
const common_js_data = require("../../../common/js/data.js");
const common_js_conver = require("../../../common/js/conver.js");
const common_js_cache_storage = require("../../../common/js/cache/storage.js");
const ContainerLoading = () => "../../../components/container-loading.js";
const DownloadProgress = () => "../../../components/download-progress.js";
const _sfc_main = {
  components: {
    ContainerLoading,
    DownloadProgress
  },
  setup() {
  },
  data() {
    return {
      pageData: {
        page: 1,
        rows: 10,
        applyStatus: "",
        //状态
        projName: ""
        //项目名称
      },
      keywords: "",
      stateList: common_js_data.stateList,
      selectState: "",
      tempSelState: "",
      msgHint: "",
      msgType: "error",
      msgShow: false,
      loadingState: "loading",
      listRefreshTrig: false,
      isLoadMore: false,
      hasMore: true,
      refundList: [],
      showHint: false,
      tempItem: null,
      isShowOptions: false,
      needRefresh: false,
      //是否需要刷新
      reasonItem: null,
      downloading: false,
      downloadProgress: 0
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "退款项目"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      // 必写项，字体颜色仅支持#ffffff和#000000
      backgroundColor: "#F0F0F0",
      // 传递的颜色值，仅支持十六进制颜色
      animation: {
        // 可选项
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    this.doRefreshList();
  },
  methods: {
    repairStatusColor: common_js_conver.repairStatusColor,
    repairStatus: common_js_conver.repairStatus,
    moneyTxt: common_js_conver.moneyTxt,
    chooseOptions() {
      this.isShowOptions = !this.isShowOptions;
      this.tempSelState = this.selectState;
    },
    //取消条件
    cancelChooseOption() {
      this.isShowOptions = false;
      this.tempSelState = "";
    },
    //清除条件
    clearChooseOption() {
      this.isShowOptions = false;
      this.selectState = "";
      this.tempSelState = "";
      this.doRefreshList();
    },
    //确定条件
    confirmChooseOption() {
      this.selectState = this.tempSelState;
      this.isShowOptions = false;
      this.tempSelState = "";
      this.doRefreshList();
    },
    //去退款
    applyRefund() {
      common_vendor.index.navigateTo({
        url: "/pages/copyright/applyRefund/applyRefund"
      });
    },
    inputKeywords(e) {
      this.keywords = e.detail.value;
    },
    clearSearch() {
      this.keywords = "";
      this.doRefreshList();
    },
    doSearchKeyWord() {
      this.doRefreshList();
    },
    chooseState(e) {
      this.tempSelState = e.currentTarget.dataset.value;
    },
    doGetMineList(isRefresh) {
      const _self = this;
      _self.refundList = isRefresh ? [] : _self.refundList;
      _self.loadingState = isRefresh ? "loading" : "";
      common_js_net_projectApi.ProApi.doGetMineRefundProList(_self.pageData).then((res) => {
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.loadingState = isRefresh ? status : "";
        _self.refundList = _self.refundList.concat(res.rows);
        _self.listRefreshTrig = false;
        _self.isLoadMore = false;
        _self.hasMore = _self.refundList.length < res.total ? "more" : "noMore";
      }).catch((err) => {
        _self.loadingState = "error";
        _self.listRefreshTrig = false;
        _self.isLoadMore = false;
        _self.hasMore = "more";
      });
    },
    //下拉刷新
    doRefreshList() {
      const _self = this;
      _self.loadingState = "loading";
      _self.hasMore = "more";
      _self.isLoadMore = false;
      _self.pageData.page = 1;
      _self.pageData.projName = _self.keywords;
      _self.pageData.applyStatus = _self.selectState;
      _self.doGetMineList(true);
    },
    //加载更多
    doLoadMore() {
      const _self = this;
      if (_self.isLoadMore || _self.hasMore == "noMore") {
        return;
      }
      _self.isLoadMore = true;
      _self.hasMore = "loading";
      _self.pageData.page = ++_self.pageData.page;
      _self.pageData.projName = _self.keywords;
      _self.pageData.applyStatus = _self.selectState;
      _self.doGetMineList(false);
    },
    //显示详情
    showReason(e) {
      const _self = this;
      const item = e.currentTarget.dataset.value;
      item.refundVoucherFileKVs.map((value) => {
        value.url = common_js_net_mainUrl.previewUrl + value.key;
        return value;
      });
      _self.reasonItem = item;
      _self.$refs.reasonDialog.open();
    },
    closeDialog() {
      this.$refs.reasonDialog.close();
    },
    previewImg(e) {
      const _self = this;
      _self.$refs.reasonDialog.close();
      const item = e.currentTarget.dataset.item;
      common_vendor.index.__f__("log", "at pages/copyright/refund/refund.vue:296", item);
      const fileName = item.value;
      const path = item.url;
      if (fileName.toLowerCase().endsWith(".pdf")) {
        _self.download(path);
      } else {
        const urls = [path];
        common_vendor.index.previewImage({
          urls
        });
      }
    },
    //取消申请
    cancelApply(e) {
      const item = e.currentTarget.dataset.value;
      const _self = this;
      common_vendor.index.showModal({
        title: "警告",
        content: "您确定要撤销这次退款吗?",
        success: (res) => {
          if (res.confirm) {
            _self.doCancelApply(item);
          }
        }
      });
    },
    //撤销
    doCancelApply(item) {
      const _self = this;
      common_vendor.index.showLoading({
        title: "撤销中..."
      });
      common_js_net_projectApi.ProApi.doCancelRefundPro(item.projRefundApplyId).then((res) => {
        common_vendor.index.hideLoading();
        _self.msgType = "success";
        _self.msgHint = "撤销成功";
        _self.$refs.msg.open();
        _self.doRefreshList();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgType = "error";
        _self.msgHint = err.msg ? err.msg : "撤销失败,请稍后重试";
        _self.$refs.msg.open();
      });
    },
    //下载文件
    doDownload(url, header) {
      const _self = this;
      return new Promise((resolve, reject) => {
        const downloadTask = common_vendor.index.downloadFile({
          url,
          header,
          success: resolve,
          fail: reject
        });
        downloadTask.onProgressUpdate((res) => {
          _self.downloadProgress = res.progress;
        });
      });
    },
    //点击下载
    //path :文件地址
    async download(path) {
      const _self = this;
      _self.downloadProgress = 0;
      _self.downloading = true;
      const url = path;
      const token = common_js_cache_storage.get("token");
      const header = {};
      if (token) {
        header.Auth = `Bearer ${token}`;
      }
      const downloadRes = await _self.doDownload(url, header);
      common_vendor.index.__f__("log", "at pages/copyright/refund/refund.vue:374", "下载返回", downloadRes);
      if (downloadRes && downloadRes.statusCode == 200) {
        _self.downloadProgress = 0;
        _self.downloading = false;
        common_vendor.index.openDocument({
          filePath: downloadRes.tempFilePath,
          showMenu: true,
          success: (res) => {
          },
          fail: (err) => {
            _self.showErr("很抱歉，文件下载出现问题。建议您稍作等待，之后再尝试下载。");
          }
        });
      } else {
        _self.showErr("很抱歉，文件下载出现问题。建议您稍作等待，之后再尝试下载。");
      }
    },
    showErr(msg) {
      const _self = this;
      _self.msgHint = msg;
      _self.msgType = "error";
      _self.showDownload = false;
      _self.downloading = false;
      _self.downloadProgress = 0;
      _self.$refs.msg.open();
    }
  },
  onPullDownRefresh() {
    this.doRefreshList();
    common_vendor.index.stopPullDownRefresh();
  }
};
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _component_ContainerLoading = common_vendor.resolveComponent("ContainerLoading");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  const _component_DownloadProgress = common_vendor.resolveComponent("DownloadProgress");
  (_easycom_uni_load_more2 + _component_ContainerLoading + _easycom_uni_popup_message2 + _easycom_uni_popup2 + _component_DownloadProgress)();
}
const _easycom_uni_load_more = () => "../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_uni_popup_message = () => "../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_load_more + _easycom_uni_popup_message + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $data.keywords,
    b: common_vendor.o((...args) => $options.inputKeywords && $options.inputKeywords(...args)),
    c: common_vendor.o((...args) => $options.doSearchKeyWord && $options.doSearchKeyWord(...args)),
    d: $data.keywords != ""
  }, $data.keywords != "" ? {
    e: common_vendor.o((...args) => $options.clearSearch && $options.clearSearch(...args))
  } : {}, {
    f: common_vendor.o((...args) => $options.chooseOptions && $options.chooseOptions(...args)),
    g: common_vendor.o((...args) => $options.applyRefund && $options.applyRefund(...args)),
    h: common_vendor.f($data.stateList, (item, index, i0) => {
      return {
        a: common_vendor.t(item.title),
        b: common_vendor.n($data.tempSelState == item.value ? "right-item-sel" : "right-item-normal"),
        c: item.value,
        d: index
      };
    }),
    i: common_vendor.o((...args) => $options.chooseState && $options.chooseState(...args)),
    j: common_vendor.o((...args) => $options.clearChooseOption && $options.clearChooseOption(...args)),
    k: common_vendor.o((...args) => $options.cancelChooseOption && $options.cancelChooseOption(...args)),
    l: common_vendor.o((...args) => $options.confirmChooseOption && $options.confirmChooseOption(...args)),
    m: common_vendor.o((...args) => $options.cancelChooseOption && $options.cancelChooseOption(...args)),
    n: common_vendor.n({
      "visible": $data.isShowOptions
    }),
    o: common_vendor.f($data.refundList, (item, index, i0) => {
      return common_vendor.e({
        a: common_vendor.t($options.repairStatus(item.applyStatus)),
        b: common_vendor.n($options.repairStatusColor(item.applyStatus)),
        c: common_vendor.t(item.gmtCreate),
        d: item,
        e: common_vendor.t(item.projName),
        f: item,
        g: item.applyStatus == "PENDING"
      }, item.applyStatus == "PENDING" ? {
        h: common_vendor.o((...args) => $options.cancelApply && $options.cancelApply(...args)),
        i: item
      } : {}, {
        j: common_vendor.t(item.refundReason),
        k: item,
        l: common_vendor.t(item.userInfoName),
        m: $options.moneyTxt(10, 14, item.projPayment / 100),
        n: item,
        o: index
      });
    }),
    p: common_vendor.o((...args) => $options.showReason && $options.showReason(...args)),
    q: common_vendor.o((...args) => $options.showReason && $options.showReason(...args)),
    r: common_vendor.o((...args) => $options.showReason && $options.showReason(...args)),
    s: common_vendor.o((...args) => $options.showReason && $options.showReason(...args)),
    t: common_vendor.p({
      status: $data.hasMore
    }),
    v: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    w: common_vendor.p({
      loadingVisible: $data.loadingState
    }),
    x: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    y: common_vendor.sr("msg", "5c3f2f90-2"),
    z: common_vendor.p({
      type: "message"
    }),
    A: common_vendor.p({
      isShow: $data.downloading,
      progress: $data.downloadProgress
    }),
    B: $data.reasonItem != null
  }, $data.reasonItem != null ? {
    C: common_vendor.t($data.reasonItem.refundReason)
  } : {}, {
    D: $data.reasonItem != null
  }, $data.reasonItem != null ? {
    E: common_vendor.f($data.reasonItem.refundVoucherFileKVs, (item, index, i0) => {
      return {
        a: common_vendor.t(item.value),
        b: item,
        c: index
      };
    }),
    F: common_vendor.o((...args) => $options.previewImg && $options.previewImg(...args))
  } : {}, {
    G: $data.reasonItem != null && $data.reasonItem.gmtReview != ""
  }, $data.reasonItem != null && $data.reasonItem.gmtReview != "" ? {
    H: common_vendor.t($data.reasonItem.gmtReview),
    I: common_vendor.t($data.reasonItem.reviewReason)
  } : {}, {
    J: common_vendor.o((...args) => $options.closeDialog && $options.closeDialog(...args)),
    K: common_vendor.sr("reasonDialog", "5c3f2f90-5"),
    L: common_vendor.p({
      type: "center",
      ["background-color"]: "#fff",
      ["border-radius"]: "15rpx 15rpx 15rpx 15rpx"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-5c3f2f90"]]);
tt.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-toutiao/pages/copyright/refund/refund.js.map
