product.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. <template>
  2. <view class="container">
  3. <view class="carousel">
  4. <swiper indicator-dots :circular="true" duration="400">
  5. <swiper-item class="swiper-item" v-for="(item, index) in imgList" :key="index">
  6. <view class="image-wrapper"><image :src="item" class="loaded" mode="aspectFill"></image></view>
  7. </swiper-item>
  8. </swiper>
  9. </view>
  10. <view class="introduce-section seckill-box-title" v-if="goodsType == 1">
  11. <view class="title flex">
  12. <view class="title-box">
  13. <text class="price-tip">¥</text>
  14. <text class="price">{{ goodsObjact.price }}</text>
  15. <!-- <text class="m-price" v-if="goodsObjact.ot_price > goodsObjact.price">¥{{ goodsObjact.ot_price }}</text> -->
  16. <!-- <text class="coupon-tip">7折</text> -->
  17. </view>
  18. <view class="flex timeStop">
  19. <view>距离结束</view>
  20. <uni-countdown
  21. color="#ffffff"
  22. background-color="#D65B3F"
  23. splitor-color="#FFFFFF"
  24. :show-day="false"
  25. :hour="seckillObj.stopTimeH"
  26. :minute="seckillObj.stopTimeM"
  27. :second="seckillObj.stopTimeS"
  28. ></uni-countdown>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="introduce-section">
  33. <text class="title" v-if="goodsType == 1">{{ goodsObjact.title }}</text>
  34. <view class="price-box" v-if="goodsType == 0">
  35. <text class="price-tip">¥</text>
  36. <text class="price">{{ goodsObjact.price }}</text>
  37. <text class="price-tip" v-if="goodsObjact.max_use_integral*1 > 0">+</text>
  38. <text class="price" v-if="goodsObjact.max_use_integral*1 > 0">{{ goodsObjact.max_use_integral }}积分</text>
  39. <text class="m-price" v-if="goodsObjact.ot_price > goodsObjact.price">¥{{ goodsObjact.ot_price }}</text>
  40. <!-- <text class="coupon-tip">7折</text> -->
  41. </view>
  42. <text class="title" v-if="goodsType == 0">{{ goodsObjact.store_name }}</text>
  43. <view class="bot-row">
  44. <text>快递: {{ goodsObjact.postage }}</text>
  45. <text style="text-align: center;">销量: {{ goodsObjact.sales }}</text>
  46. <text style="text-align: right;">{{ storeObjact.address | address}}</text>
  47. </view>
  48. </view>
  49. <!-- 评价 -->
  50. <view class="eva-section" v-if="reply" @click="navTo('/pages/product/reply?id=' + goodsid)">
  51. <view class="e-header">
  52. <text class="tit">评价</text>
  53. <text>({{ details.replyCount }})</text>
  54. <text class="tip">好评率 {{ details.replyChance }}%</text>
  55. <text class="iconfont iconenter"></text>
  56. </view>
  57. <view class="eva-box">
  58. <image class="portrait" :src="reply.avatar" mode="aspectFill"></image>
  59. <view class="right">
  60. <text class="name">{{ reply.nickname }}</text>
  61. <text class="con">{{ reply.comment }}</text>
  62. <view class="con_box">
  63. <view class="con_image" v-for="item in reply.pics"><image :src="item"></image></view>
  64. </view>
  65. <view class="bot">
  66. <text class="attr"></text>
  67. <text class="time">{{ reply.add_time }}</text>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="eva-boxs" v-if="reply.merchant_reply_content">
  72. <view class="right">
  73. <text class="con">
  74. <text style="color: #FD5B23;margin-right: 8rpx;">商家回复 :</text>
  75. {{ reply.merchant_reply_content }}
  76. </text>
  77. <view class="bot">
  78. <text class="attr"></text>
  79. <text class="time">{{ reply.merchant_reply_time }}</text>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. <view class="c-list">
  85. <view class="c-row b-b" @click="toggleSpec">
  86. <text class="tit">购买数量</text>
  87. <view class="con">
  88. <text class="selected-text">{{ goodsNumber }}</text>
  89. </view>
  90. <text class="iconfont iconenter"></text>
  91. </view>
  92. <view class="c-row b-b" v-if="goodsType == 1">
  93. <text class="tit">限购数量</text>
  94. <view class="con">
  95. <text class="selected-text">{{ goodsObjact.num + goodsObjact.unit_name }}</text>
  96. </view>
  97. </view>
  98. <view class="c-row b-b" v-if="goodsObjact.give_integral != 0">
  99. <text class="tit">获取积分</text>
  100. <text class="con t-r red">每购买一件商品送{{goodsObjact.give_integral}}积分</text>
  101. <!-- <text class="iconfont iconenter"></text> -->
  102. </view>
  103. </view>
  104. <view class="shop-box flex" v-if="goodsType == 0 && shopId > 0">
  105. <view class="flex">
  106. <image :src="shopInfo.logo" mode=" aspectFit" class="shop-img"></image>
  107. <text class="font-size-lg">{{ shopInfo.title }}</text>
  108. </view>
  109. <navigator :url="'/pages/shoping/index?merid=' + shopId"><view class="shop-button">进店逛逛</view></navigator>
  110. </view>
  111. <view class="detail-desc">
  112. <view class="d-header"><text>图文详情</text></view>
  113. <rich-text class="detail-centent" :nodes="goodsObjact.description"></rich-text>
  114. <view :class="{ contentBottomHeight: goodsType == 1 || goodsType == 2, goodsBottom: goodsType == 0 }"></view>
  115. </view>
  116. <!-- 底部操作菜单 -->
  117. <view class="page-bottom" v-if="goodsType == 0">
  118. <!-- <navigator url="/pages/index/index" open-type="switchTab" class="p-b-btn">
  119. <text class="iconfont iconhome"></text>
  120. <text>首页</text>
  121. </navigator>
  122. <navigator url="/pages/cart/cart" open-type="switchTab" class="p-b-btn">
  123. <text class="iconfont iconcart"></text>
  124. <text>购物车</text>
  125. </navigator> -->
  126. <view class="p-b-btn" :class="{ active: goodsObjact.userCollect }" @click="toFavorite(goodsObjact)">
  127. <text class="iconfont " :class="{ iconlike: !goodsObjact.userCollect, iconlikefill: goodsObjact.userCollect }"></text>
  128. <text>收藏</text>
  129. </view>
  130. <view class="action-btn-group" v-if="goodsObjact.max_use_integral == 0">
  131. <button type="primary" class=" action-btn no-border buy-now-btn" @click="toggleSpec(2)">加入购物车</button>
  132. <button type="primary" class=" action-btn no-border add-cart-btn" @click="toggleSpec(1)">立即购买</button>
  133. </view>
  134. <view class="action-btn-group" v-if="goodsObjact.max_use_integral != 0">
  135. <button type="primary" class=" action-btn no-border add-cart-btn" style="width: 750rpx;" @click="toggleSpec(1)">立即购买</button>
  136. </view>
  137. </view>
  138. <!-- 秒杀商品购买 -->
  139. <view class="goods-pay-box flex" :class="{ stop: seckillObj.stop }" v-if="goodsType == 1">
  140. <view class="goods-pay bgLine" v-if="!seckillObj.stop" @click="toggleSpec(1)"><text>立即购买</text></view>
  141. <view class="goods-pay-stop" v-else>活动已结束</view>
  142. </view>
  143. <!-- 拼团商品购买 -->
  144. <view class="goods-pay-box flex" v-if="goodsType == 2">
  145. <view class="goods-pay bg-warning" @click="navToProductGoods">
  146. <view class="goods-buttom-money">¥{{ goodsObjact.product_price }}</view>
  147. <view class="goods-buttom">单独购买</view>
  148. </view>
  149. <view class="goods-pay bg-danger" @click="toggleSpec(1)">
  150. <view class="goods-buttom-money">¥{{ goodsObjact.price }}</view>
  151. <view class="goods-buttom">我要拼团</view>
  152. </view>
  153. </view>
  154. <!-- 规格-模态层弹窗 -->
  155. <view class="popup spec" :class="specClass" @touchmove.stop.prevent="stopPrevent" @click="toggleSpec">
  156. <!-- 遮罩层 -->
  157. <view class="mask"></view>
  158. <view class="layer attr-content" @click.stop="stopPrevent">
  159. <view class="a-t">
  160. <image :src="actionImage"></image>
  161. <view class="right">
  162. <view class="good-name clamp">{{goodsObjact.store_name}}</view>
  163. <text class="price" v-if="goodsObjact.max_use_integral > 0">¥{{ actionPrice }}+{{goodsObjact.max_use_integral*1}}积分</text>
  164. <text class="price" v-else>¥{{ actionPrice }}</text>
  165. <!-- <text class="stock">库存:{{ goodsObjact.stock }}件</text> -->
  166. <!-- <view class="selected" v-if="goodsType == 0">
  167. 已选:
  168. <text class="selected-text" v-for="(sItem, sIndex) in specSelected" :key="sIndex">{{ sItem }}</text>
  169. </view> -->
  170. </view>
  171. </view>
  172. <view v-for="(item, index) in specList" :key="index" class="attr-list">
  173. <text>{{ item.attr_name }}</text>
  174. <view class="item-list">
  175. <text
  176. v-for="(childItem, childIndex) in item.attr_value"
  177. :key="childIndex"
  178. class="tit"
  179. :class="{ selected: childItem.check }"
  180. @click="selectSpec(childItem, item, index)"
  181. >
  182. {{ childItem.attr }}
  183. </text>
  184. </view>
  185. </view>
  186. <view class="attr-list">
  187. <text>购买数量</text>
  188. <view class="item-list">
  189. <uni-number-box class="step" :isMin="true" :value="goodsNumber" :min="1" :max="goodsNumberMax" @eventChange="numberChange"></uni-number-box>
  190. </view>
  191. </view>
  192. <button class="btn" @click.stop="buy">完成</button>
  193. </view>
  194. </view>
  195. <view :class="{ seckillBottom: goodsType == 1, goodsBottom: goodsType == 0 }"></view>
  196. <!-- 分享 -->
  197. <!-- <share ref="share" :contentHeight="580" :shareList="shareList"></share> -->
  198. </view>
  199. </template>
  200. <script>
  201. import share from '@/components/share';
  202. import uniNumberBox from '@/components/uni-number-box.vue';
  203. import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
  204. import { goodsDetail, cartAdd, collectAdd, collectDel, seckillGoods, groupGoods } from '@/api/product.js';
  205. import { getShoping } from '@/api/shoping.js';
  206. // import { weixindata } from '@/utils/wxAuthorized';
  207. import { mapState } from 'vuex';
  208. // #ifdef H5
  209. import { weixindata, weixinlocation,shareLoad } from '@/utils/wxAuthorized';
  210. // #endif
  211. export default {
  212. components: {
  213. share,
  214. uniNumberBox,
  215. uniCountdown
  216. },
  217. filters: {
  218. address(val) {
  219. let str = ''
  220. if(val) {
  221. str = val[0] + ' ' + val[1]
  222. }
  223. return str
  224. }
  225. },
  226. data() {
  227. return {
  228. paying: false,//是否正在支付
  229. details: '',
  230. reply: '', //评论
  231. type: 1, //默认支付方式add为
  232. goodsNumber: 1, //购买数量
  233. goodsid: '', //商品id
  234. specClass: 'none', //显示隐藏弹窗
  235. shareList: [], //分享列表
  236. goodsObjact: {}, //保存商品数据
  237. storeObjact: {},//保存店铺数据
  238. //图片循环
  239. imgList: [],
  240. specList: [],
  241. // 对比对象
  242. productValue: [],
  243. actionPrice: 0, //默认选中商品价格
  244. actionIntegral: 0,//默认选中商品积分
  245. actionImage: '', //默认选中图片
  246. uniqueId: '', //选中的商品分类
  247. specSelected: [], //选中的分类
  248. specSelectedName: '', //选中分类名称
  249. goodsNumberMax: 0, //最大可购买数量
  250. shopId: '', //商店id
  251. //商店信息
  252. shopInfo: {
  253. logo: '',
  254. title: ''
  255. }, //商店信息
  256. goodsType: 0, //商品类型1秒杀商品0为普通商品2为拼团商品
  257. // 秒杀数据保存
  258. seckillObj: {
  259. stopTime: 0, //结束时间
  260. stop: false, //是否结束
  261. stopTimeH: 0, //小时
  262. stopTimeM: 0, //分钟
  263. stopTimeS: 0 //秒钟
  264. },
  265. // 拼团数据保存
  266. pink: {
  267. id: '', //拼团编号
  268. uid: '', //用户编号
  269. people: '', //拼团人数
  270. price: '', //拼团价格
  271. stop_time: '', //拼团结束时间
  272. nickname: '', //团长昵称
  273. avatar: '', //团长头像
  274. count: '', //拼团剩余人数
  275. h: '', //时
  276. i: '', //分
  277. s: '' //秒
  278. }
  279. };
  280. },
  281. async onLoad(options) {
  282. let obj = this;
  283. //保存商品id
  284. this.goodsid = options.id;
  285. // 判断有无人邀请
  286. if (options.spread) {
  287. // 存储邀请人
  288. uni.setStorageSync('spread', options.spread);
  289. }
  290. // 判断是否为秒杀商品
  291. if (options.type == 1) {
  292. // 保存商品类型
  293. this.goodsType = 1;
  294. // 保存结束时间
  295. this.seckillObj.stopTime = options.stoptime;
  296. // 获取当前时间毫秒数
  297. let stoptime = options.stoptime * 1000;
  298. // 获取当前时间
  299. let acitonTime = new Date();
  300. // 判断当前时间是否大于结束时间
  301. if (acitonTime.getTime() > stoptime) {
  302. // 当前秒杀时间已经结束
  303. this.seckillObj.stop = true;
  304. } else {
  305. // 计算倒计时
  306. this.timeComputed(stoptime, this.seckillObj);
  307. }
  308. this.seckillGoods();
  309. return;
  310. }
  311. if (options.type == 2) {
  312. // 保存当前拼团商品类型
  313. this.goodsType = 2;
  314. // 家在数据
  315. this.groupGoods();
  316. return;
  317. }
  318. if (this.goodsType == 0) {
  319. // 加载普通商品详情
  320. this.goodsDetail();
  321. }
  322. },
  323. computed: {
  324. // #ifdef H5
  325. ...mapState(['weichatObj', 'baseURL', 'urlFile']),
  326. ...mapState('user', ['userInfo'])
  327. // #endif
  328. },
  329. methods: {
  330. // 分享
  331. // #ifdef H5
  332. IndexShare() {
  333. let obj = this
  334. // console.log('dddddddffffffffffffff')
  335. // 设置菜单中的转发按钮触发转发事件时的转发内容
  336. let pages = getCurrentPages(); //获取加载的页面
  337. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  338. let url = '/#/' + currentPage.route; //当前页面url
  339. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  340. let shareObj = {
  341. title: obj.goodsObjact.store_name, // 默认是小程序的名称(可以写slogan等)
  342. link: obj.baseURL + url + '?id=' + item.id + '&spread=' + obj.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  343. desc: obj.goodsObjact.store_name + ' 价格:' + obj.goodsObjact.price,
  344. imgUrl: obj.goodsObjact.image,
  345. success: function(res) {
  346. // 转发成功之后的回调
  347. if (res.errMsg == 'shareAppMessage:ok') {
  348. }
  349. },
  350. fail: function() {
  351. // 转发失败之后的回调
  352. if (res.errMsg == 'shareAppMessage:fail cancel') {
  353. // 用户取消转发
  354. } else if (res.errMsg == 'shareAppMessage:fail') {
  355. // 转发失败,其中 detail message 为详细失败信息
  356. }
  357. }
  358. };
  359. console.log(shareObj, '8888888888888888888');
  360. shareLoad(shareObj);
  361. },
  362. // #endif
  363. navTo(url) {
  364. uni.navigateTo({
  365. url
  366. });
  367. },
  368. //获取商店信息
  369. getShoping() {
  370. let obj = this;
  371. getShoping({
  372. mer_id: this.shopId
  373. })
  374. .then(function({ data }) {
  375. console.log(data);
  376. obj.shopInfo = data;
  377. })
  378. .catch(e => {
  379. console.log(e);
  380. });
  381. },
  382. // 转换字符串为数字
  383. moneyNum: function(value) {
  384. return +value;
  385. },
  386. navToProductGoods() {
  387. uni.redirectTo({
  388. url: '/pages/product/product?id=' + this.goodsObjact.product_id
  389. });
  390. },
  391. // 获取拼团商品详情
  392. groupGoods() {
  393. let obj = this;
  394. groupGoods({}, this.goodsid).then(function({ data }) {
  395. obj.pink = data.pink[0]; //保存拼团信息
  396. let goods = data.storeInfo;
  397. obj.goodsObjact = goods;
  398. console.log(goods,'123456');
  399. obj.imgList = goods.images; //保存轮播图
  400. obj.specList = data.productAttr; //保存分类列表
  401. obj.productValue = data.productValue; //保存分类查询数据
  402. obj.actionPrice = goods.price; //保存默认选中商品价格
  403. obj.actionImage = goods.image_base; //保存默认选中商品图片
  404. obj.goodsNumberMax = 1; //保存默认选中最大可购买商品数量
  405. obj.shopId = data.mer_id; //保存商店id
  406. if (obj.shopId > 0) {
  407. obj.getShoping();
  408. }
  409. // #ifdef H5
  410. obj.shareDate();
  411. // #endif
  412. });
  413. },
  414. // 获取秒杀商品详情
  415. seckillGoods() {
  416. let obj = this;
  417. seckillGoods({}, this.goodsid).then(function({ data }) {
  418. let goods = data.storeInfo;
  419. obj.goodsObjact = goods;
  420. obj.imgList = goods.images; //保存轮播图
  421. obj.specList = data.productAttr; //保存分类列表
  422. obj.productValue = data.productValue; //保存分类查询数据
  423. obj.actionPrice = goods.price; //保存默认选中商品价格
  424. obj.actionImage = goods.image_base; //保存默认选中商品价格
  425. obj.goodsNumberMax = goods.num; //保存默认选中最大可购买商品数量
  426. obj.shopId = data.mer_id; //保存商店id
  427. if (obj.shopId > 0) {
  428. obj.getShoping();
  429. }
  430. // #ifdef H5
  431. obj.shareDate();
  432. // #endif
  433. });
  434. },
  435. // 计算倒计时时间
  436. timeComputed(da, ar) {
  437. let obj = ar;
  438. // 设置到期时间
  439. let time = new Date(da);
  440. // 获取当前时间
  441. let actTime = new Date();
  442. // 获取到期时间具体值
  443. let tH = time.getHours();
  444. let tM = time.getMinutes();
  445. let tS = time.getSeconds();
  446. // 获取当前时间具体值
  447. let aH = actTime.getHours();
  448. let aM = actTime.getMinutes();
  449. let aS = actTime.getSeconds();
  450. // 计算时间,保存需要多少时间到期
  451. obj.stopTimeH = tH - aH;
  452. obj.stopTimeM = tM - aM;
  453. obj.stopTimeS = tS - aS;
  454. },
  455. // 获取商品信息
  456. goodsDetail() {
  457. let obj = this;
  458. goodsDetail({}, this.goodsid).then(function({ data }) {
  459. obj.details = data;
  460. let goods = data.storeInfo;
  461. let store_info = data.system_store; // 保存店铺信息
  462. console.log(store_info);
  463. obj.storeObjact = store_info;
  464. obj.goodsObjact = goods;
  465. //商品详情图超出屏幕问题
  466. if (obj.goodsObjact.description != null) {
  467. obj.goodsObjact.description = obj.goodsObjact.description.replace(/<img/g, '<img class="rich-img"').replace(/<p>\s*<img/g, '<p class="pHeight"><img');
  468. }
  469. if ( obj.goodsObjact.rule != null ) {
  470. obj.goodsObjact.rule ='<p>' + obj.goodsObjact.rule.replace(/\n/g, '</p><p>').trim() + '</p>'
  471. }
  472. obj.reply = data.reply; //保存评论列表
  473. obj.imgList = goods.slider_image; //保存轮播图
  474. obj.specList = data.productAttr; //保存分类列表
  475. console.log(data.productAttr);
  476. obj.productValue = data.productValue; //保存分类查询数据
  477. obj.actionPrice = goods.price; //保存默认选中商品价格
  478. obj.actionIntegral = goods.integral; //保存默认选中商品积分
  479. obj.actionImage = goods.image_base; //保存默认选中商品价格
  480. obj.goodsNumberMax = goods.stock; //保存默认选中最大可购买商品数量
  481. obj.shopId = data.mer_id; //保存商店id
  482. // 保存默认选中的对象
  483. obj.specSelected = []; //初始化默认选择对象
  484. for (let i = 0; i < obj.specList.length; i++) {
  485. // 设置默认数据
  486. let attrValue = obj.specList[i].attr_value[0];
  487. attrValue.check = true;
  488. obj.specSelected.push(attrValue.attr);
  489. }
  490. //保存默认选中的对象字符串名称
  491. let str = obj.specSelected.join(',');
  492. // 设置默认值
  493. obj.actionImage = obj.productValue[str].image;
  494. obj.uniqueId = obj.productValue[str].unique;
  495. // #ifdef H5
  496. obj.shareDate();
  497. // #endif
  498. });
  499. },
  500. // #ifdef H5
  501. // 加载微信html5页面分享方法
  502. shareDate() {
  503. let obj = this;
  504. // 保存分享人id链接
  505. let url = window.location.href + '&spread=' + this.userInfo.uid;
  506. // 判断是否微信浏览器
  507. let bool = uni.getStorageSync('weichatBrowser') || '';
  508. if (bool) {
  509. // 过滤微信强制添加的链接地址
  510. url = url.replace(/[\?,&]from=singlemessage/g, '');
  511. let data = {
  512. link: url, // 分享链接
  513. imgUrl: obj.goodsObjact.image, // 分享图标
  514. desc: obj.goodsObjact.store_info,
  515. title: obj.goodsObjact.store_name,
  516. success: function(e) {
  517. console.log(e);
  518. }
  519. };
  520. weixindata(data);
  521. }
  522. },
  523. // #endif
  524. // 购买数量变化
  525. numberChange(e) {
  526. this.goodsNumber = e.number;
  527. },
  528. //规格弹窗开关
  529. toggleSpec(str) {
  530. if (this.specClass === 'show') {
  531. this.specClass = 'hide';
  532. setTimeout(() => {
  533. this.specClass = 'none';
  534. }, 250);
  535. } else if (this.specClass === 'none') {
  536. this.specClass = 'show';
  537. }
  538. // 保存当前购买类型
  539. this.type = str;
  540. },
  541. //选择规格
  542. selectSpec(item, arr, ind) {
  543. arr.attr_value.forEach(function(e) {
  544. e.check = false;
  545. });
  546. item.check = true;
  547. this.specSelected[ind] = item.attr;
  548. let str = this.specSelected.join(',');
  549. this.specSelectedName = this.specSelected.join(' ');
  550. if (this.productValue[str]) {
  551. let data = this.productValue[str];
  552. this.actionPrice = data.price;
  553. this.goodsNumberMax = data.stock;
  554. this.actionIntegral = data.integral
  555. this.actionImage = data.image;
  556. this.uniqueId = data.unique;
  557. }
  558. },
  559. //分享
  560. share() {
  561. this.$refs.share.toggleMask();
  562. },
  563. //收藏
  564. toFavorite(item) {
  565. let obj = this;
  566. item.userCollect = !item.userCollect;
  567. if (!item.userCollect) {
  568. collectDel({ id: obj.goodsid, category: 'product' }).then(function(e) {
  569. uni.showToast({
  570. title: '成功取消收藏',
  571. type: 'top',
  572. duration: 1500
  573. });
  574. });
  575. } else {
  576. collectAdd({ id: obj.goodsid, category: 'product' }).then(function(e) {
  577. uni.showToast({
  578. title: '成功加入收藏',
  579. type: 'top',
  580. duration: 1500
  581. });
  582. });
  583. }
  584. },
  585. // 立即购买
  586. buy() {
  587. let obj = this;
  588. let data = {
  589. cartNum: obj.goodsNumber, //商品数量
  590. uniqueId: obj.uniqueId, //商品标签
  591. new: '1', //商品是否新增加到购物车1为不加入0为加入
  592. mer_id: obj.shopId,
  593. is_consumer: 0,
  594. // type: 0,//0为余额支付 1为消费券支付 2为积分支付
  595. };
  596. if(obj.paying) {
  597. return
  598. }
  599. obj.paying = true
  600. if (obj.type == 2) {
  601. data.new = 0;
  602. }
  603. if (obj.goodsType == 0) {
  604. data.productId = obj.goodsid; //商品编号
  605. }
  606. // 判断是否为秒杀商品
  607. if (obj.goodsType == 1) {
  608. data.secKillId = obj.goodsid; //秒杀商品编号
  609. data.productId = obj.goodsObjact.product_id; //商品编号
  610. // 判断是否秒杀已经结束
  611. if (obj.seckillObj.stop) {
  612. uni.showModal({
  613. title: '提示',
  614. content: '当前活动已经结束',
  615. showCancel: false
  616. });
  617. return;
  618. }
  619. }
  620. // 判断是否为拼团商品
  621. if (obj.goodsType == 2) {
  622. data.combinationId = obj.goodsid; //拼团编号
  623. data.productId = obj.goodsObjact.product_id; //商品编号
  624. }
  625. cartAdd(data)
  626. .then(function({ data }) {
  627. obj.paying = false
  628. if (obj.type == 1) {
  629. // 跳转到支付页
  630. uni.navigateTo({
  631. url: '/pages/order/createOrder?id=' + data.cartId + '&goodsType=' + obj.goodsType
  632. });
  633. }
  634. if (obj.type == 2) {
  635. uni.showToast({
  636. title: '成功加入购物车',
  637. type: 'top',
  638. duration: 2000
  639. });
  640. obj.toggleSpec();
  641. }
  642. })
  643. .catch(e => {
  644. obj.paying = false
  645. console.log(e);
  646. });
  647. },
  648. stopPrevent() {}
  649. }
  650. };
  651. </script>
  652. <style lang="scss">
  653. page {
  654. background: $page-color-base;
  655. }
  656. //秒杀底部高度
  657. .seckillBottom {
  658. height: 110rpx;
  659. }
  660. // 文章页底部高度撑开
  661. .contentBottomHeight {
  662. height: 110rpx;
  663. }
  664. //默认商品底部高度
  665. .goodsBottom {
  666. height: 160rpx;
  667. }
  668. .iconenter {
  669. font-size: $font-base + 2rpx;
  670. color: #888;
  671. }
  672. .carousel {
  673. /* #ifdef APP-PLUS */
  674. padding-top: var(--status-bar-height);
  675. /* #endif */
  676. height: 722rpx;
  677. position: relative;
  678. swiper {
  679. height: 100%;
  680. }
  681. .image-wrapper {
  682. width: 100%;
  683. height: 100%;
  684. }
  685. .swiper-item {
  686. display: flex;
  687. justify-content: center;
  688. align-content: center;
  689. // height: 750rpx;
  690. height: 710rpx;
  691. overflow: hidden;
  692. image {
  693. width: 100%;
  694. height: 100%;
  695. }
  696. }
  697. }
  698. // 秒杀
  699. .seckill-box-title {
  700. background: linear-gradient(90deg, rgba(239, 78, 81, 1) 0%, rgba(244, 113, 59, 1) 100%) !important;
  701. .price,
  702. .price-tip,
  703. .timeStop,
  704. .m-price {
  705. color: #ffffff !important;
  706. }
  707. .price-tip {
  708. font-size: $font-base;
  709. }
  710. .price {
  711. font-size: 45rpx !important;
  712. font-weight: bold;
  713. }
  714. .timeStop {
  715. }
  716. }
  717. // 底部拼团、秒杀支付按钮
  718. .goods-pay-box {
  719. position: fixed;
  720. left: 0;
  721. bottom: 0;
  722. z-index: 95;
  723. width: 750rpx;
  724. height: 100rpx;
  725. line-height: 1;
  726. color: #ffffff;
  727. text-align: center;
  728. font-size: $font-lg;
  729. .bgLine {
  730. background: linear-gradient(90deg, rgba(239, 78, 81, 1) 0%, rgba(244, 113, 59, 1) 100%);
  731. }
  732. // 拼团支付按钮
  733. .goods-pay {
  734. display: flex;
  735. align-content: center;
  736. flex-wrap: wrap;
  737. justify-content: center;
  738. .goods-buttom,
  739. .goods-buttom-money {
  740. width: 100%;
  741. }
  742. .goods-buttom-money {
  743. font-size: $font-base;
  744. }
  745. }
  746. .goods-pay-stop,
  747. .goods-pay {
  748. padding: 15rpx 0;
  749. height: 100%;
  750. width: 100%;
  751. }
  752. .goods-pay-stop {
  753. background: $color-gray;
  754. line-height: 70rpx;
  755. }
  756. }
  757. /* 标题简介 */
  758. .introduce-section {
  759. background: #fff;
  760. padding: 20rpx 30rpx;
  761. .title {
  762. font-size: 32rpx;
  763. color: $font-color-dark;
  764. height: 50rpx;
  765. line-height: 50rpx;
  766. }
  767. .price-box {
  768. display: flex;
  769. align-items: baseline;
  770. height: 64rpx;
  771. padding: 10rpx 0;
  772. font-size: 26rpx;
  773. color: $uni-color-primary;
  774. }
  775. .price {
  776. font-size: $font-lg + 2rpx;
  777. }
  778. .m-price {
  779. margin: 0 12rpx;
  780. color: $font-color-light;
  781. text-decoration: line-through;
  782. }
  783. .coupon-tip {
  784. align-items: center;
  785. padding: 4rpx 10rpx;
  786. background: $uni-color-primary;
  787. font-size: $font-sm;
  788. color: #fff;
  789. border-radius: 6rpx;
  790. line-height: 1;
  791. transform: translateY(-4rpx);
  792. }
  793. .bot-row {
  794. display: flex;
  795. align-items: center;
  796. height: 50rpx;
  797. font-size: $font-sm;
  798. color: $font-color-light;
  799. text {
  800. flex: 1;
  801. }
  802. }
  803. }
  804. /* 分享 */
  805. .share-section {
  806. display: flex;
  807. align-items: center;
  808. color: $font-color-base;
  809. background: linear-gradient(left, #fdf5f6, #fbebf6);
  810. padding: 12rpx 30rpx;
  811. .share-icon {
  812. display: flex;
  813. align-items: center;
  814. width: 70rpx;
  815. height: 30rpx;
  816. line-height: 1;
  817. border: 1px solid $uni-color-primary;
  818. border-radius: 4rpx;
  819. position: relative;
  820. overflow: hidden;
  821. font-size: 22rpx;
  822. color: $uni-color-primary;
  823. &:after {
  824. content: '';
  825. width: 50rpx;
  826. height: 50rpx;
  827. border-radius: 50%;
  828. left: -20rpx;
  829. top: -12rpx;
  830. position: absolute;
  831. background: $uni-color-primary;
  832. }
  833. }
  834. .iconfavorfill {
  835. position: relative;
  836. z-index: 1;
  837. font-size: 24rpx;
  838. margin-left: 2rpx;
  839. margin-right: 10rpx;
  840. color: #fff;
  841. line-height: 1;
  842. }
  843. .tit {
  844. font-size: $font-base;
  845. margin-left: 10rpx;
  846. }
  847. .iconprompt {
  848. padding: 10rpx;
  849. font-size: 30rpx;
  850. line-height: 1;
  851. }
  852. .share-btn {
  853. flex: 1;
  854. text-align: right;
  855. font-size: $font-sm;
  856. color: $uni-color-primary;
  857. }
  858. .iconenter {
  859. font-size: $font-sm;
  860. margin-left: 4rpx;
  861. color: $uni-color-primary;
  862. }
  863. }
  864. .c-list {
  865. margin-top: 20rpx;
  866. font-size: $font-sm + 2rpx;
  867. color: $font-color-base;
  868. background: #fff;
  869. .c-row {
  870. display: flex;
  871. align-items: center;
  872. padding: 20rpx 30rpx;
  873. position: relative;
  874. }
  875. .tit {
  876. width: 140rpx;
  877. }
  878. .con {
  879. flex: 1;
  880. color: $font-color-dark;
  881. .selected-text {
  882. margin-right: 10rpx;
  883. }
  884. }
  885. .bz-list {
  886. height: 40rpx;
  887. font-size: $font-sm + 2rpx;
  888. color: $font-color-dark;
  889. text {
  890. display: inline-block;
  891. margin-right: 30rpx;
  892. }
  893. }
  894. .con-list {
  895. flex: 1;
  896. display: flex;
  897. flex-direction: column;
  898. color: $font-color-dark;
  899. line-height: 40rpx;
  900. }
  901. .red {
  902. color: $uni-color-primary;
  903. }
  904. }
  905. /* 评价 */
  906. .eva-section {
  907. display: flex;
  908. flex-direction: column;
  909. padding: 20rpx 30rpx;
  910. background: #fff;
  911. margin-top: 16rpx;
  912. .e-header {
  913. display: flex;
  914. align-items: center;
  915. height: 70rpx;
  916. font-size: $font-sm + 2rpx;
  917. color: $font-color-light;
  918. .tit {
  919. font-size: $font-base + 2rpx;
  920. color: $font-color-dark;
  921. margin-right: 4rpx;
  922. }
  923. .tip {
  924. flex: 1;
  925. text-align: right;
  926. }
  927. .iconenter {
  928. margin-left: 10rpx;
  929. }
  930. }
  931. }
  932. .eva-box {
  933. display: flex;
  934. padding: 20rpx 0;
  935. .portrait {
  936. flex-shrink: 0;
  937. width: 80rpx;
  938. height: 80rpx;
  939. border-radius: 100px;
  940. }
  941. .right {
  942. flex: 1;
  943. display: flex;
  944. flex-direction: column;
  945. font-size: $font-base;
  946. color: $font-color-base;
  947. padding-left: 26rpx;
  948. .con {
  949. font-size: $font-base;
  950. color: $font-color-dark;
  951. padding: 20rpx 0;
  952. }
  953. .bot {
  954. display: flex;
  955. justify-content: space-between;
  956. font-size: $font-sm;
  957. color: $font-color-light;
  958. }
  959. }
  960. }
  961. .eva-boxs {
  962. width: 100%;
  963. overflow: hidden;
  964. padding: 10px 28rpx;
  965. background: #f4f4f4;
  966. border-radius: 12rpx;
  967. font-size: $font-sm + 2rpx;
  968. color: #333;
  969. .portrait {
  970. flex-shrink: 0;
  971. width: 80rpx;
  972. height: 80rpx;
  973. border-radius: 100px;
  974. }
  975. .right {
  976. flex: 1;
  977. display: flex;
  978. flex-direction: column;
  979. font-size: $font-base;
  980. color: $font-color-base;
  981. .con {
  982. font-size: $font-base;
  983. color: $font-color-dark;
  984. }
  985. .bot {
  986. display: flex;
  987. justify-content: space-between;
  988. font-size: $font-sm;
  989. color: $font-color-light;
  990. }
  991. }
  992. }
  993. /* 详情 */
  994. .detail-desc {
  995. background: #fff;
  996. margin-top: 16rpx;
  997. /deep/ img {
  998. max-width: 100% !important;
  999. display: inline !important;
  1000. }
  1001. /deep/ div {
  1002. max-width: 100% !important;
  1003. }
  1004. .d-header {
  1005. display: flex;
  1006. justify-content: center;
  1007. align-items: center;
  1008. height: 80rpx;
  1009. font-size: $font-base + 2rpx;
  1010. color: $font-color-dark;
  1011. position: relative;
  1012. text {
  1013. padding: 0 20rpx;
  1014. background: #fff;
  1015. position: relative;
  1016. z-index: 1;
  1017. }
  1018. &:after {
  1019. position: absolute;
  1020. left: 50%;
  1021. top: 50%;
  1022. transform: translateX(-50%);
  1023. width: 300rpx;
  1024. height: 0;
  1025. content: '';
  1026. border-bottom: 1px solid #ccc;
  1027. }
  1028. }
  1029. }
  1030. /* 规格选择弹窗 */
  1031. .attr-content {
  1032. padding: 10rpx 30rpx;
  1033. .a-t {
  1034. display: flex;
  1035. image {
  1036. width: 170rpx;
  1037. height: 170rpx;
  1038. flex-shrink: 0;
  1039. margin-top: -40rpx;
  1040. border-radius: 8rpx;
  1041. }
  1042. .right {
  1043. display: flex;
  1044. flex-direction: column;
  1045. padding-left: 24rpx;
  1046. font-size: $font-sm + 2rpx;
  1047. color: $font-color-base;
  1048. line-height: 42rpx;
  1049. .good-name {
  1050. padding-top: 20rpx;
  1051. max-width: 320rpx;
  1052. font-size: 30rpx;
  1053. font-family: PingFang SC;
  1054. font-weight: bold;
  1055. color: #1D2023;
  1056. line-height: 42rpx;
  1057. margin-bottom: 15rpx;
  1058. }
  1059. .price {
  1060. font-size: 60rpx;
  1061. font-family: PingFang SC;
  1062. font-weight: bold;
  1063. color: #FF6F0F;
  1064. // font-size: $font-lg;
  1065. // color: $uni-color-primary;
  1066. // margin-bottom: 10rpx;
  1067. }
  1068. .selected-text {
  1069. margin-right: 10rpx;
  1070. }
  1071. }
  1072. }
  1073. .attr-list {
  1074. display: flex;
  1075. flex-direction: column;
  1076. font-size: $font-base + 2rpx;
  1077. color: $font-color-base;
  1078. padding-top: 30rpx;
  1079. padding-left: 10rpx;
  1080. }
  1081. .item-list {
  1082. padding: 20rpx 0 0;
  1083. display: flex;
  1084. flex-wrap: wrap;
  1085. text {
  1086. display: flex;
  1087. align-items: center;
  1088. justify-content: center;
  1089. background: #eee;
  1090. margin-right: 20rpx;
  1091. margin-bottom: 20rpx;
  1092. border-radius: 100rpx;
  1093. min-width: 60rpx;
  1094. height: 60rpx;
  1095. padding: 0 20rpx;
  1096. font-size: $font-base;
  1097. color: $font-color-dark;
  1098. }
  1099. .selected {
  1100. background: #fbebee;
  1101. color: $uni-color-primary;
  1102. }
  1103. }
  1104. }
  1105. /* 弹出层 */
  1106. .popup {
  1107. position: fixed;
  1108. left: 0;
  1109. top: 0;
  1110. right: 0;
  1111. bottom: 0;
  1112. z-index: 99;
  1113. &.show {
  1114. display: block;
  1115. .mask {
  1116. animation: showPopup 0.2s linear both;
  1117. }
  1118. .layer {
  1119. animation: showLayer 0.2s linear both;
  1120. }
  1121. }
  1122. &.hide {
  1123. .mask {
  1124. animation: hidePopup 0.2s linear both;
  1125. }
  1126. .layer {
  1127. animation: hideLayer 0.2s linear both;
  1128. }
  1129. }
  1130. &.none {
  1131. display: none;
  1132. }
  1133. .mask {
  1134. position: fixed;
  1135. top: 0;
  1136. width: 100%;
  1137. height: 100%;
  1138. z-index: 1;
  1139. background-color: rgba(0, 0, 0, 0.4);
  1140. }
  1141. .layer {
  1142. position: fixed;
  1143. z-index: 99;
  1144. bottom: 0;
  1145. width: 100%;
  1146. min-height: 30vh;
  1147. border-radius: 10rpx 10rpx 0 0;
  1148. background-color: #fff;
  1149. .btn {
  1150. height: 66rpx;
  1151. line-height: 66rpx;
  1152. border-radius: 100rpx;
  1153. // background: $uni-color-primary;
  1154. background: $base-color;
  1155. font-size: $font-base + 2rpx;
  1156. color: #fff;
  1157. margin: 30rpx auto 20rpx;
  1158. }
  1159. }
  1160. @keyframes showPopup {
  1161. 0% {
  1162. opacity: 0;
  1163. }
  1164. 100% {
  1165. opacity: 1;
  1166. }
  1167. }
  1168. @keyframes hidePopup {
  1169. 0% {
  1170. opacity: 1;
  1171. }
  1172. 100% {
  1173. opacity: 0;
  1174. }
  1175. }
  1176. @keyframes showLayer {
  1177. 0% {
  1178. transform: translateY(120%);
  1179. }
  1180. 100% {
  1181. transform: translateY(0%);
  1182. }
  1183. }
  1184. @keyframes hideLayer {
  1185. 0% {
  1186. transform: translateY(0);
  1187. }
  1188. 100% {
  1189. transform: translateY(120%);
  1190. }
  1191. }
  1192. }
  1193. /* 底部操作菜单 */
  1194. .page-bottom {
  1195. position: fixed;
  1196. left: 0rpx;
  1197. bottom: 0rpx;
  1198. z-index: 95;
  1199. display: flex;
  1200. justify-content: center;
  1201. align-items: center;
  1202. width: 750rpx;
  1203. height: 98rpx;
  1204. background: rgba(255, 255, 255, 0.9);
  1205. box-shadow: 0 0 20rpx 0 rgba(0, 0, 0, 0.5);
  1206. // border-radius: 16rpx;
  1207. .p-b-btn {
  1208. display: flex;
  1209. flex-direction: column;
  1210. align-items: center;
  1211. justify-content: center;
  1212. font-size: $font-sm;
  1213. color: $font-color-base;
  1214. width: 100rpx;
  1215. height: 98rpx;
  1216. .iconfont {
  1217. font-size: 40rpx;
  1218. line-height: 48rpx;
  1219. color: $font-color-light;
  1220. }
  1221. &.active,
  1222. &.active .iconfont {
  1223. color: $uni-color-primary;
  1224. }
  1225. .icon-fenxiang2 {
  1226. font-size: 42rpx;
  1227. transform: translateY(-2rpx);
  1228. }
  1229. .iconlikefill {
  1230. font-size: 46rpx;
  1231. }
  1232. }
  1233. .action-btn-group {
  1234. display: flex;
  1235. height: 98rpx;
  1236. // border-radius: 100px;
  1237. overflow: hidden;
  1238. // margin-left: 20rpx;
  1239. position: relative;
  1240. // &:after {
  1241. // content: '';
  1242. // position: absolute;
  1243. // top: 50%;
  1244. // right: 50%;
  1245. // transform: translateY(-50%);
  1246. // height: 28rpx;
  1247. // width: 0;
  1248. // border-right: 1px solid rgba(255, 255, 255, 0.5);
  1249. // }
  1250. .action-btn {
  1251. display: flex;
  1252. align-items: center;
  1253. justify-content: center;
  1254. width: 350rpx;
  1255. height: 100%;
  1256. font-size: $font-base;
  1257. padding: 0;
  1258. border-radius: 0;
  1259. // background: transparent;
  1260. background: #31332D;
  1261. &.buy-now-btn {
  1262. background-color: #303e49;
  1263. }
  1264. &.add-cart-btn {
  1265. background-color: $base-color;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. // 商店头
  1271. .shop-box {
  1272. background-color: #ffffff;
  1273. margin-top: 20rpx;
  1274. margin-bottom: 10rpx;
  1275. padding: 20rpx;
  1276. .shop-img {
  1277. border-radius: 300rpx;
  1278. height: 80rpx;
  1279. width: 80rpx;
  1280. margin-right: 20rpx;
  1281. }
  1282. .shop-button {
  1283. border-radius: 100rpx;
  1284. padding: 10rpx 20rpx;
  1285. color: $color-red;
  1286. border: 1px solid $color-red;
  1287. font-size: $font-lg;
  1288. line-height: 1;
  1289. }
  1290. }
  1291. </style>