goods.vue 30 KB

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