goods.js 11 KB

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