goods.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const api_order = require("../api/order.js");
  4. const api_live = require("../api/live.js");
  5. const common_assets = require("../common/assets.js");
  6. const popupBottom = () => "../components/px-popup-bottom/px-popup-bottom.js";
  7. const _sfc_main = {
  8. components: {
  9. popupBottom
  10. },
  11. data() {
  12. return {
  13. goodsId: null,
  14. totalNum: 1,
  15. orderKey: null,
  16. type: null,
  17. liveOrderList: [],
  18. //下订单的 不在这个页面
  19. liveId: null,
  20. // storeId:uni.setStorageSync("storeId"),
  21. serviceList: ["免邮发货", "药师服务", "隐私保护"],
  22. editShow: false,
  23. productId: null,
  24. goosDetail: {},
  25. //商品详情
  26. loadding: true,
  27. buyText: "立即购买",
  28. showStorePicker: false,
  29. goodsNum: 0,
  30. //商品选择数量
  31. attrs: [],
  32. values: [],
  33. stores: [],
  34. storeNames: [],
  35. storeIdx: 0,
  36. storeName: "",
  37. product: {
  38. price: 0,
  39. otPrice: 0
  40. },
  41. showModal: false,
  42. // 当前轮播的图片
  43. activeBanner: 1,
  44. // 购物车数量
  45. cartCount: 0,
  46. // 规格弹窗
  47. specVisible: false,
  48. // // 规格数量
  49. // specNum: 1,
  50. config: null,
  51. showServiceFee: false,
  52. selectVal: "",
  53. // 链接带的storeId
  54. urlStoreId: void 0,
  55. // 所选规格门店店铺价格
  56. storePriceList: [],
  57. // 所选店铺
  58. storeSelectInfo: {},
  59. // 保存选的规格
  60. choseSpecSubIndex: 0,
  61. choseSpecIndex: 0
  62. };
  63. },
  64. onLoad(options) {
  65. if (options.productId) {
  66. this.productId = options.productId;
  67. console.log("接收到的productId:", this.productId);
  68. }
  69. this.liveId = options.liveId;
  70. this.goodsId = options.goodsId;
  71. },
  72. mounted() {
  73. this.getliveGoods();
  74. var userInfo = common_vendor.index.getStorageSync("userInfo");
  75. console.log("之前的数据在这里", userInfo);
  76. },
  77. onShow() {
  78. },
  79. methods: {
  80. // getLiveCartDetails() {
  81. // let data = {
  82. // productId: this.productId,
  83. // liveId: this.liveId,
  84. // goodsId: this.goodsId,
  85. // cartNum: this.totalNum,
  86. // };
  87. // liveCartDetails(data).then(
  88. // res => {
  89. // if (res.code == 200) {
  90. // console.log("加购物车啦", res)
  91. // this.cartCount = cartRes.data;
  92. // }
  93. // },
  94. // rej => {}
  95. // );
  96. // },
  97. doAddCart(type) {
  98. if (this.totalNum == 0) {
  99. common_vendor.index.showToast({
  100. icon: "none",
  101. title: "库存不足"
  102. });
  103. return;
  104. }
  105. if (type == "buy") {
  106. this.getKey();
  107. } else {
  108. this.getCartCount();
  109. common_vendor.index.showToast({
  110. icon: "success",
  111. title: "添加成功"
  112. });
  113. }
  114. },
  115. getCartCount() {
  116. let data = {
  117. productId: this.productId,
  118. liveId: this.liveId,
  119. goodsId: this.goodsId,
  120. cartNum: this.totalNum
  121. };
  122. api_order.addLiveCart(data).then(
  123. (res) => {
  124. if (res.code == 200) {
  125. console.log("加购物车啦", res);
  126. this.cartCount = res.data;
  127. }
  128. },
  129. (rej) => {
  130. }
  131. );
  132. },
  133. // 获得key
  134. getKey() {
  135. api_order.liveOrderKey().then(
  136. (res) => {
  137. if (res.code == 200) {
  138. console.log("下订单的key>>>>", res);
  139. this.orderKey = res.orderKey;
  140. console.log("key>>>>", this.orderKey);
  141. common_vendor.index.navigateTo({
  142. url: "/pages_shop/confirmCreateOrder?type=goods&orderKey=" + this.orderKey + "&liveId=" + this.liveId + "&productId=" + this.productId + "&totalNum=" + this.totalNum + "&price=" + this.goosDetail.price
  143. });
  144. } else {
  145. common_vendor.index.showToast({
  146. title: res.msg,
  147. icon: "none"
  148. });
  149. }
  150. },
  151. (rej) => {
  152. }
  153. );
  154. },
  155. // 点击取消/支付订单
  156. operateOrder(type) {
  157. let orderId = this.liveOrderList;
  158. console.log("orderId>>", orderId);
  159. },
  160. // 选择商品数量
  161. goodsNumChange(e) {
  162. console.log("当前选择商品数量为: " + e.value);
  163. this.totalNum = e.value;
  164. },
  165. // 提交
  166. submit() {
  167. this.specVisible = false;
  168. this.doAddCart(this.type);
  169. },
  170. // 加入购物车
  171. addCart(type) {
  172. this.type = type;
  173. this.specVisible = true;
  174. },
  175. // 跳转页面
  176. navgetTo(url) {
  177. console.log("跳转");
  178. common_vendor.index.navigateTo({
  179. url
  180. });
  181. },
  182. openEditMoney() {
  183. this.editShow = true;
  184. },
  185. //商品详情
  186. getliveGoods() {
  187. api_live.liveGoodsDetail(this.productId).then(
  188. (res) => {
  189. if (res.code == 200) {
  190. console.log("小黄车 商品详情>>>>", res);
  191. this.goosDetail = res.data;
  192. } else {
  193. common_vendor.index.showToast({
  194. title: res.msg,
  195. icon: "none"
  196. });
  197. }
  198. },
  199. (rej) => {
  200. }
  201. );
  202. }
  203. }
  204. };
  205. if (!Array) {
  206. const _component_uni_badge = common_vendor.resolveComponent("uni-badge");
  207. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  208. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  209. const _easycom_u_number_box2 = common_vendor.resolveComponent("u-number-box");
  210. const _component_popupBottom = common_vendor.resolveComponent("popupBottom");
  211. (_component_uni_badge + _easycom_u_icon2 + _easycom_u_popup2 + _easycom_u_number_box2 + _component_popupBottom)();
  212. }
  213. const _easycom_u_icon = () => "../uni_modules/uview-plus/components/u-icon/u-icon.js";
  214. const _easycom_u_popup = () => "../uni_modules/uview-plus/components/u-popup/u-popup.js";
  215. const _easycom_u_number_box = () => "../uni_modules/uview-plus/components/u-number-box/u-number-box.js";
  216. if (!Math) {
  217. (_easycom_u_icon + _easycom_u_popup + _easycom_u_number_box)();
  218. }
  219. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  220. var _a;
  221. return common_vendor.e({
  222. a: $data.goosDetail.imgUrl,
  223. b: $data.product.productType == 2
  224. }, $data.product.productType == 2 ? {} : {}, {
  225. c: common_vendor.t($data.goosDetail.price),
  226. d: common_vendor.t($data.goosDetail.otPrice),
  227. e: common_vendor.t($data.goosDetail.sales),
  228. f: common_vendor.f($data.serviceList, (item, index, i0) => {
  229. return {
  230. a: common_vendor.t(item),
  231. b: index
  232. };
  233. }),
  234. g: common_assets._imports_0$8,
  235. h: common_assets._imports_1$7,
  236. i: common_vendor.o(($event) => $options.openEditMoney()),
  237. j: $data.editShow
  238. }, $data.editShow ? {
  239. k: common_vendor.o(($event) => _ctx.cancelEditMoney()),
  240. l: common_vendor.o(($event) => _ctx.cancelEditMoney()),
  241. m: common_vendor.o(($event) => _ctx.cancelEditMoney())
  242. } : {}, {
  243. n: common_vendor.t(),
  244. o: common_vendor.o(($event) => $options.navgetTo("/pages_shop/store?liveId=" + $data.liveId)),
  245. p: $data.product.description,
  246. q: common_assets._imports_2$5,
  247. r: common_vendor.o(($event) => $options.navgetTo("./store")),
  248. s: common_assets._imports_3$1,
  249. t: common_vendor.p({
  250. size: "small",
  251. text: $data.cartCount,
  252. absolute: "rightTop",
  253. type: "error"
  254. }),
  255. v: common_vendor.o(($event) => $options.navgetTo("./cart")),
  256. w: common_vendor.o(($event) => $options.addCart("cart")),
  257. x: common_vendor.t($data.buyText),
  258. y: common_vendor.o(($event) => $options.addCart("buy")),
  259. z: ((_a = $data.goosDetail) == null ? void 0 : _a.imgUrl) || _ctx.$img.img,
  260. A: common_vendor.t($data.goosDetail.productName),
  261. B: common_vendor.t($data.goosDetail.price ? $data.goosDetail.price.toFixed(2) : "0.00"),
  262. C: common_vendor.t($data.goosDetail.sales),
  263. D: common_vendor.f($data.storePriceList, (item, index, i0) => {
  264. return {
  265. a: common_vendor.t(item.price.toFixed(2)),
  266. b: common_vendor.t(_ctx.utils.formatSalesNum(item.sales)),
  267. c: common_vendor.t(item.storeName),
  268. d: "14e5f6c8-3-" + i0 + ",14e5f6c8-2",
  269. e: index,
  270. f: common_vendor.n(_ctx.productValueSelect.storeId == item.storeId ? "item hover" : "item"),
  271. g: common_vendor.o(($event) => _ctx.pickerStore(item, index), index)
  272. };
  273. }),
  274. E: common_vendor.p({
  275. name: "arrow-right",
  276. color: "#000",
  277. size: "14"
  278. }),
  279. F: common_vendor.p({
  280. show: $data.showStorePicker,
  281. round: 16,
  282. mode: "bottom"
  283. }),
  284. G: common_vendor.o($options.goodsNumChange),
  285. H: common_vendor.o(($event) => $data.goodsNum = $event),
  286. I: common_vendor.p({
  287. bgColor: "#ececec",
  288. modelValue: $data.goodsNum
  289. }),
  290. J: common_vendor.o((...args) => $options.submit && $options.submit(...args)),
  291. K: common_vendor.sr("popup", "14e5f6c8-1"),
  292. L: common_vendor.p({
  293. visible: $data.specVisible,
  294. title: " ",
  295. radius: "32",
  296. maxHeight: "800"
  297. })
  298. });
  299. }
  300. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  301. wx.createPage(MiniProgramPage);