product.vue 32 KB

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