goods.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. let key = "";
  92. api_live.store(this.storeId, key).then(
  93. (res) => {
  94. if (res.code == 200) {
  95. console.log("查询店铺>>>>", res);
  96. this.storeInfo = res.data;
  97. } else {
  98. common_vendor.index.showToast({
  99. title: res.msg,
  100. icon: "none"
  101. });
  102. }
  103. },
  104. (rej) => {
  105. }
  106. );
  107. },
  108. //店铺展示
  109. getliveStore() {
  110. let data = {
  111. pageSize: 10,
  112. page: 1
  113. };
  114. liveStore(this.liveId, data).then(
  115. (res) => {
  116. if (res.code == 200) {
  117. console.log("小黄车 店铺展示>>>>", res);
  118. this.products = res.data;
  119. } else {
  120. common_vendor.index.showToast({
  121. title: res.msg,
  122. icon: "none"
  123. });
  124. }
  125. },
  126. (rej) => {
  127. }
  128. );
  129. },
  130. // getLiveCartDetails() {
  131. // let data = {
  132. // productId: this.productId,
  133. // liveId: this.liveId,
  134. // goodsId: this.goodsId,
  135. // cartNum: this.totalNum,
  136. // };
  137. // liveCartDetails(data).then(
  138. // res => {
  139. // if (res.code == 200) {
  140. // console.log("加购物车啦", res)
  141. // this.cartCount = cartRes.data;
  142. // }
  143. // },
  144. // rej => {}
  145. // );
  146. // },
  147. doAddCart(type) {
  148. if (this.totalNum == 0) {
  149. common_vendor.index.showToast({
  150. icon: "none",
  151. title: "库存不足"
  152. });
  153. return;
  154. }
  155. if (type == "buy") {
  156. this.getKey();
  157. } else {
  158. this.getCartCount();
  159. common_vendor.index.showToast({
  160. icon: "success",
  161. title: "添加成功"
  162. });
  163. }
  164. },
  165. getCartCount() {
  166. let data = {
  167. productId: this.productId,
  168. liveId: this.liveId,
  169. goodsId: this.goodsId,
  170. cartNum: this.totalNum
  171. };
  172. api_order.addLiveCart(data).then(
  173. (res) => {
  174. if (res.code == 200) {
  175. console.log("加购物车啦", res);
  176. this.cartCount = res.data;
  177. }
  178. },
  179. (rej) => {
  180. }
  181. );
  182. },
  183. // 获得key
  184. getKey() {
  185. api_order.liveOrderKey().then(
  186. (res) => {
  187. if (res.code == 200) {
  188. console.log("下订单的key>>>>", res);
  189. this.orderKey = res.orderKey;
  190. console.log("key>>>>", this.orderKey);
  191. common_vendor.index.navigateTo({
  192. url: "/pages_shop/confirmCreateOrder?type=goods&orderKey=" + this.orderKey + "&liveId=" + this.liveId + "&productId=" + this.productId + "&totalNum=" + this.totalNum + "&price=" + this.goosDetail.price
  193. });
  194. } else {
  195. common_vendor.index.showToast({
  196. title: res.msg,
  197. icon: "none"
  198. });
  199. }
  200. },
  201. (rej) => {
  202. }
  203. );
  204. },
  205. // 点击取消/支付订单
  206. operateOrder(type) {
  207. let orderId = this.liveOrderList;
  208. console.log("orderId>>", orderId);
  209. },
  210. // 选择商品数量
  211. goodsNumChange(e) {
  212. console.log("当前选择商品数量为: " + e.value);
  213. this.totalNum = e.value;
  214. },
  215. // 提交
  216. submit() {
  217. this.specVisible = false;
  218. this.doAddCart(this.type);
  219. },
  220. // 加入购物车
  221. addCart(type) {
  222. this.type = type;
  223. this.specVisible = true;
  224. },
  225. // 跳转页面
  226. navgetTo(url) {
  227. console.log("跳转");
  228. common_vendor.index.navigateTo({
  229. url
  230. });
  231. },
  232. openEditMoney() {
  233. this.editShow = true;
  234. },
  235. //商品详情
  236. getliveGoods() {
  237. api_live.liveGoodsDetail(this.productId).then(
  238. (res) => {
  239. if (res.code == 200) {
  240. console.log("小黄车 商品详情>>>>", res);
  241. this.goosDetail = res.data;
  242. } else {
  243. common_vendor.index.showToast({
  244. title: res.msg,
  245. icon: "none"
  246. });
  247. }
  248. },
  249. (rej) => {
  250. }
  251. );
  252. }
  253. }
  254. };
  255. if (!Array) {
  256. const _component_uni_badge = common_vendor.resolveComponent("uni-badge");
  257. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  258. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  259. const _easycom_u_number_box2 = common_vendor.resolveComponent("u-number-box");
  260. const _component_popupBottom = common_vendor.resolveComponent("popupBottom");
  261. (_component_uni_badge + _easycom_u_icon2 + _easycom_u_popup2 + _easycom_u_number_box2 + _component_popupBottom)();
  262. }
  263. const _easycom_u_icon = () => "../uni_modules/uview-plus/components/u-icon/u-icon.js";
  264. const _easycom_u_popup = () => "../uni_modules/uview-plus/components/u-popup/u-popup.js";
  265. const _easycom_u_number_box = () => "../uni_modules/uview-plus/components/u-number-box/u-number-box.js";
  266. if (!Math) {
  267. (_easycom_u_icon + _easycom_u_popup + _easycom_u_number_box)();
  268. }
  269. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  270. var _a, _b, _c, _d;
  271. return common_vendor.e({
  272. a: $data.goosDetail.imgUrl,
  273. b: $data.product.productType == 2
  274. }, $data.product.productType == 2 ? {} : {}, {
  275. c: common_vendor.t($data.goosDetail.price),
  276. d: common_vendor.t($data.goosDetail.otPrice),
  277. e: common_vendor.t($data.goosDetail.sales),
  278. f: common_vendor.f($data.serviceList, (item, index, i0) => {
  279. return {
  280. a: common_vendor.t(item),
  281. b: index
  282. };
  283. }),
  284. g: common_assets._imports_0$8,
  285. h: common_assets._imports_1$7,
  286. i: common_vendor.o(($event) => $options.openEditMoney()),
  287. j: $data.editShow
  288. }, $data.editShow ? {
  289. k: common_vendor.o(($event) => _ctx.cancelEditMoney()),
  290. l: common_vendor.o(($event) => _ctx.cancelEditMoney()),
  291. m: common_vendor.o(($event) => _ctx.cancelEditMoney())
  292. } : {}, {
  293. n: $data.storeInfo
  294. }, $data.storeInfo ? {
  295. o: ((_a = $data.storeInfo) == null ? void 0 : _a.logoUrl) || _ctx.$img.img,
  296. p: common_vendor.t((_b = $data.storeInfo) == null ? void 0 : _b.storeName),
  297. q: common_vendor.t((_c = $data.storeInfo) == null ? void 0 : _c.salesCount),
  298. r: common_vendor.o(($event) => $options.navgetTo("/pages_shop/store?liveId=" + $data.liveId + "&storeId=" + $data.storeId))
  299. } : {}, {
  300. s: $data.product.description,
  301. t: common_assets._imports_2$4,
  302. v: common_vendor.o(($event) => $options.navgetTo("/pages_shop/store?liveId=" + $data.liveId + "&storeId=" + $data.storeId)),
  303. w: common_assets._imports_3$1,
  304. x: common_vendor.p({
  305. size: "small",
  306. text: $data.cartCount,
  307. absolute: "rightTop",
  308. type: "error"
  309. }),
  310. y: common_vendor.o(($event) => $options.navgetTo("./cart")),
  311. z: common_vendor.o(($event) => $options.addCart("cart")),
  312. A: common_vendor.t($data.buyText),
  313. B: common_vendor.o(($event) => $options.addCart("buy")),
  314. C: ((_d = $data.goosDetail) == null ? void 0 : _d.imgUrl) || _ctx.$img.img,
  315. D: common_vendor.t($data.goosDetail.productName),
  316. E: common_vendor.t($data.goosDetail.price ? $data.goosDetail.price.toFixed(2) : "0.00"),
  317. F: common_vendor.t($data.goosDetail.sales),
  318. G: common_vendor.f($data.storePriceList, (item, index, i0) => {
  319. return {
  320. a: common_vendor.t(item.price.toFixed(2)),
  321. b: common_vendor.t(_ctx.utils.formatSalesNum(item.sales)),
  322. c: common_vendor.t(item.storeName),
  323. d: "14e5f6c8-3-" + i0 + ",14e5f6c8-2",
  324. e: index,
  325. f: common_vendor.n(_ctx.productValueSelect.storeId == item.storeId ? "item hover" : "item"),
  326. g: common_vendor.o(($event) => _ctx.pickerStore(item, index), index)
  327. };
  328. }),
  329. H: common_vendor.p({
  330. name: "arrow-right",
  331. color: "#000",
  332. size: "14"
  333. }),
  334. I: common_vendor.p({
  335. show: $data.showStorePicker,
  336. round: 16,
  337. mode: "bottom"
  338. }),
  339. J: common_vendor.o($options.goodsNumChange),
  340. K: common_vendor.o(($event) => $data.goodsNum = $event),
  341. L: common_vendor.p({
  342. bgColor: "#ececec",
  343. modelValue: $data.goodsNum
  344. }),
  345. M: common_vendor.o((...args) => $options.submit && $options.submit(...args)),
  346. N: common_vendor.sr("popup", "14e5f6c8-1"),
  347. O: common_vendor.p({
  348. visible: $data.specVisible,
  349. title: " ",
  350. radius: "32",
  351. maxHeight: "800"
  352. })
  353. });
  354. }
  355. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  356. wx.createPage(MiniProgramPage);