"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_conver = require("../../../common/js/conver.js");
const common_js_net_shop = require("../../../common/js/net/shop.js");
const common_js_net_mainUrl = require("../../../common/js/net/mainUrl.js");
const _sfc_main = {
  setup() {
  },
  data() {
    return {
      msgHint: "",
      msgType: "info",
      msgShow: false,
      showType: false,
      goodsId: "",
      goods: null,
      typeNameList: [],
      cardTypeName: "",
      cityName: "",
      leaderType: "",
      needRefresh: false
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "我要卖"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#FFFFFF",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    const id = options.id;
    if (id && id != "") {
      this.goodsId = id;
      this.doGetGoodsDetail();
    } 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.doGetGoodsDetail();
    }
  },
  methods: {
    goodsStatus: common_js_conver.goodsStatus,
    //获取商品详情
    doGetGoodsDetail() {
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const that = this;
      common_js_net_shop.Shop.doGetGoodsDetail(this.goodsId).then((res) => {
        common_vendor.index.hideLoading();
        if (res && res != null) {
          res.goodsLocalPhoto = common_js_net_mainUrl.sImgPrefix + res.goodsLocalPhoto;
          switch (res.goodsLeaderType) {
            case "1":
              res.goodsLeaderTypeName = "自然人";
              break;
            case "2":
              res.goodsLeaderTypeName = "法人";
              break;
            case "3":
              res.goodsLeaderTypeName = "非法人组织或其他";
              break;
          }
          that.goods = res;
          that.getDic();
        } else {
          that.msgHint = "网络错误,请稍后重试";
          that.msgType = "error";
          that.$refs.msg.open();
          setTimeout(() => {
            common_vendor.index.navigateBack();
          }, 1800);
        }
      }).catch((err) => {
        common_vendor.index.hideLoading();
        that.msgHint = err.msg ? err.msg : "网络错误,请稍后重试";
        that.msgth = "error";
        that.$refs.msg.open();
        setTimeout(() => {
          common_vendor.index.navigateBack();
        }, 1800);
      });
    },
    //获取字典详情
    getDic() {
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const that = this;
      const sort = common_js_net_shop.Shop.doGetGoodsDic("0b00884a-f7a2-425f-93e5-599fbaad4bde");
      const type = common_js_net_shop.Shop.doGetDicDetail(that.goods.goodsLeaderIdcardType);
      const city1 = common_js_net_shop.Shop.doGetAreaDetail(that.goods.goodsLeaderCity1);
      const city2 = common_js_net_shop.Shop.doGetAreaDetail(that.goods.goodsLeaderCity2);
      const list = [sort, type, city1, city2];
      Promise.all(list).then((res) => {
        common_vendor.index.hideLoading();
        if (res && res.length > 0) {
          const tempList = [];
          res[0].forEach((item) => {
            if (that.goods.goodsType.indexOf(item.dataId) != -1) {
              tempList.push(item);
            }
          });
          that.typeNameList = tempList;
          that.cardTypeName = res[1].dataName;
          that.cityName = res[2].areaName + "/" + res[3].areaName;
        }
      }).catch((err) => {
        common_vendor.index.__f__("log", "at pages/shop/manageGoods/manageGoods.vue:254", err);
        common_vendor.index.hideLoading();
      });
    },
    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();
    },
    //提交审核
    doCheck() {
      common_vendor.index.showModal({
        title: "提示",
        content: "确定要将该软著商品提交审核吗?",
        complete: (res) => {
          if (res.confirm) {
            this.goCheck();
          }
        }
      });
    },
    //去审核
    goCheck() {
      common_vendor.index.showLoading({
        title: "提交中..."
      });
      const that = this;
      common_js_net_shop.Shop.doSubCheck(that.goodsId).then((res) => {
        common_vendor.index.hideLoading();
        that.msgHint = "提交成功";
        that.msgType = "success";
        that.$refs.msg.open();
        that.upPageNeedRefresh();
        that.doGetGoodsDetail();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        that.msgHint = err.msg ? err.msg : "网络错误,请稍后重试";
        that.msgType = "error";
        that.$refs.msg.open();
      });
    },
    //去编辑
    doEdit() {
      const that = this;
      common_vendor.index.__f__("log", "at pages/shop/manageGoods/manageGoods.vue:306", "mangage商品ID", that.goodsId);
      common_vendor.index.navigateTo({
        url: "/pages/shop/publishGoods/publishGoods?id=" + that.goodsId
      });
    },
    //删除
    doDel() {
      common_vendor.index.showModal({
        title: "警告",
        content: "您确定要删除该软著商品吗?",
        complete: (res) => {
          if (res.confirm) {
            this.goDel();
          }
        }
      });
    },
    //删除
    goDel() {
      common_vendor.index.showLoading({
        title: "删除中..."
      });
      const that = this;
      common_js_net_shop.Shop.doDelGoods(that.goodsId).then((res) => {
        common_vendor.index.hideLoading();
        that.msgHint = "删除成功";
        that.msgType = "success";
        that.$refs.msg.open();
        setTimeout(() => {
          that.backPageRefresh();
        }, 1200);
      }).catch((err) => {
        common_vendor.index.hideLoading();
        that.msgHint = err.msg ? err.msg : "网络错误,请稍后重试";
        that.msgType = "error";
        that.$refs.msg.open();
      });
    },
    //上架或下架
    doSale() {
      var content;
      var status = "publish";
      if (this.goods.goodsStatus == "1") {
        content = "您确定要下架该软著商品吗?";
        status = "no-publish";
      } else if (this.goods.goodsStatus == "0") {
        content = "您确定要上架该软著商品吗?";
        status = "publish";
      }
      common_vendor.index.showModal({
        title: "提示",
        content,
        complete: (res) => {
          if (res.confirm) {
            this.goSale(status);
          }
        }
      });
    },
    //上下架
    goSale(status) {
      common_vendor.index.showLoading({
        title: "操作中..."
      });
      const that = this;
      common_js_net_shop.Shop.doSaleGoods(status, that.goodsId).then((res) => {
        common_vendor.index.hideLoading();
        that.msgHint = "操作成功";
        that.msgType = "success";
        that.$refs.msg.open();
        that.upPageNeedRefresh();
        that.doGetGoodsDetail();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        that.msgHint = err.msg ? err.msg : "网络错误,请稍后重试";
        that.msgType = "error";
        that.$refs.msg.open();
      });
    },
    upPageNeedRefresh() {
      let pages = getCurrentPages();
      let beforePage = pages[pages.length - 2];
      beforePage.$vm.needRefresh = true;
    }
  }
};
if (!Array) {
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_popup_message2 + _easycom_uni_popup2)();
}
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_popup_message + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $data.goods != null
  }, $data.goods != null ? common_vendor.e({
    b: common_vendor.o((...args) => $options.doPreImg && $options.doPreImg(...args)),
    c: $data.goods.goodsLocalPhoto,
    d: $data.goods.goodsLocalPhoto,
    e: $data.goods.goodsCheckStatus != ""
  }, $data.goods.goodsCheckStatus != "" ? common_vendor.e({
    f: common_vendor.t($options.goodsStatus($data.goods.goodsCheckStatus, $data.goods.goodsStatus, $data.goods.goodsOrderStatus)),
    g: $data.goods.goodsCheckRemark != ""
  }, $data.goods.goodsCheckRemark != "" ? {
    h: common_vendor.t($data.goods.goodsCheckRemark)
  } : {}) : {}, {
    i: common_vendor.t($data.goods.goodsName),
    j: common_vendor.f($data.typeNameList, (item, index, i0) => {
      return {
        a: index,
        b: common_vendor.t(item.dataName)
      };
    }),
    k: common_vendor.t($data.goods.goodsPrice),
    l: common_vendor.t($data.goods.goodsLastTime),
    m: common_vendor.t($data.goods.goodsLeaderTypeName),
    n: common_vendor.t($data.goods.goodsLeader),
    o: common_vendor.t($data.cityName),
    p: common_vendor.t($data.goods.goodsLeaderPhone),
    q: common_vendor.t($data.cardTypeName),
    r: common_vendor.t($data.goods.goodsLeaderIdcard)
  }) : {}, {
    s: $data.goods != null
  }, $data.goods != null ? common_vendor.e({
    t: $data.goods.goodsCheckStatus != "1" && $data.goods.goodsStatus != "1"
  }, $data.goods.goodsCheckStatus != "1" && $data.goods.goodsStatus != "1" ? {
    v: common_vendor.o((...args) => $options.doDel && $options.doDel(...args))
  } : {}, {
    w: $data.goods.goodsStatus != "1"
  }, $data.goods.goodsStatus != "1" ? {
    x: common_vendor.o((...args) => $options.doEdit && $options.doEdit(...args))
  } : {}, {
    y: $data.goods.goodsCheckStatus == "" || $data.goods.goodsCheckStatus == "0"
  }, $data.goods.goodsCheckStatus == "" || $data.goods.goodsCheckStatus == "0" ? {
    z: common_vendor.o((...args) => $options.doCheck && $options.doCheck(...args))
  } : {}, {
    A: $data.goods.goodsCheckStatus == "2"
  }, $data.goods.goodsCheckStatus == "2" ? {
    B: common_vendor.t($data.goods.goodsStatus == "1" ? "下架" : "上架"),
    C: common_vendor.o((...args) => $options.doSale && $options.doSale(...args))
  } : {}) : {}, {
    D: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    E: common_vendor.sr("msg", "0017f074-0"),
    F: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-0017f074"]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/pages/shop/manageGoods/manageGoods.js.map
