"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_net_shop = require("../../../common/js/net/shop.js");
const common_js_net_mainUrl = require("../../../common/js/net/mainUrl.js");
const common_js_cache_storage = require("../../../common/js/cache/storage.js");
const common_js_conver = require("../../../common/js/conver.js");
const DownloadProgress = () => "../../../components/download-progress.js";
const ContainerLoading = () => "../../../components/container-loading.js";
var docFix = ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"];
var imgFix = ["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "ico", "tiff", "tif"];
function getFileExtension(filename) {
  if (!filename || typeof filename !== "string")
    return "";
  var lastDot = filename.lastIndexOf(".");
  return lastDot === -1 ? "" : filename.substring(lastDot + 1).toLowerCase();
}
function isImageFile(filename) {
  return imgFix.indexOf(getFileExtension(filename)) !== -1;
}
function isDocumentFile(filename) {
  return docFix.indexOf(getFileExtension(filename)) !== -1;
}
const _sfc_main = {
  components: {
    DownloadProgress,
    ContainerLoading
  },
  setup() {
  },
  data() {
    return {
      msgHint: "",
      msgType: "info",
      msgShow: false,
      showType: false,
      goodsId: "",
      goods: null,
      typeNameList: [],
      cardTypeName: "",
      cityName: "",
      leaderType: "",
      needRefresh: false,
      orderId: "",
      order: null,
      curTab: 0,
      loadingState: "loading",
      pageData: {
        page: 1,
        rows: 10,
        orderId: ""
      },
      isLoadMore: false,
      hasMore: "more",
      listRefreshTrig: false,
      replenlishList: [],
      //补充资料
      kind: "buy",
      //用来标识 buy买家  sell卖家
      files: [],
      downloadProgress: 0,
      downloading: false,
      underlineOffset: 20
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "详情"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#FFFFFF",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    const orderId = options.orderId;
    const kind = options.kind;
    if (orderId && orderId != "") {
      this.orderId = orderId;
      this.kind = kind;
      this.pageData.orderId = orderId;
      this.doGetOrderDetail();
    } else {
      this.msgHint = "数据有误,请稍后重试";
      this.msgType = "error";
      this.$refs.msg.open();
      setTimeout(() => {
        common_vendor.index.navigateBack();
      }, 1500);
    }
  },
  onShow() {
    if (this.needRefresh) {
      this.needRefresh = false;
      this.upPageNeedRefresh();
      this.doGetOrderDetail();
      this.doRefreshList();
    }
  },
  methods: {
    isImg: common_js_conver.isImg,
    // 更新下划线位置
    //显示补充详情
    doShowReplishDetail(e) {
      const item = e.currentTarget.dataset.item;
      if (this.kind == "buy" && item.buyId == "") {
        this.msgHint = "请补充内容";
        this.msgType = "error";
        this.$refs.msg.open();
        return;
      }
      if (this.kind == "sell" && item.sellId == "") {
        this.msgHint = "请补充内容";
        this.msgType = "error";
        this.$refs.msg.open();
        return;
      }
      common_vendor.index.navigateTo({
        url: "/pages/shop/replenishStuffDetail/replenishStuffDetail?id=" + item.correctionId + "&kind=" + this.kind
      });
    },
    bindChangeTab(e) {
      const tabIndex = e.currentTarget.dataset.value;
      this.curTab = tabIndex;
      if (this.curTab == 2) {
        this.doRefreshList();
      }
    },
    //加载补充资料
    doRefreshList() {
      this.loadingState = "loading";
      this.listRefreshTrig = true;
      this.replenlishList = [];
      this.isLoadMore = false;
      this.hasMore = "more";
      this.pageData.page = 1;
      this.doGetReplenish(true);
    },
    //加载更多
    doLoadMore() {
      const _self2 = this;
      if (_self2.isLoadMore || _self2.hasMore == "noMore") {
        return;
      }
      this.isLoadMore = true;
      this.hasMore = "loading";
      this.pageData.page = ++this.pageData.page;
      _self2.doGetReplenish(false);
    },
    //获取补充资料
    doGetReplenish(isRefresh) {
      const _self2 = this;
      common_js_net_shop.Shop.doGetReplenishList(_self2.kind, _self2.pageData).then((res) => {
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self2.loadingState = isRefresh ? status : "";
        _self2.replenlishList = _self2.replenlishList.concat(res.rows);
        _self2.isLoadMore = false;
        _self2.listRefreshTrig = false;
        _self2.hasMore = _self2.replenlishList.length < res.total ? "more" : "noMore";
      }).catch((err) => {
        _self2.loadingState = "error";
        _self2.isLoadMore = false;
        _self2.hasMore = "more";
        _self2.listRefreshTrig = false;
      });
    },
    //获取订单详情
    doGetOrderDetail() {
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const _self2 = this;
      common_js_net_shop.Shop.doGetOrderDetail(_self2.orderId).then((res) => {
        common_vendor.index.hideLoading();
        res.goodsDTO.goodsPhoto = common_js_net_mainUrl.sImgPrefix + res.goodsDTO.goodsPhoto;
        _self2.order = res;
        if (res.orderStatus == "过户已完成" && res.producePhoto != "") {
          _self2.doGetFileInfo(res.producePhoto);
        }
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self2.msgHint = err.msg ? err.msg : "网络错误,请稍后重试";
        _self2.msgType = "error";
        _self2.$refs.msg.open();
        setTimeout(() => {
          common_vendor.index.navigateBack();
        }, 1800);
      });
    },
    // 添加baseUrl
    addPrefix: function(list) {
      return list.map(function(item) {
        item.netUrl = common_js_net_mainUrl.sImgPrefix + item.fileId;
        return item;
      });
    },
    //获取文件详情
    doGetFileInfo(ids) {
      var that = this;
      var data = {
        ids
      };
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      common_js_net_shop.Shop.doGetFileInfos(data).then(function(res) {
        common_vendor.index.hideLoading();
        if (res && res !== null) {
          const list = that.addPrefix(res);
          that.files = list;
        }
      }).catch(function(err) {
        common_vendor.index.hideLoading();
        that.showMessage(err.msg || "获取证书详情失败,请稍后重试", "error");
      });
    },
    showMessage: function(msg, type) {
      this.msgHint = msg;
      this.msgType = type || "info";
      this.$refs.msg.open();
    },
    doPreImg(e) {
      common_vendor.index.previewImage({
        urls: [e.currentTarget.dataset.value]
      });
    },
    backPageRefresh() {
      let pages = getCurrentPages();
      let beforePage = pages[pages.length - 2];
      beforePage.$vm.needRefresh = true;
      common_vendor.index.navigateBack();
    },
    //取消订单
    doCancelOrder() {
      common_vendor.index.showModal({
        title: "提示",
        content: "您确定要取消该订单吗?",
        complete: (res) => {
          if (res.confirm) {
            this.goCancelOrder();
          }
        }
      });
    },
    goCancelOrder() {
      common_vendor.index.showLoading({
        title: "取消中..."
      });
      const _self2 = this;
      common_js_net_shop.Shop.doCancelOrder(_self2.orderId).then((res) => {
        common_vendor.index.hideLoading();
        _self2.msgHint = "取消成功";
        _self2.msgType = "success";
        _self2.$refs.msg.open();
        _self2.upPageNeedRefresh();
        _self2.doGetOrderDetail();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self2.msgHint = err.msg ? err.msg : "网络错误,请稍后重试";
        _self2.msgType = "error";
        _self2.$refs.msg.open();
      });
    },
    upPageNeedRefresh() {
      let pages = getCurrentPages();
      let beforePage = pages[pages.length - 2];
      beforePage.$vm.needRefresh = true;
    },
    //付款
    async doPayOrder() {
      try {
        const _self2 = this;
        common_vendor.index.showLoading({
          title: "付款中..."
        });
        await common_js_net_shop.Shop.doConfirmOrder(_self2.orderId);
        common_vendor.index.hideLoading();
        _self2.msgHint = "购买成功";
        _self2.msgType = "success";
        _self2.$refs.msg.open();
        setTimeout(() => {
          _self2.upPageNeedRefresh();
          _self2.doGetOrderDetail();
        }, 1500);
      } catch (err) {
        common_vendor.index.hideLoading();
        this.msgHint = err.msg ? err.msg : "网络错误,请稍后重试";
        this.msgType = "error";
        this.$refs.msg.open();
      }
    },
    //填报受让人信息
    bindFill() {
      common_vendor.index.navigateTo({
        url: "/pages/shop/addAssigneeInfo/addAssigneeInfo?orderId=" + this.orderId
      });
    },
    //补充材料
    goReplenish(e) {
      const item = e.currentTarget.dataset.value;
      common_vendor.index.navigateTo({
        url: "/pages/shop/addReplenishStuff/addReplenishStuff?id=" + item.correctionId
      });
    },
    doPreImg: function(e) {
      var url = e.currentTarget.dataset.value;
      common_vendor.index.previewImage({
        urls: [url]
      });
    },
    // 下载文件
    doDownloadFile: function(e) {
      var item = e.currentTarget.dataset.item;
      if (isImageFile(item.fileName)) {
        common_vendor.index.previewImage({
          urls: [item.netUrl]
        });
      } else {
        if (isDocumentFile(item.fileName)) {
          this.goDownloadFile(item);
        } else {
          this.showMessage("该文件无法在小程序中打开,请前往电脑端查看", "info");
        }
      }
    },
    async goDownloadFile(item) {
      try {
        common_vendor.index.__f__("log", "at pages/shop/orderDetail/orderDetail.vue:629", item);
        const _self2 = this;
        _self2.downloadProgress = 0;
        _self2.downloading = true;
        const url = item.netUrl + "." + item.fileType;
        const fileName = item.fileName;
        const token = common_js_cache_storage.get("token");
        const header = {};
        if (token) {
          header.Auth = `Bearer ${token}`;
        }
        const downloadRes = await _self2.doStartDownload(url, header);
        if (downloadRes && downloadRes.statusCode == 200) {
          if (downloadRes.tempFilePath.endsWith(".txt")) {
            _self2.msgTxt = "下载成功";
            _self2.msgType = "success";
            _self2.$refs.msg.open();
            _self2.showDownload = false;
            _self2.downloading = false;
            _self2.downloadProgress = 0;
            common_vendor.index.navigateTo({
              url: "/pages/common/readTxt/readTxt?filePath=" + downloadRes.tempFilePath
            });
          } else {
            common_vendor.index.openDocument({
              filePath: downloadRes.tempFilePath,
              fileType: item.fileType,
              showMenu: true,
              success(res) {
                common_vendor.index.__f__("log", "at pages/shop/orderDetail/orderDetail.vue:660", res);
                _self2.showDownload = false;
                _self2.downloading = false;
                _self2.downloadProgress = 0;
              },
              fail(err) {
                _self2.showErr("很抱歉，文件下载出现问题。建议您稍作等待，之后再尝试下载。");
              }
            });
          }
        } else {
          _self2.showErr("很抱歉，文件下载出现问题。建议您稍作等待，之后再尝试下载。");
        }
      } catch (err) {
        _self.showErr("很抱歉，文件下载出现问题。建议您稍作等待，之后再尝试下载。");
      }
    },
    //下载文件
    doStartDownload(url, header) {
      const _self2 = this;
      return new Promise((resolve, reject) => {
        const downloadTask = common_vendor.index.downloadFile({
          url,
          header,
          success: resolve,
          fail: reject
        });
        downloadTask.onProgressUpdate((res) => {
          _self2.downloadProgress = res.progress;
        });
      });
    },
    showErr(msg) {
      const _self2 = this;
      _self2.msgHint = msg;
      _self2.msgType = "error";
      _self2.downloading = false;
      _self2.downloadProgress = 0;
      _self2.$refs.msg.open();
    }
  }
};
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _component_ContainerLoading = common_vendor.resolveComponent("ContainerLoading");
  const _component_template = common_vendor.resolveComponent("template");
  const _component_DownloadProgress = common_vendor.resolveComponent("DownloadProgress");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_load_more2 + _component_ContainerLoading + _component_template + _component_DownloadProgress + _easycom_uni_popup_message2 + _easycom_uni_popup2)();
}
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.order != null
  }, $data.order != null ? common_vendor.e({
    b: common_vendor.o((...args) => $options.doPreImg && $options.doPreImg(...args)),
    c: $data.order.goodsDTO.goodsPhoto,
    d: $data.order.goodsDTO.goodsPhoto,
    e: common_vendor.o((...args) => $options.bindChangeTab && $options.bindChangeTab(...args)),
    f: common_vendor.n($data.curTab == 0 ? "tab-item-active" : "tab-item-inactive"),
    g: common_vendor.o((...args) => $options.bindChangeTab && $options.bindChangeTab(...args)),
    h: common_vendor.n($data.curTab == 1 ? "tab-item-active" : "tab-item-inactive"),
    i: $data.order.waitCorrectionCount > 0
  }, $data.order.waitCorrectionCount > 0 ? {
    j: common_vendor.t($data.order.waitCorrectionCount)
  } : {}, {
    k: common_vendor.o((...args) => $options.bindChangeTab && $options.bindChangeTab(...args)),
    l: common_vendor.n($data.curTab == 2 ? "tab-item-active" : "tab-item-inactive"),
    m: $data.order.buyUserDTO != null && $data.kind == "buy"
  }, $data.order.buyUserDTO != null && $data.kind == "buy" ? {
    n: common_vendor.o((...args) => $options.bindChangeTab && $options.bindChangeTab(...args)),
    o: common_vendor.n($data.curTab == 3 ? "tab-item-active" : "tab-item-inactive")
  } : {}, {
    p: $data.kind == "buy" && $data.order.orderStatus == "过户已完成"
  }, $data.kind == "buy" && $data.order.orderStatus == "过户已完成" ? {
    q: common_vendor.o((...args) => $options.bindChangeTab && $options.bindChangeTab(...args)),
    r: common_vendor.n($data.curTab == 4 ? "tab-item-active" : "tab-item-inactive")
  } : {}, {
    s: $data.curTab == 0
  }, $data.curTab == 0 ? {
    t: common_vendor.t($data.order.goodsDTO.goodsPrice),
    v: common_vendor.t($data.order.orderStatus),
    w: common_vendor.t($data.order.createTime),
    x: common_vendor.t($data.order.payTime == "" ? "未付款" : $data.order.payTime)
  } : {}, {
    y: $data.curTab == 1
  }, $data.curTab == 1 ? common_vendor.e({
    z: common_vendor.t($data.order.goodsDTO.goodsName),
    A: common_vendor.t($data.order.goodsDTO.goodsOpenPrice),
    B: common_vendor.t($data.order.goodsDTO.goodsStatusTime),
    C: $data.kind == "sell"
  }, $data.kind == "sell" ? {
    D: common_vendor.t($data.order.sellUserDTO.type),
    E: common_vendor.t($data.order.sellUserDTO.name),
    F: common_vendor.t($data.order.sellUserDTO.city),
    G: common_vendor.t($data.order.sellUserDTO.phone),
    H: common_vendor.t($data.order.sellUserDTO.idcardType),
    I: common_vendor.t($data.order.sellUserDTO.idcard)
  } : {}) : {}, {
    J: $data.curTab == 2
  }, $data.curTab == 2 ? {
    K: common_vendor.f($data.replenlishList, (item, index, i0) => {
      return common_vendor.e({
        a: index,
        b: common_vendor.t(item.correctionTitle),
        c: item,
        d: $data.kind == "buy" && item.buyId == ""
      }, $data.kind == "buy" && item.buyId == "" ? {
        e: item,
        f: common_vendor.o((...args) => $options.goReplenish && $options.goReplenish(...args))
      } : {}, {
        g: $data.kind == "sell" && item.sellId == ""
      }, $data.kind == "sell" && item.sellId == "" ? {
        h: item,
        i: common_vendor.o((...args) => $options.goReplenish && $options.goReplenish(...args))
      } : {}, {
        j: common_vendor.t(item.correctionRemark),
        k: item
      }, $data.kind == "sell" ? {
        l: common_vendor.t(item.sellId == "" ? "待补充" : "已补充"),
        m: common_vendor.n(item.sellId == "" ? "col-primary" : "col-green")
      } : {}, $data.kind == "buy" ? {
        n: common_vendor.t(item.buyId == "" ? "待补充" : "已补充"),
        o: common_vendor.n(item.buyId == "" ? "col-primary" : "col-green")
      } : {}, {
        p: common_vendor.t(item.createTime)
      });
    }),
    L: common_vendor.o((...args) => $options.doShowReplishDetail && $options.doShowReplishDetail(...args)),
    M: common_vendor.o((...args) => $options.doShowReplishDetail && $options.doShowReplishDetail(...args)),
    N: $data.kind == "sell",
    O: $data.kind == "buy",
    P: common_vendor.p({
      status: $data.hasMore
    }),
    Q: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    R: common_vendor.p({
      loadingVisible: $data.loadingState,
      bindrefresh: "doRefreshList"
    })
  } : {}, {
    S: $data.curTab == 3 && $data.kind == "buy"
  }, $data.curTab == 3 && $data.kind == "buy" ? {
    T: common_vendor.t($data.order.buyUserDTO.type != "" ? $data.order.buyUserDTO.type : "暂无"),
    U: common_vendor.t($data.order.buyUserDTO.name != "" ? $data.order.buyUserDTO.name : "暂无"),
    V: common_vendor.t($data.order.buyUserDTO.city != "" ? $data.order.buyUserDTO.city : "暂无"),
    W: common_vendor.t($data.order.buyUserDTO.phone != "" ? $data.order.buyUserDTO.phone : "暂无"),
    X: common_vendor.t($data.order.buyUserDTO.idcardType != "" ? $data.order.buyUserDTO.idcardType : "暂无"),
    Y: common_vendor.t($data.order.buyUserDTO.idcard != "" ? $data.order.buyUserDTO.idcardType : "暂无")
  } : {}, {
    Z: $data.curTab == 4 && $data.kind == "buy" && $data.order.orderStatus == "过户已完成"
  }, $data.curTab == 4 && $data.kind == "buy" && $data.order.orderStatus == "过户已完成" ? {
    aa: common_vendor.t($data.order.produceTime),
    ab: common_vendor.f($data.files, (item, index, i0) => {
      return common_vendor.e({
        a: $options.isImg(item.fileType)
      }, $options.isImg(item.fileType) ? {
        b: item.netUrl,
        c: common_vendor.t(item.fileName)
      } : {}, {
        d: common_vendor.t(item.fileName),
        e: item
      });
    }),
    ac: common_vendor.p({
      ["wx:else"]: ""
    }),
    ad: common_vendor.o((...args) => $options.doDownloadFile && $options.doDownloadFile(...args))
  } : {}) : {}, {
    ae: $data.order != null
  }, $data.order != null ? common_vendor.e({
    af: $data.order.orderStatus == "买家待付款" || $data.order.orderStatus == "待填写资料"
  }, $data.order.orderStatus == "买家待付款" || $data.order.orderStatus == "待填写资料" ? {
    ag: common_vendor.o((...args) => $options.doCancelOrder && $options.doCancelOrder(...args))
  } : {}, {
    ah: $data.order.orderStatus == "买家待付款" && $data.kind == "buy"
  }, $data.order.orderStatus == "买家待付款" && $data.kind == "buy" ? {
    ai: common_vendor.o((...args) => $options.doPayOrder && $options.doPayOrder(...args))
  } : {}, {
    aj: $data.order.orderStatus == "待填写资料" && $data.kind == "buy"
  }, $data.order.orderStatus == "待填写资料" && $data.kind == "buy" ? {
    ak: common_vendor.o((...args) => $options.bindFill && $options.bindFill(...args))
  } : {}) : {}, {
    al: common_vendor.p({
      isShow: $data.downloading,
      progress: $data.downloadProgress
    }),
    am: common_vendor.p({
      duration: 2e3,
      type: $data.msgType,
      message: $data.msgHint
    }),
    an: common_vendor.sr("msg", "564ec1bd-3"),
    ao: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-564ec1bd"]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/pages/shop/orderDetail/orderDetail.js.map
