product.vue 34 KB

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