goods.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. <template>
  2. <div class="main-page">
  3. <!-- #ifdef APP-PLUS -->
  4. <view class="status_bar"></view>
  5. <!-- #endif -->
  6. <!-- 仅h5有效 打开App -->
  7. <!-- 分享 -->
  8. <shares v-if="shareFlage && goodsDetail.id" :skuId="this.routerVal.id" :goodsId="this.routerVal.goodsId" :link="'/pages/product/goods?id='+this.routerVal.id+'&goodsId='+this.routerVal.goodsId"
  9. :thumbnail="goodsDetail.thumbnail" :goodsName="goodsDetail.goodsName" type="goods" @close="shareFlage = false" />
  10. <view class="index">
  11. <u-navbar :background="navbar" :is-back="false" :class="headerFlag ? 'header' : 'header bg-none scoll-hide'">
  12. <div class="headerRow">
  13. <div class="backs" @click="back()">
  14. <u-icon name="arrow-left" color="#8e8e8e"></u-icon>
  15. </div>
  16. <div class="headerList" :class="headerFlag ? 'tab-bar' : 'tab-bar scoll-hide'">
  17. <div class="headerRow">
  18. <div style="text-align: center" :span="3" v-for="header in headerList" :key="header.id" :class="{ cur: scrollId === header.id }" @click="headerTab(header.id)">
  19. {{ header.text }}
  20. </div>
  21. </div>
  22. </div>
  23. <div class="share" @click="shareChange()">
  24. <image class="shareImg" src="/static/share.png" alt=""></image>
  25. </div>
  26. </div>
  27. </u-navbar>
  28. <view class="showBack" v-show="!headerFlag">
  29. <u-row>
  30. <u-col :span="2" @click="back()">
  31. <div class="iconBag" style="text-align: center">
  32. <image class="headerImg" src="/static/bagBack.png" alt=""></image>
  33. </div>
  34. </u-col>
  35. <u-col :span="8"></u-col>
  36. <u-col :span="2" class="share" style="text-align: center" @click="shareChange()">
  37. <image class="headerImg" src="/static/bagShare.png" alt=""></image>
  38. </u-col>
  39. </u-row>
  40. </view>
  41. </view>
  42. <view class="product-container" :style="{ height: productRefHeight }" ref="productRef" id="productRef">
  43. <scroll-view scroll-anchoring enableBackToTop="true" scroll-with-animation scroll-y class="scoll-page" :scroll-top="tabScrollTop" @scroll="pageScroll">
  44. <view>
  45. <!-- 轮播图 -->
  46. <GoodsSwiper id="main1" :res="imgList" />
  47. <!-- 促销活动条 -->
  48. <PromotionAssembleLayout v-if="PromotionList" :detail="goodsDetail" :res="PromotionList" />
  49. <view class="card-box top-radius-0" id="main2">
  50. <!-- 活动不显示价钱 -->
  51. <view v-if="!is_promotion" class="desc-blod -goods-msg">
  52. <view class="-goods-flex">
  53. <view class="desc-blod">
  54. {{ goodsDetail.goodsName || "" }}
  55. </view>
  56. <view class="favorite" @click="clickFavorite(goodsDetail.id)">
  57. <u-icon size="30" :color="favorite ? '#f2270c' : '#262626'" :name="favorite ? 'heart-fill' : 'heart'"></u-icon>
  58. <view :style="{ color: favorite ? '#f2270c' : '#262626' }">{{ favorite ? "已收藏" : "收藏" }}</view>
  59. </view>
  60. </view>
  61. <!-- 商品描述 -->
  62. <view class="-goods-desc">
  63. {{ goodsDetail.sellingPoint || '' }}
  64. </view>
  65. </view>
  66. <view v-else class="-goods-msg">
  67. <!-- 没有拼团,秒杀等活动的情况下 -->
  68. <view>
  69. <view class="-goods-flex">
  70. <!-- 如果有积分显示积分 -->
  71. <view class="-goods-price" v-if="goodsDetail.price != undefined">
  72. <span v-if="pointDetail.points"> <span class="price">{{pointDetail.points}}</span>
  73. <span>积分</span>
  74. </span>
  75. <span v-else> <span>¥</span><span class="price">{{ formatPrice(goodsDetail.price)[0] }}</span>.{{
  76. formatPrice(goodsDetail.price)[1]
  77. }} </span>
  78. </view>
  79. <view class="-goods-price" v-else> ¥<span class="price">0 </span>.00 </view>
  80. <view class="favorite" @click="clickFavorite(goodsDetail.id)">
  81. <u-icon size="30" :color="favorite ? '#f2270c' : '#262626'" :name="favorite ? 'heart-fill' : 'heart'"></u-icon>
  82. <view :style="{ color: favorite ? '#f2270c' : '#262626' }">{{ favorite ? "已收藏" : "收藏" }}</view>
  83. </view>
  84. </view>
  85. <view class="-goods-name desc-blod">
  86. {{ goodsDetail.goodsName || "" }}
  87. </view>
  88. <view class="-goods-desc">
  89. {{ goodsDetail.sellingPoint || '' }}
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. <view class="card-box">
  95. <view class="card-flex" @click="shutMask(1)">
  96. <view class="card-title"> 促销 </view>
  97. <view class="card-content">
  98. <span v-if="PromotionList && emptyPromotion()">暂无促销信息</span>
  99. <PromotionLayout v-else @shutMasks="shutMask" :res="PromotionList" />
  100. </view>
  101. <view class="card-bottom">
  102. <u-icon name="more-dot-fill"></u-icon>
  103. </view>
  104. </view>
  105. </view>
  106. <!-- 拼团用户列表 -->
  107. <PromotionAssembleListLayout v-if="isGroup" @to-assemble-buy-now="toAssembleBuyNow" :res="PromotionList" />
  108. <view class="card-box">
  109. <view class="card-flex" @click="shutMask(4)">
  110. <view class="card-title"> 已选 </view>
  111. <view class="card-content">
  112. <span v-if="selectedGoods.spec">{{ selectedGoods.spec.specName }}-{{
  113. selectedGoods.spec.specValue
  114. }}</span>
  115. <span v-else>默认</span>
  116. </view>
  117. <view class="card-bottom">
  118. <u-icon name="more-dot-fill"></u-icon>
  119. </view>
  120. </view>
  121. <view class="card-flex" @click="shutMask(3)">
  122. <view class="card-title"> 送至 </view>
  123. <view class="card-content">
  124. <span v-if="delivery">{{
  125. delivery.consigneeAddressPath | clearStrComma
  126. }}</span>
  127. <span v-else>暂无地址信息</span>
  128. </view>
  129. <view class="card-bottom">
  130. <u-icon name="more-dot-fill"></u-icon>
  131. </view>
  132. </view>
  133. </view>
  134. <!-- 评价 -->
  135. <Evaluation id="main5" :goodsDetail="goodsDetail" />
  136. <!-- 店铺推荐 -->
  137. <storeLayout id="main7" :storeDetail="storeDetail" :goodsDetail="goodsDetail" :res="recommendList" />
  138. <!-- 宝贝详情 -->
  139. <GoodsIntro id="main9" :res="goodsDetail" :goodsId="goodsDetail.goodsId" v-if="goodsDetail.id" />
  140. <!-- 宝贝推荐 -->
  141. <GoodsRecommend id="main11" :res="likeGoodsList" />
  142. </view>
  143. </scroll-view>
  144. <view class="page-bottom mp-iphonex-bottom" id="pageBottom">
  145. <view class="icon-btn">
  146. <view class="icon-btn-item" @click="navigateToStore(goodsDetail.storeId)">
  147. <u-icon size="34" class="red" name="home-fill"></u-icon>
  148. <view class="red icon-btn-name">店铺</view>
  149. </view>
  150. <!-- <view class="icon-btn-item" @click="linkMsgDetail()">
  151. <u-icon size="34" name="kefu-ermai"></u-icon>
  152. <view class="icon-btn-name">客服</view>
  153. </view> -->
  154. <view class="icon-btn-item" @click="reluchToCart()">
  155. <u-icon size="34" name="storeping-cart"></u-icon>
  156. <view class="icon-btn-name">购物车</view>
  157. <view v-if="nums && nums > 0" class="num-icon">{{ nums }}</view>
  158. </view>
  159. </view>
  160. <!-- 正常结算页面 -->
  161. <view class="detail-btn" v-if="!isGroup">
  162. <view class="to-store-car to-store-btn" @click="shutMask(4)">加入购物车</view>
  163. <view class="to-buy to-store-btn" @click="shutMask(4, 'buy')">立即购买</view>
  164. <view class="to-store-car to-store-btn" v-if="startTimer">暂未开始</view>
  165. </view>
  166. <!-- 拼团结算 -->
  167. <view class="detail-btn" v-else>
  168. <view class="to-store-car pt-buy to-store-btn" @click="shutMask(4, 'buy')">
  169. <view>¥{{ goodsDetail.price | unitPrice }}</view>
  170. <view>单独购买</view>
  171. </view>
  172. <view class="to-buy pt-buy to-store-btn" @click="toAssembleBuyNow">
  173. <view>¥{{ goodsDetail.promotionPrice | unitPrice }}</view>
  174. <view>拼团价格</view>
  175. </view>
  176. </view>
  177. </view>
  178. <!-- 规格-模态层弹窗 -->
  179. <view class="popup spec" @click="shutMask(false)" v-show="maskFlag">
  180. <!-- 促销弹窗 -->
  181. <view class="cuxiao mask" v-show="cuxiao">
  182. <view ref="mask_title" class="title mask_title">
  183. 优惠
  184. <span @click="shutMask(false)">×</span>
  185. </view>
  186. <scroll-view class="scroll_mask" :scroll-y="true">
  187. <view class="con-cuxiao">
  188. <text>促销活动</text>
  189. <PromotionDetailsLayout :res="PromotionList" />
  190. </view>
  191. <view class="con-cuxiao coupons">
  192. <text>可领优惠券</text>
  193. <PromotionCoupon @getCoupon="getCoupon" :res="PromotionList" />
  194. </view>
  195. </scroll-view>
  196. </view>
  197. <!-- 配送地址弹窗 -->
  198. <popupAddress @closeAddress="closePopupAddress" @deliveryData="deliveryFun" v-if="goodsDetail.id" :goodsId="goodsDetail.id" :addressFlag="addressFlag" />
  199. <!-- 商品规格 商品详情,以及默认参与活动的id-->
  200. <popupGoods :addr="delivery" ref="popupGoods" @changed="changedGoods" @closeBuy="closePopupBuy" @queryCart="cartCount()" :goodsDetail="goodsDetail" :goodsSpec="goodsSpec" :id="productId"
  201. v-if="goodsDetail.id " :pointDetail="pointDetail" @handleClickSku="init" :buyMask="buyMask" />
  202. </view>
  203. </view>
  204. </div>
  205. </template>
  206. <script>
  207. /************接口API***************/
  208. import {
  209. getGoods,
  210. getGoodsList,
  211. getMpScene,
  212. getGoodsDistribution,
  213. } from "@/api/goods.js";
  214. import * as API_trade from "@/api/trade.js";
  215. import * as API_Members from "@/api/members.js";
  216. import * as API_store from "@/api/store.js";
  217. /************请求存储***************/
  218. import storage from "@/utils/storage.js";
  219. /************组件***************/
  220. import PromotionLayout from "./product/promotion/-promotion"; //促销组件
  221. import PromotionDetailsLayout from "./product/promotion/-promotion-details"; //促销活动详情
  222. import PromotionAssembleLayout from "./product/promotion/-promotion-assemble-promotions"; //促销活动条
  223. import PromotionAssembleListLayout from "./product/promotion/-promotion-assemble-list"; //拼团用户列表
  224. import PromotionCoupon from "./product/promotion/-promotion-coupon"; //优惠券组件
  225. import GoodsIntro from "./product/goods/-goods-intro"; //商品介绍组件
  226. import GoodsRecommend from "./product/goods/-goods-recommend"; //宝贝推荐
  227. import storeLayout from "./product/shop/-shop"; //店铺组件
  228. import Evaluation from "./product/evaluation/-evaluation"; //评价组件
  229. import GoodsSwiper from "./product/goods/-goods-swiper"; //轮播图组件
  230. import popupGoods from "./product/popup/goods"; //购物车商品的模块
  231. import popupAddress from "./product/popup/address"; //地址选择模块
  232. import shares from "@/components/m-share/index"; //分享
  233. export default {
  234. components: {
  235. shares,
  236. PromotionLayout,
  237. PromotionDetailsLayout,
  238. PromotionAssembleLayout,
  239. PromotionAssembleListLayout,
  240. PromotionCoupon,
  241. GoodsIntro,
  242. GoodsRecommend,
  243. storeLayout,
  244. Evaluation,
  245. GoodsSwiper,
  246. popupGoods,
  247. popupAddress,
  248. },
  249. data() {
  250. return {
  251. shareFlage: false,
  252. selectedGoods: "", //选择的商品规格昵称
  253. is_promotion: true, //判断显示拼团活动文字
  254. isGroup: false, // 是否是拼团活动
  255. pointDetail: "", // 是否是积分商品
  256. assemble: "", //拼团的sku
  257. scroll_mask_height: 0, //促销活动的高度
  258. navbar: {
  259. background: "#fff",
  260. },
  261. productRefHeight: "",
  262. header: {
  263. top: 0,
  264. height: 50,
  265. },
  266. headerFlag: false, //顶部导航显示与否
  267. headerList: [
  268. //顶部导航文字
  269. {
  270. text: "商品",
  271. id: "1",
  272. },
  273. {
  274. text: "评价",
  275. id: "2",
  276. },
  277. {
  278. text: "详情",
  279. id: "3",
  280. },
  281. {
  282. text: "推荐",
  283. id: "4",
  284. },
  285. ],
  286. oldtabScrollTop: 0,
  287. tabScrollTop: null,
  288. scrollArr: [],
  289. scrollId: "1",
  290. scrollFlag: true,
  291. current: "1", //当前显示的轮播图页
  292. goodsDetail: {}, //商品数据
  293. goodsSpec: "", //规格数据
  294. imgList: [], //轮播图数据
  295. favorite: false, //收藏与否flag
  296. recommendList: [], //推荐列表
  297. maskFlag: false, //模态显示与否
  298. cuxiao: false, //促销弹窗
  299. goodsInfo: false, //商品介绍弹窗
  300. addressFlag: false, //配送地址弹窗
  301. buyMask: false, //添加购物车直接购买,查看已选 弹窗
  302. num: 1, //添加到购物车的数量
  303. skuId: "", //
  304. storeDetail: "", //店铺基本信息,
  305. // 店铺信息
  306. storeParams: {
  307. pageNumber: 1,
  308. pageSize: 10,
  309. },
  310. likeGoodsList: "", //相似商品列表
  311. PromotionList: "", //活动,促销,列表
  312. specList: [],
  313. skusCombination: [],
  314. selectedSpec: [],
  315. nums: 0,
  316. delivery: "",
  317. exchange: {},
  318. productId: 0,
  319. startTimer: false, //未开启 是false
  320. routerVal: "",
  321. };
  322. },
  323. watch: {
  324. isGroup(val) {
  325. if (val) {
  326. let timer = setInterval(() => {
  327. this.$refs.popupGoods.buyType = "PINTUAN";
  328. clearInterval(timer);
  329. }, 100);
  330. this.is_promotion = false;
  331. } else {
  332. this.is_promotion = true;
  333. this.$refs.popupGoods.buyType = "";
  334. }
  335. },
  336. },
  337. mounted() {
  338. const { windowHeight } = uni.getSystemInfoSync();
  339. let bottomHeight = 0;
  340. let topHeight = 0;
  341. uni.getSystemInfo({
  342. success: function (res) {
  343. // res - 各种参数
  344. let bottom = uni.createSelectorQuery().select(".page-bottom");
  345. bottom
  346. .boundingClientRect(function (data) {
  347. if (data && data.height) {
  348. //data - 各种参数
  349. bottomHeight = data.height; // 获取元素宽度
  350. }
  351. })
  352. .exec();
  353. let top = uni.createSelectorQuery().select(".header");
  354. top
  355. .boundingClientRect(function (data) {
  356. if (data && data.height) {
  357. //data - 各种参数
  358. topHeight = data.height; // 获取元素宽度
  359. }
  360. })
  361. .exec();
  362. },
  363. });
  364. this.productRefHeight = windowHeight - bottomHeight + "px";
  365. },
  366. async onLoad(options) {
  367. this.routerVal = options;
  368. },
  369. async onShow() {
  370. this.goodsDetail = {};
  371. //如果有参数ids说明事分销短连接,需要获取参数
  372. if (this.routerVal.scene) {
  373. getMpScene(this.routerVal.scene).then((res) => {
  374. if (res.data.success) {
  375. let data = res.data.result.split(","); // skuId,goodsId,distributionId
  376. this.init(data[0], data[1], data[2]);
  377. }
  378. });
  379. } else {
  380. this.init(
  381. this.routerVal.id,
  382. this.routerVal.goodsId,
  383. this.routerVal.distributionId,
  384. this.routerVal.whetherPoint
  385. );
  386. }
  387. },
  388. methods: {
  389. // 循环出当前促销是否为空
  390. emptyPromotion() {
  391. if (
  392. this.PromotionList == "" ||
  393. this.PromotionList == null ||
  394. this.PromotionList == []
  395. ) {
  396. return true;
  397. }
  398. },
  399. /**初始化信息 */
  400. async init(id, goodsId, distributionId) {
  401. this.isGroup = false; //初始化拼团
  402. this.productId = id; // skuId
  403. // 这里请求获取到页面数据 解析数据
  404. uni.showLoading({
  405. title: "加载中",
  406. mask: true,
  407. });
  408. let response = await getGoods(id, goodsId);
  409. // 这里是绑定分销员
  410. if (distributionId || this.$store.state.distributionId) {
  411. let disResult = await getGoodsDistribution(distributionId);
  412. if (!disResult.data.success || disResult.statusCode == 403) {
  413. this.$store.state.distributionId = distributionId;
  414. }
  415. }
  416. uni.hideLoading();
  417. /**商品信息以及规格信息存储 */
  418. this.goodsDetail = response.data.result.data;
  419. this.goodsSpec = response.data.result.specs;
  420. this.PromotionList = response.data.result.promotionMap;
  421. // 判断是否拼团活动或者积分商品 如果有则显示拼团活动信息
  422. this.PromotionList &&
  423. Object.keys(this.PromotionList).forEach((item) => {
  424. // 拼团商品
  425. if (item.indexOf("PINTUAN") == 0) {
  426. this.isGroup = true;
  427. }
  428. // 积分
  429. if (item.indexOf("POINTS_GOODS") == 0) {
  430. this.pointDetail = this.PromotionList[item];
  431. }
  432. });
  433. // 轮播图
  434. this.imgList = this.goodsDetail.goodsGalleryList;
  435. // 获取店铺基本信息
  436. this.getstoreBaseInfoFun(this.goodsDetail.storeId);
  437. // 获取购物车
  438. this.cartCount();
  439. // 获取店铺推荐商品
  440. this.getstoreRecommend();
  441. // 获取商品列表
  442. this.getOtherLikeGoods();
  443. // 获取商品是否已被收藏 如果未登录不获取
  444. if (this.$options.filters.isLogin("auth")) {
  445. this.getGoodsCollectionFun(this.goodsDetail.id);
  446. }
  447. },
  448. linkMsgDetail () {
  449. uni.navigateTo({
  450. url: '/pages/product/customerservice/index'
  451. })
  452. },
  453. // 格式化金钱 1999 --> [1999,00]
  454. formatPrice(val) {
  455. if (typeof val == "undefined") {
  456. return val;
  457. }
  458. return val.toFixed(2).split(".");
  459. },
  460. /**选择商品 */
  461. changedGoods(val) {
  462. this.selectedGoods = val;
  463. },
  464. /** 点击子级地址回调参数*/
  465. deliveryFun(val) {
  466. this.delivery = val;
  467. },
  468. /**
  469. * 地址子级关闭回调
  470. */
  471. closePopupAddress(val) {
  472. this.addressFlag = val;
  473. this.maskFlag = false;
  474. },
  475. /**
  476. * 商品规格子级关闭回调
  477. */
  478. closePopupBuy(val) {
  479. this.buyMask = val;
  480. this.maskFlag = false;
  481. },
  482. /** 参与拼团 创建拼团 */
  483. toAssembleBuyNow(order) {
  484. this.shutMask(4, "PINTUAN", order);
  485. },
  486. /**
  487. * 查看购物车
  488. */
  489. reluchToCart() {
  490. let obj = {
  491. from: "product",
  492. id: this.productId,
  493. };
  494. storage.setCartBackbtn(obj);
  495. uni.switchTab({
  496. url: "/pages/tabbar/cart/cartList",
  497. });
  498. },
  499. /**
  500. * 查询购物车总数量
  501. */
  502. cartCount() {
  503. if (storage.getHasLogin()) {
  504. API_trade.getCartNum().then((res) => {
  505. this.nums = res.data.result;
  506. });
  507. }
  508. },
  509. /**
  510. * 返回
  511. */
  512. back() {
  513. if (getCurrentPages().length == 1) {
  514. uni.switchTab({
  515. url: "/pages/tabbar/home/index",
  516. });
  517. } else {
  518. uni.navigateBack();
  519. }
  520. },
  521. /**
  522. * 获取店铺信息
  523. */
  524. getstoreBaseInfoFun(id) {
  525. API_store.getstoreBaseInfo(id).then((res) => {
  526. if (res.data.success) {
  527. this.storeDetail = res.data.result;
  528. }
  529. });
  530. },
  531. /**
  532. * 删除收藏店铺
  533. */
  534. deleteGoodsCollectionFun(id) {
  535. API_Members.deleteGoodsCollection(id).then((res) => {
  536. if (res.statusCode == 200) {
  537. uni.showToast({
  538. title: "商品已取消收藏!",
  539. icon: "none",
  540. });
  541. this.favorite = !this.favorite;
  542. }
  543. });
  544. },
  545. /**
  546. * 获取商品是否已被收藏
  547. */
  548. getGoodsCollectionFun(goodsId) {
  549. if (storage.getHasLogin()) {
  550. API_Members.getGoodsIsCollect(goodsId, "GOODS").then((res) => {
  551. this.favorite = res.data.result;
  552. });
  553. }
  554. },
  555. /**
  556. * 获取店铺推荐商品列表
  557. */
  558. getstoreRecommend() {
  559. getGoodsList({
  560. pageNumber: 1,
  561. pageSize: 6,
  562. storeId: this.goodsDetail.storeId,
  563. recommend: true,
  564. }).then((res) => {
  565. this.recommendList = res.data.result.content;
  566. });
  567. },
  568. /**
  569. * 获取相似商品列表
  570. */
  571. getOtherLikeGoods() {
  572. getGoodsList({
  573. pageNumber: 1,
  574. pageSize: 10,
  575. category: this.goodsDetail.categoryId,
  576. keyword: this.goodsDetail.name,
  577. }).then((res) => {
  578. this.likeGoodsList = res.data.result.content;
  579. });
  580. },
  581. /**
  582. * 领取优惠券
  583. */
  584. receiveCouponsFun(id) {
  585. API_Members.receiveCoupons(id).then((res) => {
  586. uni.showToast({
  587. title: res.data.message,
  588. icon: "none",
  589. });
  590. });
  591. },
  592. /**
  593. * 跳转到店铺页面
  594. */
  595. navigateToStore(store_id) {
  596. uni.navigateTo({
  597. url: `/pages/product/shopPage?id=` + store_id,
  598. });
  599. },
  600. /**
  601. * 获取优惠券按钮
  602. */
  603. getCoupon(item) {
  604. this.receiveCouponsFun(item.id);
  605. },
  606. /**
  607. * 规格弹窗开关
  608. */
  609. shutMask(flag, buyFlag, type) {
  610. // type是指是否点击底部按钮
  611. if (flag) {
  612. switch (flag) {
  613. case 1: //优惠券弹窗
  614. this.maskFlag = true;
  615. this.cuxiao = true;
  616. break;
  617. case 3:
  618. this.maskFlag = true;
  619. this.addressFlag = true;
  620. break;
  621. case 4: //添加购物车直接购买,查看已选 弹窗
  622. // 判断是否是一个规格
  623. this.maskFlag = true;
  624. this.buyMask = true;
  625. if (buyFlag == "PINTUAN") {
  626. if (type.orderSn) {
  627. this.$refs.popupGoods.parentOrder = type;
  628. }
  629. this.$refs.popupGoods.buyType = "PINTUAN";
  630. }
  631. if (buyFlag == "buy") {
  632. this.$refs.popupGoods.buyType = "";
  633. }
  634. break;
  635. }
  636. } else {
  637. this.maskFlag = false;
  638. this.cuxiao = false;
  639. this.buyMask = false;
  640. }
  641. },
  642. /**
  643. * 收藏
  644. */
  645. clickFavorite(id) {
  646. if (this.favorite) {
  647. // 取消收藏
  648. this.deleteGoodsCollectionFun(id);
  649. return false;
  650. }
  651. API_Members.collectionGoods(id, "GOODS").then((res) => {
  652. if (res.data.success) {
  653. uni.showToast({
  654. title: "收藏成功!",
  655. icon: "none",
  656. });
  657. }
  658. });
  659. this.favorite = !this.favorite;
  660. },
  661. /**
  662. * 顶部header显示或隐藏
  663. */
  664. pageScroll(e) {
  665. if (this.scrollFlag) {
  666. this.calcSize();
  667. }
  668. if (e.detail.scrollTop > 200) {
  669. //当距离大于200时显示回到顶部按钮
  670. this.headerFlag = true;
  671. } else {
  672. //当距离小于200时隐藏回到顶部按钮
  673. this.headerFlag = false;
  674. }
  675. if (e.detail.scrollTop < this.scrollArr[0] - 10) {
  676. this.scrollId = "1";
  677. }
  678. if (e.detail.scrollTop > this.scrollArr[1] - 10) {
  679. this.scrollId = "2";
  680. }
  681. if (e.detail.scrollTop > this.scrollArr[2] - 10) {
  682. this.scrollId = "3";
  683. }
  684. if (e.detail.scrollTop > this.scrollArr[3] - 10) {
  685. this.scrollId = "4";
  686. }
  687. },
  688. /**
  689. * 计算每个要跳转到的模块高度信息
  690. */
  691. calcSize() {
  692. let h = 0;
  693. let that = this;
  694. let arr = [
  695. "main1",
  696. "main2",
  697. "main3",
  698. "main4",
  699. "main5",
  700. "main6",
  701. "main7",
  702. "main8",
  703. "main9",
  704. "main10",
  705. "main11",
  706. ];
  707. arr.forEach((item) => {
  708. let view = uni.createSelectorQuery().select("#" + item);
  709. view
  710. .fields(
  711. {
  712. size: true,
  713. },
  714. (data) => {
  715. if (
  716. item === "main1" ||
  717. item === "main5" ||
  718. item === "main9" ||
  719. item === "main11"
  720. ) {
  721. that.scrollArr.push(h);
  722. }
  723. if (data && data.height) {
  724. h += data.height;
  725. }
  726. }
  727. )
  728. .exec();
  729. });
  730. this.scrollFlag = false;
  731. },
  732. /**
  733. * 点击顶部跳转到对应位置
  734. */
  735. headerTab(id) {
  736. if (this.scrollFlag) {
  737. this.calcSize();
  738. }
  739. this.scrollId = id;
  740. this.$nextTick(() => {
  741. this.tabScrollTop = this.scrollArr[id - 1];
  742. });
  743. },
  744. /**
  745. * 点击分享
  746. */
  747. async shareChange() {
  748. this.shareFlage = true;
  749. },
  750. },
  751. };
  752. </script>
  753. <style lang="scss" scoped>
  754. // #ifdef MP-WEIXIN
  755. @import "./product/mp-goods.scss";
  756. // #endif
  757. @import "./product/style.scss";
  758. @import "./product/product.scss";
  759. </style>