product.vue 34 KB

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