"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_conver = require("../../../common/js/conver.js");
const common_js_net_mainUrl = require("../../../common/js/net/mainUrl.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() {
    const globalData = common_vendor.inject("globalData");
    return {
      globalData
    };
  },
  data() {
    return {
      keywords: "",
      pageData: {
        page: 1,
        rows: 10,
        projName: "",
        type: "",
        correctionType: "",
        applyStatus: ""
      },
      msgShow: false,
      msgHint: "",
      msgType: "error",
      loadingState: "loading",
      listRefreshTrig: false,
      isLoadMore: false,
      hasMore: true,
      repairList: [],
      //开票记录
      typeList: common_js_data.typeList,
      selectType: "",
      tempSelType: "",
      kindList: common_js_data.kindList,
      selectKind: "",
      tempSelKind: "",
      stateList: common_js_data.stateList,
      selectState: "",
      tempSelState: "",
      buttons: [{
        text: "关闭"
      }],
      showHint: false,
      approveImgs: [],
      approveTime: "",
      approveDesc: "",
      preUrl: common_js_net_mainUrl.previewUrl,
      approveStatus: false,
      //是否显示编辑提示
      showDownloadDialog: false,
      downloadProgress: 0,
      //下载文件进度
      downloading: false,
      //下载文件中
      tempDownloadPro: null,
      //下载的item
      approveReason: "",
      //补正原因
      isShowOptions: false,
      curOptions: "state",
      needRefresh: false,
      //是否需要刷新
      reasonItem: null
      //详情
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "补正项目"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#F0F0F0",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    this.doRefreshList();
  },
  methods: {
    repairStatusColor: common_js_conver.repairStatusColor,
    repairStatus: common_js_conver.repairStatus,
    repairType: common_js_conver.repairType,
    repairKind: common_js_conver.repairKind,
    inputKeywords(e) {
      this.keywords = e.detail.value;
    },
    //清除搜索内容
    clearSearch() {
      this.keywords = "";
      this.doRefreshList();
    },
    //发起搜索
    doSearchKeyWord() {
      this.doRefreshList();
    },
    //展示隐藏筛选
    chooseOptions() {
      this.tempSelKind = this.selectKind;
      this.tempSelState = this.selectState;
      this.tempSelType = this.selectType;
      this.isShowOptions = !this.isShowOptions;
    },
    //左边条件
    chooseLeft(e) {
      this.curOptions = e.currentTarget.dataset.value;
    },
    //右边条件
    chooseType(e) {
      this.tempSelType = e.currentTarget.dataset.value;
    },
    chooseKind(e) {
      this.tempSelKind = e.currentTarget.dataset.value;
    },
    chooseState(e) {
      this.tempSelState = e.currentTarget.dataset.value;
    },
    confirmChooseOption() {
      this.selectState = this.tempSelState;
      this.selectKind = this.tempSelKind;
      this.selectType = this.tempSelType;
      this.tempSelKind = "";
      this.tempSelState = "";
      this.tempSelType = "";
      this.isShowOptions = false;
      this.doRefreshList();
    },
    cancelChooseOption() {
      this.isShowOptions = false;
      this.tempSelKind = "";
      this.tempSelState = "";
      this.tempSelType = "";
    },
    clearChooseOption() {
      this.selectKind = "";
      this.selectState = "";
      this.selectType = "";
      this.tempSelKind = "";
      this.tempSelState = "";
      this.tempSelType = "";
      this.isShowOptions = false;
      this.doRefreshList();
    },
    closeDialog() {
      this.$refs.reasonDialog.close();
      this.$refs.downloadDialog.close();
    },
    //显示详情
    showReason(e) {
      const item = e.currentTarget.dataset.value;
      item.correctionVoucherFileKVs.map((value) => {
        value.url = common_js_net_mainUrl.previewUrl + value.key;
        return value;
      });
      this.reasonItem = item;
      common_vendor.index.__f__("log", "at pages/copyright/repair/repair.vue:394", item);
      this.$refs.reasonDialog.open();
    },
    //预览补正凭证
    previewImg(e) {
      const _self = this;
      _self.$refs.reasonDialog.close();
      const item = e.currentTarget.dataset.item;
      common_vendor.index.__f__("log", "at pages/copyright/repair/repair.vue:402", 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
        });
      }
    },
    //下载文件
    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/repair/repair.vue:445", "下载返回", 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();
    },
    //刷新
    doRefreshList() {
      common_vendor.index.__f__("log", "at pages/copyright/repair/repair.vue:474", "正在刷新...");
      const _self = this;
      _self.loadingState = "loading";
      _self.hasMore = "more";
      _self.pageData.page = 1;
      _self.pageData.projName = _self.keywords;
      _self.pageData.type = _self.selectType;
      _self.pageData.correctionType = _self.selectKind;
      _self.pageData.applyStatus = _self.selectState;
      _self.isLoadMore = false;
      _self.doGetRepairList(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.type = _self.selectType;
      _self.pageData.correctionType = _self.selectKind;
      _self.pageData.applyStatus = _self.selectState;
      _self.doGetRepairList(false);
    },
    //加载列表
    doGetRepairList(isRefresh) {
      const _self = this;
      _self.repairList = isRefresh ? [] : _self.repairList;
      _self.loadingState = isRefresh ? "loading" : "";
      common_js_net_projectApi.ProApi.doGetMineRepairList(_self.pageData).then((res) => {
        common_vendor.index.__f__("log", "at pages/copyright/repair/repair.vue:508", res);
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.loadingState = isRefresh ? status : "";
        _self.repairList = _self.repairList.concat(res.rows);
        _self.isLoadMore = false;
        _self.hasMore = _self.repairList.length < res.total ? "more" : "noMore";
      }).catch((err) => {
        _self.loadingState = "error";
        _self.isLoadMore = false;
        _self.hasMore = "more";
      });
    },
    //下载
    downloadFile(e) {
      this.tempDownloadPro = e.currentTarget.dataset.value;
      this.$refs.downloadDialog.open();
    },
    //下载code或资料
    doDownloadDatum(e) {
      const _self = this;
      const path = e.currentTarget.dataset.path;
      const url = common_js_net_mainUrl.copyrightUrl + path + this.tempDownloadPro.projId;
      _self.download(url);
    },
    //去申请补正
    applyRepair() {
      common_vendor.index.navigateTo({
        url: "/pages/copyright/applyRepair/applyRepair"
      });
    },
    //取消申请
    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.doCancelProrepair(item.projCorrectionApplyId).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();
      });
    }
  },
  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 _component_DownloadProgress = common_vendor.resolveComponent("DownloadProgress");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  (_easycom_uni_load_more2 + _component_ContainerLoading + _component_DownloadProgress + _easycom_uni_popup2 + _easycom_uni_popup_message2)();
}
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_load_more + _easycom_uni_popup + _easycom_uni_popup_message)();
}
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.applyRepair && $options.applyRepair(...args)),
    h: common_vendor.n($data.curOptions == "state" ? "left-sel-line" : "left-normal-line"),
    i: common_vendor.o((...args) => $options.chooseLeft && $options.chooseLeft(...args)),
    j: common_vendor.n($data.curOptions == "kind" ? "left-sel-line" : "left-normal-line"),
    k: common_vendor.o((...args) => $options.chooseLeft && $options.chooseLeft(...args)),
    l: common_vendor.n($data.curOptions == "type" ? "left-sel-line" : "left-normal-line"),
    m: common_vendor.o((...args) => $options.chooseLeft && $options.chooseLeft(...args)),
    n: $data.curOptions == "state"
  }, $data.curOptions == "state" ? {
    o: 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
      };
    }),
    p: common_vendor.o((...args) => $options.chooseState && $options.chooseState(...args))
  } : $data.curOptions == "kind" ? {
    r: common_vendor.f($data.kindList, (item, index, i0) => {
      return {
        a: common_vendor.t(item.title),
        b: common_vendor.n($data.tempSelKind == item.value ? "right-item-sel" : "right-item-normal"),
        c: item.value,
        d: index
      };
    }),
    s: common_vendor.o((...args) => $options.chooseKind && $options.chooseKind(...args))
  } : {
    t: common_vendor.f($data.typeList, (item, index, i0) => {
      return {
        a: common_vendor.t(item.title),
        b: common_vendor.n($data.tempSelType == item.value ? "right-item-sel" : "right-item-normal"),
        c: item.value,
        d: index
      };
    }),
    v: common_vendor.o((...args) => $options.chooseType && $options.chooseType(...args))
  }, {
    q: $data.curOptions == "kind",
    w: common_vendor.o((...args) => $options.clearChooseOption && $options.clearChooseOption(...args)),
    x: common_vendor.o((...args) => $options.cancelChooseOption && $options.cancelChooseOption(...args)),
    y: common_vendor.o((...args) => $options.confirmChooseOption && $options.confirmChooseOption(...args)),
    z: common_vendor.o((...args) => $options.cancelChooseOption && $options.cancelChooseOption(...args)),
    A: common_vendor.n({
      "visible": $data.isShowOptions
    }),
    B: common_vendor.f($data.repairList, (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.correctionReason),
        k: item,
        l: common_vendor.t($options.repairType(item.type)),
        m: common_vendor.t($options.repairKind(item.correctionType)),
        n: item,
        o: item.applyStatus == "APPROVED"
      }, item.applyStatus == "APPROVED" ? {
        p: common_vendor.o((...args) => $options.downloadFile && $options.downloadFile(...args)),
        q: item
      } : {}, {
        r: index
      });
    }),
    C: common_vendor.o((...args) => $options.showReason && $options.showReason(...args)),
    D: common_vendor.o((...args) => $options.showReason && $options.showReason(...args)),
    E: common_vendor.o((...args) => $options.showReason && $options.showReason(...args)),
    F: common_vendor.o((...args) => $options.showReason && $options.showReason(...args)),
    G: common_vendor.p({
      status: $data.hasMore
    }),
    H: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    I: common_vendor.p({
      loadingVisible: $data.loadingState
    }),
    J: common_vendor.p({
      isShow: $data.downloading,
      progress: $data.downloadProgress
    }),
    K: $data.reasonItem != null
  }, $data.reasonItem != null ? {
    L: common_vendor.t($data.reasonItem.correctionReason)
  } : {}, {
    M: $data.reasonItem != null
  }, $data.reasonItem != null ? {
    N: common_vendor.f($data.reasonItem.correctionVoucherFileKVs, (item, index, i0) => {
      return {
        a: common_vendor.t(item.value),
        b: item,
        c: index
      };
    }),
    O: common_vendor.o((...args) => $options.previewImg && $options.previewImg(...args))
  } : {}, {
    P: $data.reasonItem != null && $data.reasonItem.gmtReview != ""
  }, $data.reasonItem != null && $data.reasonItem.gmtReview != "" ? {
    Q: common_vendor.t($data.reasonItem.gmtReview),
    R: common_vendor.t($data.reasonItem.reviewReason)
  } : {}, {
    S: common_vendor.o((...args) => $options.closeDialog && $options.closeDialog(...args)),
    T: common_vendor.sr("reasonDialog", "9b73658f-3"),
    U: common_vendor.p({
      type: "center",
      ["background-color"]: "#fff",
      ["border-radius"]: "15rpx 15rpx 15rpx 15rpx"
    }),
    V: common_vendor.o((...args) => $options.closeDialog && $options.closeDialog(...args)),
    W: $data.tempDownloadPro != null
  }, $data.tempDownloadPro != null ? common_vendor.e({
    X: $data.tempDownloadPro.correctionType == "MANUAL" || $data.tempDownloadPro.correctionType == "ALL"
  }, $data.tempDownloadPro.correctionType == "MANUAL" || $data.tempDownloadPro.correctionType == "ALL" ? {
    Y: common_vendor.o((...args) => $options.doDownloadDatum && $options.doDownloadDatum(...args)),
    Z: common_vendor.o((...args) => $options.doDownloadDatum && $options.doDownloadDatum(...args))
  } : {}, {
    aa: $data.tempDownloadPro.correctionType == "CODE" || $data.tempDownloadPro.correctionType == "ALL"
  }, $data.tempDownloadPro.correctionType == "CODE" || $data.tempDownloadPro.correctionType == "ALL" ? {
    ab: common_vendor.o((...args) => $options.doDownloadDatum && $options.doDownloadDatum(...args)),
    ac: common_vendor.o((...args) => $options.doDownloadDatum && $options.doDownloadDatum(...args))
  } : {}) : {}, {
    ad: common_vendor.sr("downloadDialog", "9b73658f-4"),
    ae: common_vendor.p({
      type: "bottom"
    }),
    af: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    ag: common_vendor.sr("msg", "9b73658f-5"),
    ah: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-9b73658f"]]);
tt.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-toutiao/pages/copyright/repair/repair.js.map
