goods.js 10 KB

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