product.vue 34 KB

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