goods.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  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" :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. headerFlag: false, //顶部导航显示与否
  308. headerList: [
  309. //顶部导航文字按照规则来 详情全局搜索
  310. {
  311. text: "商品",
  312. id: "1",
  313. },
  314. {
  315. text: "评价",
  316. id: "2",
  317. },
  318. {
  319. text: "详情",
  320. id: "3",
  321. },
  322. {
  323. text: "推荐",
  324. id: "4",
  325. },
  326. ],
  327. oldtabScrollTop: 0,
  328. tabScrollTop: null,
  329. scrollArr: [],
  330. scrollId: "1",
  331. scrollFlag: true,
  332. current: "1", //当前显示的轮播图页
  333. goodsDetail: {}, //商品数据
  334. goodsSpec: "", //规格数据
  335. imgList: [], //轮播图数据
  336. favorite: false, //收藏与否flag
  337. recommendList: [], //推荐列表
  338. maskFlag: false, //模态显示与否
  339. cuxiao: false, //促销弹窗
  340. goodsInfo: false, //商品介绍弹窗
  341. addressFlag: false, //配送地址弹窗
  342. buyMask: false, //添加购物车直接购买,查看已选 弹窗
  343. num: 1, //添加到购物车的数量
  344. skuId: "", //
  345. storeDetail: "", //店铺基本信息,
  346. // 店铺信息
  347. storeParams: {
  348. pageNumber: 1,
  349. pageSize: 10,
  350. },
  351. likeGoodsList: "", //相似商品列表
  352. PromotionList: "", //活动,促销,列表
  353. specList: [],
  354. skusCombination: [],
  355. selectedSpec: [],
  356. nums: 0,
  357. delivery: "",
  358. exchange: {},
  359. productId: 0,
  360. startTimer: false, //未开启 是false
  361. routerVal: "",
  362. };
  363. },
  364. // #ifdef MP-WEIXNI
  365. shareAppMessage() {
  366. return {
  367. title: this.goodsDetail.goodsName,
  368. type: 0,
  369. query: `id=${this.routerVal.id}&goodsId=${this.routerVal.goodsId}`,
  370. path: `/pages/product/goods`,
  371. imageUrl: this.goodsDetail.goodsGalleryList[0],
  372. };
  373. },
  374. // #endif
  375. watch: {
  376. isGroup(val) {
  377. if (val) {
  378. let timer = setInterval(() => {
  379. this.$refs.popupGoods.buyType = "PINTUAN";
  380. clearInterval(timer);
  381. }, 100);
  382. this.isPromotion = false;
  383. } else {
  384. this.isPromotion = true;
  385. this.$refs.popupGoods.buyType = "";
  386. }
  387. },
  388. },
  389. mounted() {
  390. const { windowHeight } = uni.getSystemInfoSync();
  391. let bottomHeight = 0;
  392. let topHeight = 0;
  393. uni.getSystemInfo({
  394. success: function (res) {
  395. // res - 各种参数
  396. let bottom = uni.createSelectorQuery().select(".page-bottom");
  397. bottom
  398. .boundingClientRect(function (data) {
  399. if (data && data.height) {
  400. //data - 各种参数
  401. bottomHeight = data.height; // 获取元素宽度
  402. }
  403. })
  404. .exec();
  405. let top = uni.createSelectorQuery().select(".header");
  406. top
  407. .boundingClientRect(function (data) {
  408. if (data && data.height) {
  409. //data - 各种参数
  410. topHeight = data.height; // 获取元素宽度
  411. }
  412. })
  413. .exec();
  414. },
  415. });
  416. this.productRefHeight = windowHeight - bottomHeight + "px";
  417. },
  418. async onLoad(options) {
  419. this.routerVal = options;
  420. // #ifdef MP-WEIXIN
  421. // 小程序默认分享
  422. uni.showShareMenu({
  423. withShareTicket: true,
  424. menus: ["shareAppMessage", "shareTimeline"],
  425. });
  426. // #endif
  427. },
  428. async onShow() {
  429. this.goodsDetail = {};
  430. //如果有参数ids说明事分销短连接,需要获取参数
  431. if (this.routerVal.scene) {
  432. getMpScene(this.routerVal.scene).then((res) => {
  433. if (res.data.success) {
  434. let data = res.data.result.split(","); // skuId,goodsId,distributionId
  435. this.init(data[0], data[1], data[2]);
  436. }
  437. });
  438. } else {
  439. this.init(
  440. this.routerVal.id,
  441. this.routerVal.goodsId,
  442. this.routerVal.distributionId,
  443. this.routerVal.whetherPoint
  444. );
  445. }
  446. },
  447. methods: {
  448. /**
  449. * 导航栏列表栏
  450. */
  451. handleNavbarList(val) {
  452. modelNavigateTo({ url: val });
  453. },
  454. /**
  455. * 循环出当前促销是否为空
  456. */
  457. emptyPromotion() {
  458. if (
  459. this.PromotionList == "" ||
  460. this.PromotionList == null ||
  461. this.PromotionList == []
  462. ) {
  463. return true;
  464. }
  465. },
  466. selectSku(idObj) {
  467. this.init(idObj.skuId, idObj.goodsId);
  468. },
  469. /**
  470. * 初始化信息
  471. */
  472. async init(id, goodsId, distributionId) {
  473. console.log(id, goodsId);
  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. // 判断是否拼团活动或者积分商品 如果有则显示拼团活动信息
  499. this.PromotionList &&
  500. Object.keys(this.PromotionList).forEach((item) => {
  501. // 拼团商品
  502. if (item.indexOf("PINTUAN") == 0) {
  503. this.isGroup = true;
  504. }
  505. // 积分
  506. if (item.indexOf("POINTS_GOODS") == 0) {
  507. this.pointDetail = this.PromotionList[item];
  508. }
  509. });
  510. // 轮播图
  511. this.imgList = this.goodsDetail.goodsGalleryList;
  512. // 获取店铺基本信息
  513. this.getstoreBaseInfoFun(this.goodsDetail.storeId);
  514. // 获取购物车
  515. this.cartCount();
  516. // 获取店铺推荐商品
  517. this.getstoreRecommend();
  518. // 获取商品列表
  519. this.getOtherLikeGoods();
  520. // 获取商品是否已被收藏 如果未登录不获取
  521. if (this.$options.filters.isLogin("auth")) {
  522. this.getGoodsCollectionFun(this.goodsDetail.id);
  523. }
  524. },
  525. linkMsgDetail() {
  526. // 客服
  527. // #ifdef MP-WEIXIN
  528. const params = {
  529. storeName: this.storeDetail.storeName,
  530. goodsName: this.goodsDetail.goodsName,
  531. goodsId: this.goodsDetail.goodsId,
  532. goodsImg: this.goodsDetail.thumbnail,
  533. price: this.goodsDetail.promotionPrice || this.goodsDetail.price,
  534. // originalPrice: this.goodsDetail.original || this.goodsDetail.price,
  535. uuid: storage.getUuid(),
  536. token: storage.getAccessToken(),
  537. sign: this.storeDetail.yzfSign,
  538. mpSign: this.storeDetail.yzfMpSign,
  539. };
  540. uni.navigateTo({
  541. url:
  542. "/pages/product/customerservice/index?params=" +
  543. encodeURIComponent(JSON.stringify(params)),
  544. });
  545. // #endif
  546. // #ifndef MP-WEIXIN
  547. const sign = this.storeDetail.yzfSign;
  548. uni.navigateTo({
  549. url:
  550. "/pages/tabbar/home/web-view?src=https://yzf.qq.com/xv/web/static/chat/index.html?sign=" +
  551. sign,
  552. });
  553. // #endif
  554. },
  555. // 格式化金钱 1999 --> [1999,00]
  556. formatPrice(val) {
  557. if (typeof val == "undefined") {
  558. return val;
  559. }
  560. return val.toFixed(2).split(".");
  561. },
  562. /**选择商品 */
  563. changedGoods(val) {
  564. this.selectedGoods = val;
  565. },
  566. /** 点击子级地址回调参数*/
  567. deliveryFun(val) {
  568. this.delivery = val;
  569. },
  570. /**
  571. * 地址子级关闭回调
  572. */
  573. closePopupAddress(val) {
  574. this.addressFlag = val;
  575. this.maskFlag = false;
  576. },
  577. /**
  578. * 商品规格子级关闭回调
  579. */
  580. closePopupBuy(val) {
  581. this.buyMask = val;
  582. this.maskFlag = false;
  583. },
  584. /** 参与拼团 创建拼团 */
  585. toAssembleBuyNow(order) {
  586. this.shutMask(4, "PINTUAN", order);
  587. },
  588. /**
  589. * 查看购物车
  590. */
  591. reluchToCart() {
  592. let obj = {
  593. from: "product",
  594. id: this.productId,
  595. };
  596. storage.setCartBackbtn(obj);
  597. uni.switchTab({
  598. url: "/pages/tabbar/cart/cartList",
  599. });
  600. },
  601. /**
  602. * 查询购物车总数量
  603. */
  604. cartCount() {
  605. if (storage.getHasLogin()) {
  606. API_trade.getCartNum().then((res) => {
  607. this.nums = res.data.result;
  608. });
  609. }
  610. },
  611. /**
  612. * 返回
  613. */
  614. back() {
  615. if (getCurrentPages().length == 1) {
  616. uni.switchTab({
  617. url: "/pages/tabbar/home/index",
  618. });
  619. } else {
  620. uni.navigateBack();
  621. }
  622. },
  623. /**
  624. * 获取店铺信息
  625. */
  626. getstoreBaseInfoFun(id) {
  627. API_store.getstoreBaseInfo(id).then((res) => {
  628. if (res.data.success) {
  629. this.storeDetail = res.data.result;
  630. }
  631. });
  632. },
  633. /**
  634. * 删除收藏店铺
  635. */
  636. deleteGoodsCollectionFun(id) {
  637. API_Members.deleteGoodsCollection(id).then((res) => {
  638. if (res.statusCode == 200) {
  639. uni.showToast({
  640. title: "商品已取消收藏!",
  641. icon: "none",
  642. });
  643. this.favorite = !this.favorite;
  644. }
  645. });
  646. },
  647. /**
  648. * 获取商品是否已被收藏
  649. */
  650. getGoodsCollectionFun(goodsId) {
  651. if (storage.getHasLogin()) {
  652. API_Members.getGoodsIsCollect(goodsId, "GOODS").then((res) => {
  653. this.favorite = res.data.result;
  654. });
  655. }
  656. },
  657. /**
  658. * 获取店铺推荐商品列表
  659. */
  660. getstoreRecommend() {
  661. getGoodsList({
  662. pageNumber: 1,
  663. pageSize: 6,
  664. storeId: this.goodsDetail.storeId,
  665. recommend: true,
  666. }).then((res) => {
  667. this.recommendList = res.data.result.content;
  668. });
  669. },
  670. /**
  671. * 获取相似商品列表
  672. */
  673. getOtherLikeGoods() {
  674. getGoodsList({
  675. pageNumber: 1,
  676. pageSize: 10,
  677. category: this.goodsDetail.categoryId,
  678. keyword: this.goodsDetail.name,
  679. }).then((res) => {
  680. this.likeGoodsList = res.data.result.content;
  681. console.warn(this.likeGoodsList);
  682. });
  683. },
  684. /**
  685. * 领取优惠券
  686. */
  687. receiveCouponsFun(id) {
  688. API_Members.receiveCoupons(id).then((res) => {
  689. uni.showToast({
  690. title: res.data.message,
  691. icon: "none",
  692. });
  693. });
  694. },
  695. /**
  696. * 跳转到店铺页面
  697. */
  698. navigateToStore(store_id) {
  699. uni.navigateTo({
  700. url: `/pages/product/shopPage?id=` + store_id,
  701. });
  702. },
  703. /**
  704. * 获取优惠券按钮
  705. */
  706. getCoupon(item) {
  707. this.receiveCouponsFun(item.id);
  708. },
  709. /**
  710. * 规格弹窗开关
  711. */
  712. shutMask(flag, buyFlag, type) {
  713. // type是指是否点击底部按钮
  714. if (flag) {
  715. switch (flag) {
  716. case 1: //优惠券弹窗
  717. this.maskFlag = true;
  718. this.cuxiao = true;
  719. break;
  720. case 3:
  721. this.maskFlag = true;
  722. this.addressFlag = true;
  723. break;
  724. case 4: //添加购物车直接购买,查看已选 弹窗
  725. // 判断是否是一个规格
  726. this.maskFlag = true;
  727. this.buyMask = true;
  728. if (buyFlag == "PINTUAN") {
  729. if (type.orderSn) {
  730. this.$refs.popupGoods.parentOrder = type;
  731. }
  732. this.$refs.popupGoods.buyType = "PINTUAN";
  733. }
  734. if (buyFlag == "buy") {
  735. this.$refs.popupGoods.buyType = "";
  736. }
  737. break;
  738. }
  739. } else {
  740. this.maskFlag = false;
  741. this.cuxiao = false;
  742. this.buyMask = false;
  743. }
  744. },
  745. /**
  746. * 收藏
  747. */
  748. clickFavorite(id) {
  749. if (this.favorite) {
  750. // 取消收藏
  751. this.deleteGoodsCollectionFun(id);
  752. return false;
  753. }
  754. API_Members.collectionGoods(id, "GOODS").then((res) => {
  755. if (res.data.success) {
  756. uni.showToast({
  757. title: "收藏成功!",
  758. icon: "none",
  759. });
  760. }
  761. });
  762. this.favorite = !this.favorite;
  763. },
  764. /**
  765. * 顶部header显示或隐藏
  766. */
  767. pageScroll(e) {
  768. if (this.scrollFlag) {
  769. this.calcSize();
  770. }
  771. if (e.detail.scrollTop > 200) {
  772. //当距离大于200时显示回到顶部按钮
  773. this.headerFlag = true;
  774. } else {
  775. //当距离小于200时隐藏回到顶部按钮
  776. this.headerFlag = false;
  777. }
  778. if (e.detail.scrollTop < this.scrollArr[0] - 10) {
  779. this.scrollId = "1";
  780. }
  781. if (e.detail.scrollTop > this.scrollArr[1] - 10) {
  782. this.scrollId = "2";
  783. }
  784. if (e.detail.scrollTop > this.scrollArr[2] - 10) {
  785. this.scrollId = "3";
  786. }
  787. if (e.detail.scrollTop > this.scrollArr[3] - 10) {
  788. this.scrollId = "4";
  789. }
  790. },
  791. /**
  792. * 计算每个要跳转到的模块高度信息
  793. */
  794. calcSize() {
  795. let h = 0;
  796. let that = this;
  797. let arr = [
  798. "main1",
  799. "main2",
  800. "main3",
  801. "main4",
  802. "main5",
  803. "main6",
  804. "main7",
  805. "main8",
  806. "main9",
  807. "main10",
  808. "main11",
  809. ];
  810. arr.forEach((item) => {
  811. let view = uni.createSelectorQuery().select("#" + item);
  812. view
  813. .fields(
  814. {
  815. size: true,
  816. },
  817. (data) => {
  818. if (
  819. item === "main1" ||
  820. item === "main5" ||
  821. item === "main9" ||
  822. item === "main11"
  823. ) {
  824. that.scrollArr.push(h);
  825. }
  826. if (data && data.height) {
  827. h += data.height;
  828. }
  829. }
  830. )
  831. .exec();
  832. });
  833. this.scrollFlag = false;
  834. },
  835. /**
  836. * 点击顶部跳转到对应位置
  837. */
  838. headerTab(id) {
  839. if (this.scrollFlag) {
  840. this.calcSize();
  841. }
  842. this.scrollId = id;
  843. this.$nextTick(() => {
  844. this.tabScrollTop = this.scrollArr[id - 1];
  845. });
  846. },
  847. /**
  848. * 点击分享
  849. */
  850. async shareChange() {
  851. this.shareFlage = true;
  852. },
  853. },
  854. };
  855. </script>
  856. <style lang="scss" scoped>
  857. // #ifdef MP-WEIXIN
  858. @import "./product/mp-goods.scss";
  859. // #endif
  860. @import "./product/style.scss";
  861. @import "./product/product.scss";
  862. </style>