product.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  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(1)">
  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. console.log(1111);
  591. let data = {
  592. cartNum: obj.goodsNumber, //商品数量
  593. uniqueId: obj.uniqueId, //商品标签
  594. new: '1', //商品是否新增加到购物车1为不加入0为加入
  595. mer_id: obj.shopId,
  596. is_consumer: 0
  597. // type: 0,//0为余额支付 1为消费券支付 2为积分支付
  598. };
  599. if (obj.paying) {
  600. return;
  601. }
  602. obj.paying = true;
  603. if (obj.type == 2) {
  604. data.new = 0;
  605. }
  606. if (obj.goodsType == 0) {
  607. data.productId = obj.goodsid; //商品编号
  608. }
  609. // 判断是否为秒杀商品
  610. if (obj.goodsType == 1) {
  611. data.secKillId = obj.goodsid; //秒杀商品编号
  612. data.productId = obj.goodsObjact.product_id; //商品编号
  613. // 判断是否秒杀已经结束
  614. if (obj.seckillObj.stop) {
  615. uni.showModal({
  616. title: '提示',
  617. content: '当前活动已经结束',
  618. showCancel: false
  619. });
  620. return;
  621. }
  622. }
  623. // 判断是否为拼团商品
  624. if (obj.goodsType == 2) {
  625. data.combinationId = obj.goodsid; //拼团编号
  626. data.productId = obj.goodsObjact.product_id; //商品编号
  627. }
  628. cartAdd(data)
  629. .then(function({ data }) {
  630. obj.paying = false;
  631. if (obj.type == 1) {
  632. // 跳转到支付页
  633. uni.navigateTo({
  634. url: '/pages/order/createOrder?id=' + data.cartId + '&goodsType=' + obj.goodsType
  635. });
  636. }
  637. if (obj.type == 2) {
  638. uni.showToast({
  639. title: '成功加入购物车',
  640. type: 'top',
  641. duration: 2000
  642. });
  643. obj.toggleSpec();
  644. }
  645. })
  646. .catch(e => {
  647. obj.paying = false;
  648. console.log(e);
  649. });
  650. },
  651. stopPrevent() {}
  652. }
  653. };
  654. </script>
  655. <style lang="scss">
  656. page {
  657. background: $page-color-base;
  658. }
  659. //秒杀底部高度
  660. .seckillBottom {
  661. height: 110rpx;
  662. }
  663. // 文章页底部高度撑开
  664. .contentBottomHeight {
  665. height: 110rpx;
  666. }
  667. //默认商品底部高度
  668. .goodsBottom {
  669. height: 160rpx;
  670. }
  671. .iconenter {
  672. font-size: $font-base + 2rpx;
  673. color: #888;
  674. }
  675. .carousel {
  676. /* #ifdef APP-PLUS */
  677. padding-top: var(--status-bar-height);
  678. /* #endif */
  679. height: 722rpx;
  680. position: relative;
  681. swiper {
  682. height: 100%;
  683. }
  684. .image-wrapper {
  685. width: 100%;
  686. height: 100%;
  687. }
  688. .swiper-item {
  689. display: flex;
  690. justify-content: center;
  691. align-content: center;
  692. // height: 750rpx;
  693. height: 710rpx;
  694. overflow: hidden;
  695. image {
  696. width: 100%;
  697. height: 100%;
  698. }
  699. }
  700. }
  701. // 秒杀
  702. .seckill-box-title {
  703. background: linear-gradient(90deg, rgba(239, 78, 81, 1) 0%, rgba(244, 113, 59, 1) 100%) !important;
  704. .price,
  705. .price-tip,
  706. .timeStop,
  707. .m-price {
  708. color: #ffffff !important;
  709. }
  710. .price-tip {
  711. font-size: $font-base;
  712. }
  713. .price {
  714. font-size: 45rpx !important;
  715. font-weight: bold;
  716. }
  717. .timeStop {
  718. }
  719. }
  720. // 底部拼团、秒杀支付按钮
  721. .goods-pay-box {
  722. position: fixed;
  723. left: 0;
  724. bottom: 0;
  725. z-index: 95;
  726. width: 750rpx;
  727. height: 100rpx;
  728. line-height: 1;
  729. color: #ffffff;
  730. text-align: center;
  731. font-size: $font-lg;
  732. .bgLine {
  733. background: linear-gradient(90deg, rgba(239, 78, 81, 1) 0%, rgba(244, 113, 59, 1) 100%);
  734. }
  735. // 拼团支付按钮
  736. .goods-pay {
  737. display: flex;
  738. align-content: center;
  739. flex-wrap: wrap;
  740. justify-content: center;
  741. .goods-buttom,
  742. .goods-buttom-money {
  743. width: 100%;
  744. }
  745. .goods-buttom-money {
  746. font-size: $font-base;
  747. }
  748. }
  749. .goods-pay-stop,
  750. .goods-pay {
  751. padding: 15rpx 0;
  752. height: 100%;
  753. width: 100%;
  754. }
  755. .goods-pay-stop {
  756. background: $color-gray;
  757. line-height: 70rpx;
  758. }
  759. }
  760. /* 标题简介 */
  761. .introduce-section {
  762. background: #fff;
  763. padding: 20rpx 30rpx;
  764. .title {
  765. font-size: 32rpx;
  766. color: $font-color-dark;
  767. height: 50rpx;
  768. line-height: 50rpx;
  769. }
  770. .price-box {
  771. display: flex;
  772. align-items: baseline;
  773. height: 64rpx;
  774. padding: 10rpx 0;
  775. font-size: 26rpx;
  776. color: $uni-color-primary;
  777. }
  778. .price {
  779. font-size: $font-lg + 2rpx;
  780. }
  781. .m-price {
  782. margin: 0 12rpx;
  783. color: $font-color-light;
  784. text-decoration: line-through;
  785. }
  786. .coupon-tip {
  787. align-items: center;
  788. padding: 4rpx 10rpx;
  789. background: $uni-color-primary;
  790. font-size: $font-sm;
  791. color: #fff;
  792. border-radius: 6rpx;
  793. line-height: 1;
  794. transform: translateY(-4rpx);
  795. }
  796. .bot-row {
  797. display: flex;
  798. align-items: center;
  799. height: 50rpx;
  800. font-size: $font-sm;
  801. color: $font-color-light;
  802. text {
  803. flex: 1;
  804. }
  805. }
  806. }
  807. /* 分享 */
  808. .share-section {
  809. display: flex;
  810. align-items: center;
  811. color: $font-color-base;
  812. background: linear-gradient(left, #fdf5f6, #fbebf6);
  813. padding: 12rpx 30rpx;
  814. .share-icon {
  815. display: flex;
  816. align-items: center;
  817. width: 70rpx;
  818. height: 30rpx;
  819. line-height: 1;
  820. border: 1px solid $uni-color-primary;
  821. border-radius: 4rpx;
  822. position: relative;
  823. overflow: hidden;
  824. font-size: 22rpx;
  825. color: $uni-color-primary;
  826. &:after {
  827. content: '';
  828. width: 50rpx;
  829. height: 50rpx;
  830. border-radius: 50%;
  831. left: -20rpx;
  832. top: -12rpx;
  833. position: absolute;
  834. background: $uni-color-primary;
  835. }
  836. }
  837. .iconfavorfill {
  838. position: relative;
  839. z-index: 1;
  840. font-size: 24rpx;
  841. margin-left: 2rpx;
  842. margin-right: 10rpx;
  843. color: #fff;
  844. line-height: 1;
  845. }
  846. .tit {
  847. font-size: $font-base;
  848. margin-left: 10rpx;
  849. }
  850. .iconprompt {
  851. padding: 10rpx;
  852. font-size: 30rpx;
  853. line-height: 1;
  854. }
  855. .share-btn {
  856. flex: 1;
  857. text-align: right;
  858. font-size: $font-sm;
  859. color: $uni-color-primary;
  860. }
  861. .iconenter {
  862. font-size: $font-sm;
  863. margin-left: 4rpx;
  864. color: $uni-color-primary;
  865. }
  866. }
  867. .c-list {
  868. margin-top: 20rpx;
  869. font-size: $font-sm + 2rpx;
  870. color: $font-color-base;
  871. background: #fff;
  872. .c-row {
  873. display: flex;
  874. align-items: center;
  875. padding: 20rpx 30rpx;
  876. position: relative;
  877. }
  878. .tit {
  879. width: 140rpx;
  880. }
  881. .con {
  882. flex: 1;
  883. color: $font-color-dark;
  884. .selected-text {
  885. margin-right: 10rpx;
  886. }
  887. }
  888. .bz-list {
  889. height: 40rpx;
  890. font-size: $font-sm + 2rpx;
  891. color: $font-color-dark;
  892. text {
  893. display: inline-block;
  894. margin-right: 30rpx;
  895. }
  896. }
  897. .con-list {
  898. flex: 1;
  899. display: flex;
  900. flex-direction: column;
  901. color: $font-color-dark;
  902. line-height: 40rpx;
  903. }
  904. .red {
  905. color: $uni-color-primary;
  906. }
  907. }
  908. /* 评价 */
  909. .eva-section {
  910. display: flex;
  911. flex-direction: column;
  912. padding: 20rpx 30rpx;
  913. background: #fff;
  914. margin-top: 16rpx;
  915. .e-header {
  916. display: flex;
  917. align-items: center;
  918. height: 70rpx;
  919. font-size: $font-sm + 2rpx;
  920. color: $font-color-light;
  921. .tit {
  922. font-size: $font-base + 2rpx;
  923. color: $font-color-dark;
  924. margin-right: 4rpx;
  925. }
  926. .tip {
  927. flex: 1;
  928. text-align: right;
  929. }
  930. .iconenter {
  931. margin-left: 10rpx;
  932. }
  933. }
  934. }
  935. .eva-box {
  936. display: flex;
  937. padding: 20rpx 0;
  938. .portrait {
  939. flex-shrink: 0;
  940. width: 80rpx;
  941. height: 80rpx;
  942. border-radius: 100px;
  943. }
  944. .right {
  945. flex: 1;
  946. display: flex;
  947. flex-direction: column;
  948. font-size: $font-base;
  949. color: $font-color-base;
  950. padding-left: 26rpx;
  951. .con {
  952. font-size: $font-base;
  953. color: $font-color-dark;
  954. padding: 20rpx 0;
  955. }
  956. .bot {
  957. display: flex;
  958. justify-content: space-between;
  959. font-size: $font-sm;
  960. color: $font-color-light;
  961. }
  962. }
  963. }
  964. .eva-boxs {
  965. width: 100%;
  966. overflow: hidden;
  967. padding: 10px 28rpx;
  968. background: #f4f4f4;
  969. border-radius: 12rpx;
  970. font-size: $font-sm + 2rpx;
  971. color: #333;
  972. .portrait {
  973. flex-shrink: 0;
  974. width: 80rpx;
  975. height: 80rpx;
  976. border-radius: 100px;
  977. }
  978. .right {
  979. flex: 1;
  980. display: flex;
  981. flex-direction: column;
  982. font-size: $font-base;
  983. color: $font-color-base;
  984. .con {
  985. font-size: $font-base;
  986. color: $font-color-dark;
  987. }
  988. .bot {
  989. display: flex;
  990. justify-content: space-between;
  991. font-size: $font-sm;
  992. color: $font-color-light;
  993. }
  994. }
  995. }
  996. /* 详情 */
  997. .detail-desc {
  998. background: #fff;
  999. margin-top: 16rpx;
  1000. /deep/ img {
  1001. max-width: 100% !important;
  1002. display: inline !important;
  1003. }
  1004. /deep/ div {
  1005. max-width: 100% !important;
  1006. }
  1007. .d-header {
  1008. display: flex;
  1009. justify-content: center;
  1010. align-items: center;
  1011. height: 80rpx;
  1012. font-size: $font-base + 2rpx;
  1013. color: $font-color-dark;
  1014. position: relative;
  1015. text {
  1016. padding: 0 20rpx;
  1017. background: #fff;
  1018. position: relative;
  1019. z-index: 1;
  1020. }
  1021. &:after {
  1022. position: absolute;
  1023. left: 50%;
  1024. top: 50%;
  1025. transform: translateX(-50%);
  1026. width: 300rpx;
  1027. height: 0;
  1028. content: '';
  1029. border-bottom: 1px solid #ccc;
  1030. }
  1031. }
  1032. }
  1033. /* 规格选择弹窗 */
  1034. .attr-content {
  1035. padding: 10rpx 30rpx;
  1036. .a-t {
  1037. display: flex;
  1038. image {
  1039. width: 170rpx;
  1040. height: 170rpx;
  1041. flex-shrink: 0;
  1042. margin-top: -40rpx;
  1043. border-radius: 8rpx;
  1044. }
  1045. .right {
  1046. display: flex;
  1047. flex-direction: column;
  1048. padding-left: 24rpx;
  1049. font-size: $font-sm + 2rpx;
  1050. color: $font-color-base;
  1051. line-height: 42rpx;
  1052. .good-name {
  1053. padding-top: 20rpx;
  1054. max-width: 320rpx;
  1055. font-size: 30rpx;
  1056. font-family: PingFang SC;
  1057. font-weight: bold;
  1058. color: #1d2023;
  1059. line-height: 42rpx;
  1060. margin-bottom: 15rpx;
  1061. }
  1062. .price {
  1063. font-size: 60rpx;
  1064. font-family: PingFang SC;
  1065. font-weight: bold;
  1066. color: #ff6f0f;
  1067. // font-size: $font-lg;
  1068. // color: $uni-color-primary;
  1069. // margin-bottom: 10rpx;
  1070. }
  1071. .selected-text {
  1072. margin-right: 10rpx;
  1073. }
  1074. }
  1075. }
  1076. .attr-list {
  1077. display: flex;
  1078. flex-direction: column;
  1079. font-size: $font-base + 2rpx;
  1080. color: $font-color-base;
  1081. padding-top: 30rpx;
  1082. padding-left: 10rpx;
  1083. }
  1084. .item-list {
  1085. padding: 20rpx 0 0;
  1086. display: flex;
  1087. flex-wrap: wrap;
  1088. text {
  1089. display: flex;
  1090. align-items: center;
  1091. justify-content: center;
  1092. background: #eee;
  1093. margin-right: 20rpx;
  1094. margin-bottom: 20rpx;
  1095. border-radius: 100rpx;
  1096. min-width: 60rpx;
  1097. height: 60rpx;
  1098. padding: 0 20rpx;
  1099. font-size: $font-base;
  1100. color: $font-color-dark;
  1101. }
  1102. .selected {
  1103. background: #fbebee;
  1104. color: $uni-color-primary;
  1105. }
  1106. }
  1107. }
  1108. /* 弹出层 */
  1109. .popup {
  1110. position: fixed;
  1111. left: 0;
  1112. top: 0;
  1113. right: 0;
  1114. bottom: 0;
  1115. z-index: 99;
  1116. &.show {
  1117. display: block;
  1118. .mask {
  1119. animation: showPopup 0.2s linear both;
  1120. }
  1121. .layer {
  1122. animation: showLayer 0.2s linear both;
  1123. }
  1124. }
  1125. &.hide {
  1126. .mask {
  1127. animation: hidePopup 0.2s linear both;
  1128. }
  1129. .layer {
  1130. animation: hideLayer 0.2s linear both;
  1131. }
  1132. }
  1133. &.none {
  1134. display: none;
  1135. }
  1136. .mask {
  1137. position: fixed;
  1138. top: 0;
  1139. width: 100%;
  1140. height: 100%;
  1141. z-index: 1;
  1142. background-color: rgba(0, 0, 0, 0.4);
  1143. }
  1144. .layer {
  1145. position: fixed;
  1146. z-index: 99;
  1147. bottom: 0;
  1148. width: 100%;
  1149. min-height: 30vh;
  1150. border-radius: 10rpx 10rpx 0 0;
  1151. background-color: #fff;
  1152. .btn {
  1153. height: 66rpx;
  1154. line-height: 66rpx;
  1155. border-radius: 100rpx;
  1156. // background: $uni-color-primary;
  1157. background: $base-color;
  1158. font-size: $font-base + 2rpx;
  1159. color: #fff;
  1160. margin: 30rpx auto 20rpx;
  1161. }
  1162. }
  1163. @keyframes showPopup {
  1164. 0% {
  1165. opacity: 0;
  1166. }
  1167. 100% {
  1168. opacity: 1;
  1169. }
  1170. }
  1171. @keyframes hidePopup {
  1172. 0% {
  1173. opacity: 1;
  1174. }
  1175. 100% {
  1176. opacity: 0;
  1177. }
  1178. }
  1179. @keyframes showLayer {
  1180. 0% {
  1181. transform: translateY(120%);
  1182. }
  1183. 100% {
  1184. transform: translateY(0%);
  1185. }
  1186. }
  1187. @keyframes hideLayer {
  1188. 0% {
  1189. transform: translateY(0);
  1190. }
  1191. 100% {
  1192. transform: translateY(120%);
  1193. }
  1194. }
  1195. }
  1196. /* 底部操作菜单 */
  1197. .page-bottom {
  1198. position: fixed;
  1199. left: 0rpx;
  1200. bottom: 0rpx;
  1201. z-index: 95;
  1202. display: flex;
  1203. justify-content: center;
  1204. align-items: center;
  1205. width: 750rpx;
  1206. height: 98rpx;
  1207. background: rgba(255, 255, 255, 0.9);
  1208. box-shadow: 0 0 20rpx 0 rgba(0, 0, 0, 0.5);
  1209. // border-radius: 16rpx;
  1210. .p-b-btn {
  1211. display: flex;
  1212. flex-direction: column;
  1213. align-items: center;
  1214. justify-content: center;
  1215. font-size: $font-sm;
  1216. color: $font-color-base;
  1217. width: 100rpx;
  1218. height: 98rpx;
  1219. .iconfont {
  1220. font-size: 40rpx;
  1221. line-height: 48rpx;
  1222. color: $font-color-light;
  1223. }
  1224. &.active,
  1225. &.active .iconfont {
  1226. color: $uni-color-primary;
  1227. }
  1228. .icon-fenxiang2 {
  1229. font-size: 42rpx;
  1230. transform: translateY(-2rpx);
  1231. }
  1232. .iconlikefill {
  1233. font-size: 46rpx;
  1234. }
  1235. }
  1236. .action-btn-group {
  1237. display: flex;
  1238. height: 98rpx;
  1239. // border-radius: 100px;
  1240. overflow: hidden;
  1241. // margin-left: 20rpx;
  1242. position: relative;
  1243. // &:after {
  1244. // content: '';
  1245. // position: absolute;
  1246. // top: 50%;
  1247. // right: 50%;
  1248. // transform: translateY(-50%);
  1249. // height: 28rpx;
  1250. // width: 0;
  1251. // border-right: 1px solid rgba(255, 255, 255, 0.5);
  1252. // }
  1253. .action-btn {
  1254. display: flex;
  1255. align-items: center;
  1256. justify-content: center;
  1257. width: 350rpx;
  1258. height: 100%;
  1259. font-size: $font-base;
  1260. padding: 0;
  1261. border-radius: 0;
  1262. // background: transparent;
  1263. background: #31332d;
  1264. &.buy-now-btn {
  1265. background-color: #303e49;
  1266. }
  1267. &.add-cart-btn {
  1268. background-color: $base-color;
  1269. }
  1270. }
  1271. }
  1272. }
  1273. // 商店头
  1274. .shop-box {
  1275. background-color: #ffffff;
  1276. margin-top: 20rpx;
  1277. margin-bottom: 10rpx;
  1278. padding: 20rpx;
  1279. .shop-img {
  1280. border-radius: 300rpx;
  1281. height: 80rpx;
  1282. width: 80rpx;
  1283. margin-right: 20rpx;
  1284. }
  1285. .shop-button {
  1286. border-radius: 100rpx;
  1287. padding: 10rpx 20rpx;
  1288. color: $color-red;
  1289. border: 1px solid $color-red;
  1290. font-size: $font-lg;
  1291. line-height: 1;
  1292. }
  1293. }
  1294. </style>