goods.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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. <popups v-model="popupsSwitch" @tapPopup="handleNavbarList" :popData="navbarListData" :x="navbarListX" :y="navbarListY" placement="top-start" />
  11. <view class="index">
  12. <!-- topBar -->
  13. <u-navbar :background="navbar" :is-back="false" :class="headerFlag ? 'header' : 'header bg-none scroll-hide'">
  14. <div class="headerRow">
  15. <div class="backs">
  16. <u-icon @click="back()" name="arrow-left" class="icon-back"></u-icon>
  17. <u-icon name="list" @click="popupsSwitch = !popupsSwitch" class="icon-list"></u-icon>
  18. </div>
  19. <div class="headerList" :class="headerFlag ? 'tab-bar' : 'tab-bar scroll-hide'">
  20. <div class="headerRow">
  21. <div class="nav-item" v-for="header in headerList" :key="header.id" :class="{ cur: scrollId === header.id }" @click="headerTab(header.id)">
  22. {{ header.text }}
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </u-navbar>
  28. <u-navbar :border-bottom="false" v-show="!headerFlag" class="header-only-back" :background="navbarOnlyBack" :is-back="false">
  29. <div>
  30. <div class="bg-back">
  31. <u-icon size="40" @click="back()" name="arrow-left" class="icon-back"></u-icon>
  32. <u-icon size="40" @click="popupsSwitch = !popupsSwitch" name="list" class="icon-list"></u-icon>
  33. </div>
  34. </div>
  35. </u-navbar>
  36. </view>
  37. <view class="product-container" :style="{ height: productRefHeight }" ref="productRef" id="productRef">
  38. <scroll-view scroll-anchoring enableBackToTop="true" scroll-with-animation scroll-y class="scroll-page" :scroll-top="tabScrollTop" @scroll="pageScroll">
  39. <view>
  40. <!-- 轮播图 -->
  41. <GoodsSwiper id="main1" :res="imgList" />
  42. <!-- 促销活动条 -->
  43. <PromotionAssembleLayout v-if="PromotionList" :detail="goodsDetail" :res="PromotionList" />
  44. <view class="card-box top-radius-0" id="main2">
  45. <!-- 活动不显示价钱 -->
  46. <view v-if="!isPromotion" class="desc-bold -goods-msg">
  47. <view class="-goods-flex">
  48. <view class="desc-bold">
  49. {{ goodsDetail.goodsName || "" }}
  50. </view>
  51. <view class="favorite" @click="clickFavorite(goodsDetail.id)">
  52. <u-icon size="30" :color="favorite ? '#f2270c' : '#262626'" :name="favorite ? 'heart-fill' : 'heart'"></u-icon>
  53. <view :style="{ color: favorite ? '#f2270c' : '#262626' }">{{ favorite ? "已收藏" : "收藏" }}</view>
  54. </view>
  55. </view>
  56. <!-- 商品描述 -->
  57. <view class="-goods-desc">
  58. {{ goodsDetail.sellingPoint || '' }}
  59. </view>
  60. </view>
  61. <view v-else class="-goods-msg">
  62. <!-- 没有拼团,秒杀等活动的情况下 -->
  63. <view>
  64. <view class="-goods-flex">
  65. <!-- 如果有积分显示积分 -->
  66. <view class="-goods-price" v-if="goodsDetail.price != undefined">
  67. <span v-if="pointDetail.points"> <span class="price">{{pointDetail.points}}</span>
  68. <span>积分</span>
  69. </span>
  70. <span v-else> <span>¥</span><span class="price">{{ formatPrice(goodsDetail.price)[0] }}</span>.{{
  71. formatPrice(goodsDetail.price)[1]
  72. }} </span>
  73. </view>
  74. <view class="-goods-price" v-else> ¥<span class="price">0 </span>.00 </view>
  75. <view class="icons share" @click="shareChange()">
  76. <u-icon size="30" name="share-fill"></u-icon>
  77. <view>分享</view>
  78. </view>
  79. <view class="icons" @click="clickFavorite(goodsDetail.id)">
  80. <u-icon size="30" :color="favorite ? '#f2270c' : '#262626'" :name="favorite ? 'heart-fill' : 'heart'"></u-icon>
  81. <view :style="{ color: favorite ? '#f2270c' : '#262626' }">{{ favorite ? "已收藏" : "收藏" }}</view>
  82. </view>
  83. </view>
  84. <view class="-goods-name desc-bold">
  85. {{ goodsDetail.goodsName || "" }}
  86. </view>
  87. <view class="-goods-desc">
  88. {{ goodsDetail.sellingPoint || '' }}
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. <view class="card-box">
  94. <view class="card-flex" @click="shutMask(1)">
  95. <view class="card-title"> 促销 </view>
  96. <view class="card-content">
  97. <span v-if="PromotionList && emptyPromotion()">暂无促销信息</span>
  98. <PromotionLayout v-else @shutMasks="shutMask" :res="PromotionList" />
  99. </view>
  100. <view class="card-bottom">
  101. <u-icon name="more-dot-fill"></u-icon>
  102. </view>
  103. </view>
  104. </view>
  105. <!-- 拼团用户列表 -->
  106. <PromotionAssembleListLayout v-if="isGroup" @to-assemble-buy-now="toAssembleBuyNow" :res="PromotionList" />
  107. <!-- 配置地址 如果是虚拟产品的时候不展示 -->
  108. <view class="card-box" v-if="goodsDetail.goodsType !='VIRTUAL_GOODS'">
  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" :goodsParams="goodsParams" :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" v-if="goodsDetail.goodsType!='VIRTUAL_GOODS'" @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="selectSku" :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. import { modelNavigateTo } from "@/pages/tabbar/home/template/tpl.js";
  218. /************请求存储***************/
  219. import storage from "@/utils/storage.js";
  220. /************组件***************/
  221. import PromotionLayout from "./product/promotion/-promotion"; //促销组件
  222. import PromotionDetailsLayout from "./product/promotion/-promotion-details"; //促销活动详情
  223. import PromotionAssembleLayout from "./product/promotion/-promotion-assemble-promotions"; //促销活动条
  224. import PromotionAssembleListLayout from "./product/promotion/-promotion-assemble-list"; //拼团用户列表
  225. import PromotionCoupon from "./product/promotion/-promotion-coupon"; //优惠券组件
  226. import GoodsIntro from "./product/goods/-goods-intro"; //商品介绍组件
  227. import GoodsRecommend from "./product/goods/-goods-recommend"; //宝贝推荐
  228. import storeLayout from "./product/shop/-shop"; //店铺组件
  229. import Evaluation from "./product/evaluation/-evaluation"; //评价组件
  230. import GoodsSwiper from "./product/goods/-goods-swiper"; //轮播图组件
  231. import popupGoods from "./product/popup/goods"; //购物车商品的模块
  232. import popupAddress from "./product/popup/address"; //地址选择模块
  233. import shares from "@/components/m-share/index"; //分享
  234. import popups from "@/components/popups/popups"; //气泡框
  235. export default {
  236. components: {
  237. popups,
  238. shares,
  239. PromotionLayout,
  240. PromotionDetailsLayout,
  241. PromotionAssembleLayout,
  242. PromotionAssembleListLayout,
  243. PromotionCoupon,
  244. GoodsIntro,
  245. GoodsRecommend,
  246. storeLayout,
  247. Evaluation,
  248. GoodsSwiper,
  249. popupGoods,
  250. popupAddress,
  251. },
  252. data() {
  253. return {
  254. // #ifdef H5
  255. navbarListX: 110, //导航栏列表栏x轴
  256. navbarListY: 80, //导航栏列表栏y轴
  257. // #endif
  258. // #ifdef MP-WEIXIN
  259. navbarListX: 100, //导航栏列表栏x轴
  260. navbarListY: 140, //导航栏列表栏y轴
  261. // #endif
  262. // #ifdef APP-PLUS
  263. navbarListX: 120, //导航栏列表栏x轴
  264. navbarListY: 170, //导航栏列表栏y轴
  265. // #endif
  266. navbarListData: [
  267. //导航栏列表栏数据
  268. {
  269. title: "首页",
  270. icon: "home-fill",
  271. ___type: "other",
  272. },
  273. {
  274. title: "购物车",
  275. icon: "bag-fill",
  276. ___type: "other",
  277. },
  278. {
  279. title: "搜索",
  280. icon: "search",
  281. ___type: "category",
  282. },
  283. {
  284. title: "个人中心",
  285. icon: "account-fill",
  286. ___type: "other",
  287. },
  288. ],
  289. popupsSwitch: false, //导航栏列表栏开关
  290. shareFlage: false,
  291. selectedGoods: "", //选择的商品规格昵称
  292. isPromotion: true, //判断显示拼团活动文字
  293. isGroup: false, // 是否是拼团活动
  294. pointDetail: "", // 是否是积分商品
  295. assemble: "", //拼团的sku
  296. navbarOnlyBack: {
  297. background: "transparent",
  298. },
  299. navbar: {
  300. background: "#fff",
  301. },
  302. productRefHeight: "",
  303. header: {
  304. top: 0,
  305. height: 50,
  306. },
  307. goodsParams: [], // 商品参数
  308. headerFlag: false, //顶部导航显示与否
  309. headerList: [
  310. //顶部导航文字按照规则来 详情全局搜索
  311. {
  312. text: "商品",
  313. id: "1",
  314. },
  315. {
  316. text: "评价",
  317. id: "2",
  318. },
  319. {
  320. text: "详情",
  321. id: "3",
  322. },
  323. {
  324. text: "推荐",
  325. id: "4",
  326. },
  327. ],
  328. oldtabScrollTop: 0,
  329. tabScrollTop: null,
  330. scrollArr: [],
  331. scrollId: "1",
  332. scrollFlag: true,
  333. current: "1", //当前显示的轮播图页
  334. goodsDetail: {}, //商品数据
  335. goodsSpec: "", //规格数据
  336. imgList: [], //轮播图数据
  337. favorite: false, //收藏与否flag
  338. recommendList: [], //推荐列表
  339. maskFlag: false, //模态显示与否
  340. cuxiao: false, //促销弹窗
  341. goodsInfo: false, //商品介绍弹窗
  342. addressFlag: false, //配送地址弹窗
  343. buyMask: false, //添加购物车直接购买,查看已选 弹窗
  344. num: 1, //添加到购物车的数量
  345. skuId: "", //
  346. storeDetail: "", //店铺基本信息,
  347. // 店铺信息
  348. storeParams: {
  349. pageNumber: 1,
  350. pageSize: 10,
  351. },
  352. likeGoodsList: "", //相似商品列表
  353. PromotionList: "", //活动,促销,列表
  354. specList: [],
  355. skusCombination: [],
  356. selectedSpec: [],
  357. nums: 0,
  358. delivery: "",
  359. exchange: {},
  360. productId: 0,
  361. startTimer: false, //未开启 是false
  362. routerVal: "",
  363. };
  364. },
  365. // #ifdef MP-WEIXNI
  366. shareAppMessage() {
  367. return {
  368. title: this.goodsDetail.goodsName,
  369. type: 0,
  370. query:`id=${this.routerVal.id}&goodsId=${this.routerVal.goodsId}`,
  371. path: `/pages/product/goods`,
  372. imageUrl:this.goodsDetail.goodsGalleryList[0],
  373. };
  374. },
  375. // #endif
  376. watch: {
  377. isGroup(val) {
  378. if (val) {
  379. let timer = setInterval(() => {
  380. this.$refs.popupGoods.buyType = "PINTUAN";
  381. clearInterval(timer);
  382. }, 100);
  383. this.isPromotion = false;
  384. } else {
  385. this.isPromotion = true;
  386. this.$refs.popupGoods.buyType = "";
  387. }
  388. },
  389. },
  390. mounted() {
  391. const { windowHeight } = uni.getSystemInfoSync();
  392. let bottomHeight = 0;
  393. let topHeight = 0;
  394. uni.getSystemInfo({
  395. success: function (res) {
  396. // res - 各种参数
  397. let bottom = uni.createSelectorQuery().select(".page-bottom");
  398. bottom
  399. .boundingClientRect(function (data) {
  400. if (data && data.height) {
  401. //data - 各种参数
  402. bottomHeight = data.height; // 获取元素宽度
  403. }
  404. })
  405. .exec();
  406. let top = uni.createSelectorQuery().select(".header");
  407. top
  408. .boundingClientRect(function (data) {
  409. if (data && data.height) {
  410. //data - 各种参数
  411. topHeight = data.height; // 获取元素宽度
  412. }
  413. })
  414. .exec();
  415. },
  416. });
  417. this.productRefHeight = windowHeight - bottomHeight + "px";
  418. },
  419. async onLoad(options) {
  420. this.routerVal = options;
  421. // #ifdef MP-WEIXIN
  422. // 小程序默认分享
  423. uni.showShareMenu({
  424. withShareTicket: true,
  425. menus: ["shareAppMessage", "shareTimeline"],
  426. });
  427. // #endif
  428. },
  429. async onShow() {
  430. this.goodsDetail = {};
  431. //如果有参数ids说明事分销短连接,需要获取参数
  432. if (this.routerVal.scene) {
  433. getMpScene(this.routerVal.scene).then((res) => {
  434. if (res.data.success) {
  435. let data = res.data.result.split(","); // skuId,goodsId,distributionId
  436. this.init(data[0], data[1], data[2]);
  437. }
  438. });
  439. } else {
  440. this.init(
  441. this.routerVal.id,
  442. this.routerVal.goodsId,
  443. this.routerVal.distributionId,
  444. this.routerVal.whetherPoint
  445. );
  446. }
  447. },
  448. methods: {
  449. /**
  450. * 导航栏列表栏
  451. */
  452. handleNavbarList(val) {
  453. modelNavigateTo({ url: val });
  454. },
  455. /**
  456. * 循环出当前促销是否为空
  457. */
  458. emptyPromotion() {
  459. if (
  460. this.PromotionList == "" ||
  461. this.PromotionList == null ||
  462. this.PromotionList == []
  463. ) {
  464. return true;
  465. }
  466. },
  467. selectSku (idObj) { // 选择sku的回调
  468. this.init(idObj.skuId,idObj.goodsId)
  469. },
  470. /**
  471. * 初始化信息
  472. */
  473. async init(id, goodsId, distributionId) {
  474. this.isGroup = false; //初始化拼团
  475. this.productId = id; // skuId
  476. // 这里请求获取到页面数据 解析数据
  477. uni.showLoading({
  478. title: "加载中",
  479. mask: true,
  480. });
  481. let response = await getGoods(id, goodsId);
  482. if (!response.data.success) {
  483. uni.navigateBack();
  484. return false;
  485. }
  486. // 这里是绑定分销员
  487. if (distributionId || this.$store.state.distributionId) {
  488. let disResult = await getGoodsDistribution(distributionId);
  489. if (!disResult.data.success || disResult.statusCode == 403) {
  490. this.$store.state.distributionId = distributionId;
  491. }
  492. }
  493. uni.hideLoading();
  494. /**商品信息以及规格信息存储 */
  495. this.goodsDetail = response.data.result.data;
  496. this.goodsSpec = response.data.result.specs;
  497. this.PromotionList = response.data.result.promotionMap;
  498. this.goodsParams = response.data.result.goodsParamsDTOList || []
  499. // 判断是否拼团活动或者积分商品 如果有则显示拼团活动信息
  500. this.PromotionList &&
  501. Object.keys(this.PromotionList).forEach((item) => {
  502. // 拼团商品
  503. if (item.indexOf("PINTUAN") == 0) {
  504. this.isGroup = true;
  505. }
  506. // 积分
  507. if (item.indexOf("POINTS_GOODS") == 0) {
  508. this.pointDetail = this.PromotionList[item];
  509. }
  510. });
  511. // 轮播图
  512. this.imgList = this.goodsDetail.goodsGalleryList;
  513. // 获取店铺基本信息
  514. this.getstoreBaseInfoFun(this.goodsDetail.storeId);
  515. // 获取购物车
  516. this.cartCount();
  517. // 获取店铺推荐商品
  518. this.getstoreRecommend();
  519. // 获取商品列表
  520. this.getOtherLikeGoods();
  521. // 获取商品是否已被收藏 如果未登录不获取
  522. if (this.$options.filters.isLogin("auth")) {
  523. this.getGoodsCollectionFun(this.goodsDetail.id);
  524. }
  525. },
  526. linkMsgDetail() {
  527. // 客服
  528. // #ifdef MP-WEIXIN
  529. const params = {
  530. storeName: this.storeDetail.storeName,
  531. goodsName: this.goodsDetail.goodsName,
  532. goodsId: this.goodsDetail.goodsId,
  533. goodsImg: this.goodsDetail.thumbnail,
  534. price: this.goodsDetail.promotionPrice || this.goodsDetail.price,
  535. // originalPrice: this.goodsDetail.original || this.goodsDetail.price,
  536. uuid: storage.getUuid(),
  537. token: storage.getAccessToken(),
  538. sign: this.storeDetail.yzfSign,
  539. mpSign: this.storeDetail.yzfMpSign,
  540. };
  541. uni.navigateTo({
  542. url:
  543. "/pages/product/customerservice/index?params=" +
  544. encodeURIComponent(JSON.stringify(params)),
  545. });
  546. // #endif
  547. // #ifndef MP-WEIXIN
  548. const sign = this.storeDetail.yzfSign;
  549. uni.navigateTo({
  550. url:
  551. "/pages/tabbar/home/web-view?src=https://yzf.qq.com/xv/web/static/chat/index.html?sign=" +
  552. sign,
  553. });
  554. // #endif
  555. },
  556. // 格式化金钱 1999 --> [1999,00]
  557. formatPrice(val) {
  558. if (typeof val == "undefined") {
  559. return val;
  560. }
  561. return val.toFixed(2).split(".");
  562. },
  563. /**选择商品 */
  564. changedGoods(val) {
  565. this.selectedGoods = val;
  566. },
  567. /** 点击子级地址回调参数*/
  568. deliveryFun(val) {
  569. this.delivery = val;
  570. },
  571. /**
  572. * 地址子级关闭回调
  573. */
  574. closePopupAddress(val) {
  575. this.addressFlag = val;
  576. this.maskFlag = false;
  577. },
  578. /**
  579. * 商品规格子级关闭回调
  580. */
  581. closePopupBuy(val) {
  582. this.buyMask = val;
  583. this.maskFlag = false;
  584. },
  585. /** 参与拼团 创建拼团 */
  586. toAssembleBuyNow(order) {
  587. this.shutMask(4, "PINTUAN", order);
  588. },
  589. /**
  590. * 查看购物车
  591. */
  592. reluchToCart() {
  593. let obj = {
  594. from: "product",
  595. id: this.productId,
  596. };
  597. storage.setCartBackbtn(obj);
  598. uni.switchTab({
  599. url: "/pages/tabbar/cart/cartList",
  600. });
  601. },
  602. /**
  603. * 查询购物车总数量
  604. */
  605. cartCount() {
  606. if (storage.getHasLogin()) {
  607. API_trade.getCartNum().then((res) => {
  608. this.nums = res.data.result;
  609. });
  610. }
  611. },
  612. /**
  613. * 返回
  614. */
  615. back() {
  616. if (getCurrentPages().length == 1) {
  617. uni.switchTab({
  618. url: "/pages/tabbar/home/index",
  619. });
  620. } else {
  621. uni.navigateBack();
  622. }
  623. },
  624. /**
  625. * 获取店铺信息
  626. */
  627. getstoreBaseInfoFun(id) {
  628. API_store.getstoreBaseInfo(id).then((res) => {
  629. if (res.data.success) {
  630. this.storeDetail = res.data.result;
  631. }
  632. });
  633. },
  634. /**
  635. * 删除收藏店铺
  636. */
  637. deleteGoodsCollectionFun(id) {
  638. API_Members.deleteGoodsCollection(id).then((res) => {
  639. if (res.statusCode == 200) {
  640. uni.showToast({
  641. title: "商品已取消收藏!",
  642. icon: "none",
  643. });
  644. this.favorite = !this.favorite;
  645. }
  646. });
  647. },
  648. /**
  649. * 获取商品是否已被收藏
  650. */
  651. getGoodsCollectionFun(goodsId) {
  652. if (storage.getHasLogin()) {
  653. API_Members.getGoodsIsCollect(goodsId, "GOODS").then((res) => {
  654. this.favorite = res.data.result;
  655. });
  656. }
  657. },
  658. /**
  659. * 获取店铺推荐商品列表
  660. */
  661. getstoreRecommend() {
  662. getGoodsList({
  663. pageNumber: 1,
  664. pageSize: 6,
  665. storeId: this.goodsDetail.storeId,
  666. recommend: true,
  667. }).then((res) => {
  668. this.recommendList = res.data.result.content;
  669. });
  670. },
  671. /**
  672. * 获取相似商品列表
  673. */
  674. getOtherLikeGoods() {
  675. getGoodsList({
  676. pageNumber: 1,
  677. pageSize: 10,
  678. category: this.goodsDetail.categoryId,
  679. keyword: this.goodsDetail.name,
  680. }).then((res) => {
  681. this.likeGoodsList = res.data.result.content;
  682. console.warn(this.likeGoodsList);
  683. });
  684. },
  685. /**
  686. * 领取优惠券
  687. */
  688. receiveCouponsFun(id) {
  689. API_Members.receiveCoupons(id).then((res) => {
  690. uni.showToast({
  691. title: res.data.message,
  692. icon: "none",
  693. });
  694. });
  695. },
  696. /**
  697. * 跳转到店铺页面
  698. */
  699. navigateToStore(store_id) {
  700. uni.navigateTo({
  701. url: `/pages/product/shopPage?id=` + store_id,
  702. });
  703. },
  704. /**
  705. * 获取优惠券按钮
  706. */
  707. getCoupon(item) {
  708. this.receiveCouponsFun(item.id);
  709. },
  710. /**
  711. * 规格弹窗开关
  712. */
  713. shutMask(flag, buyFlag, type) {
  714. // type是指是否点击底部按钮
  715. if (flag) {
  716. switch (flag) {
  717. case 1: //优惠券弹窗
  718. this.maskFlag = true;
  719. this.cuxiao = true;
  720. break;
  721. case 3:
  722. this.maskFlag = true;
  723. this.addressFlag = true;
  724. break;
  725. case 4: //添加购物车直接购买,查看已选 弹窗
  726. // 判断是否是一个规格
  727. this.maskFlag = true;
  728. this.buyMask = true;
  729. if (buyFlag == "PINTUAN") {
  730. if (type.orderSn) {
  731. this.$refs.popupGoods.parentOrder = type;
  732. }
  733. this.$refs.popupGoods.buyType = "PINTUAN";
  734. }
  735. if (buyFlag == "buy") {
  736. this.$refs.popupGoods.buyType = "";
  737. }
  738. break;
  739. }
  740. } else {
  741. this.maskFlag = false;
  742. this.cuxiao = false;
  743. this.buyMask = false;
  744. }
  745. },
  746. /**
  747. * 收藏
  748. */
  749. clickFavorite(id) {
  750. if (this.favorite) {
  751. // 取消收藏
  752. this.deleteGoodsCollectionFun(id);
  753. return false;
  754. }
  755. API_Members.collectionGoods(id, "GOODS").then((res) => {
  756. if (res.data.success) {
  757. uni.showToast({
  758. title: "收藏成功!",
  759. icon: "none",
  760. });
  761. }
  762. });
  763. this.favorite = !this.favorite;
  764. },
  765. /**
  766. * 顶部header显示或隐藏
  767. */
  768. pageScroll(e) {
  769. if (this.scrollFlag) {
  770. this.calcSize();
  771. }
  772. if (e.detail.scrollTop > 200) {
  773. //当距离大于200时显示回到顶部按钮
  774. this.headerFlag = true;
  775. } else {
  776. //当距离小于200时隐藏回到顶部按钮
  777. this.headerFlag = false;
  778. }
  779. if (e.detail.scrollTop < this.scrollArr[0] - 10) {
  780. this.scrollId = "1";
  781. }
  782. if (e.detail.scrollTop > this.scrollArr[1] - 10) {
  783. this.scrollId = "2";
  784. }
  785. if (e.detail.scrollTop > this.scrollArr[2] - 10) {
  786. this.scrollId = "3";
  787. }
  788. if (e.detail.scrollTop > this.scrollArr[3] - 10) {
  789. this.scrollId = "4";
  790. }
  791. },
  792. /**
  793. * 计算每个要跳转到的模块高度信息
  794. */
  795. calcSize() {
  796. let h = 0;
  797. let that = this;
  798. let arr = [
  799. "main1",
  800. "main2",
  801. "main3",
  802. "main4",
  803. "main5",
  804. "main6",
  805. "main7",
  806. "main8",
  807. "main9",
  808. "main10",
  809. "main11",
  810. ];
  811. arr.forEach((item) => {
  812. let view = uni.createSelectorQuery().select("#" + item);
  813. view
  814. .fields(
  815. {
  816. size: true,
  817. },
  818. (data) => {
  819. if (
  820. item === "main1" ||
  821. item === "main5" ||
  822. item === "main9" ||
  823. item === "main11"
  824. ) {
  825. that.scrollArr.push(h);
  826. }
  827. if (data && data.height) {
  828. h += data.height;
  829. }
  830. }
  831. )
  832. .exec();
  833. });
  834. this.scrollFlag = false;
  835. },
  836. /**
  837. * 点击顶部跳转到对应位置
  838. */
  839. headerTab(id) {
  840. if (this.scrollFlag) {
  841. this.calcSize();
  842. }
  843. this.scrollId = id;
  844. this.$nextTick(() => {
  845. this.tabScrollTop = this.scrollArr[id - 1];
  846. });
  847. },
  848. /**
  849. * 点击分享
  850. */
  851. async shareChange() {
  852. this.shareFlage = true;
  853. },
  854. },
  855. };
  856. </script>
  857. <style lang="scss" scoped>
  858. // #ifdef MP-WEIXIN
  859. @import "./product/mp-goods.scss";
  860. // #endif
  861. @import "./product/style.scss";
  862. @import "./product/product.scss";
  863. </style>