productdetails.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="产品详情"
  5. :placeholder="true"
  6. :autoBack="false"
  7. @leftClick="leftClick"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <u-loading-page :loading="loadingPage"></u-loading-page>
  12. <u-swiper
  13. v-if="details.slideImgList.length>0"
  14. :list="details.slideImgList"
  15. height="700rpx"
  16. @change="e => currentNum = e.current"
  17. :autoplay="false"
  18. indicatorStyle="right: 20px"
  19. >
  20. <view
  21. slot="indicator"
  22. class="indicator-num"
  23. >
  24. <text class="indicator-num__text">{{ currentNum + 1 }}/{{ details.slideImgList.length }}</text>
  25. </view>
  26. </u-swiper>
  27. <view class="product-info view-wrap">
  28. <view class="red">
  29. <view class="" v-if="vuex_member_info.priceType>1">
  30. <text class="price">¥ <text class="price-num">{{details.vipPrice}}</text></text>
  31. <text class="vip-icon">VIP</text>
  32. <text class="exchangeCredit" v-if="details.isCredit==1">+{{details.exchangeCredit}}积分</text>
  33. </view>
  34. <view class="" v-else>
  35. <text v-if="details.isCredit==1&&details.exchangeType==0" class="price">¥ <text class="price-num">0</text></text>
  36. <text v-else class="price">¥ <text class="price-num">{{details.salePrice}}</text></text>
  37. <text class="exchangeCredit" v-if="details.isCredit==1">+{{details.exchangeCredit}}积分</text>
  38. </view>
  39. </view>
  40. <view class="u-flex u-row-between gray">
  41. <text v-if="vuex_member_info.priceType>1" class="line-through">¥ <text class="">{{details.salePrice}}</text></text>
  42. <text class="">库存 {{details.stock}}</text>
  43. </view>
  44. <view class="name">{{details.goodsName}}</view>
  45. </view>
  46. <view class="specification info-line u-flex view-wrap" v-if="details.specification">
  47. <view class="info-til">规格</view>
  48. <view class="info-con u-flex">{{details.specification}}</view>
  49. </view>
  50. <view class="addr view-wrap">
  51. <view class="addr-line u-flex">
  52. <view class="info-til">快递</view>
  53. <view class="info-con u-flex">
  54. 包邮
  55. </view>
  56. </view>
  57. <view class="addr-line u-flex" v-if="details.period">
  58. <view class="info-til">保质期</view>
  59. <view class="info-con u-flex">
  60. {{details.period|filterPeriod}}
  61. </view>
  62. </view>
  63. <!-- <view class="addr-line u-flex">
  64. <text class="addr-til">送至</text>
  65. <view class="addr-con u-flex u-flex-1">
  66. <view class="u-flex u-row-between u-flex-1">
  67. <text>贵阳市 南明区</text>
  68. <u-icon name="arrow-right" color="#676767" size="20"></u-icon>
  69. </view>
  70. </view>
  71. </view> -->
  72. </view>
  73. <view class="comment view-wrap u-flex u-row-between">
  74. <view class="left">
  75. <text class="til">评价</text>
  76. <text class="num">({{details.commentNum}})</text>
  77. </view>
  78. <view class="right u-flex" @click="$u.route('/shopping/comment',{id:details.id})">
  79. <text>查看全部</text>
  80. <u-icon name="arrow-right" color="#676767" size="20"></u-icon>
  81. </view>
  82. </view>
  83. <view class="detail view-wrap">
  84. <view class="til">详情</view>
  85. <view class="con">
  86. <!-- <view class="" v-html="details.detail"></view> -->
  87. <u-parse :content="details.detail"></u-parse>
  88. <!-- {{details.detail}} -->
  89. </view>
  90. </view>
  91. <view class="details-tool-wrap">
  92. <view class="details-tool u-flex u-row-between">
  93. <view class="left u-flex">
  94. <view class="icon-wrap" @click="shareShow=true">
  95. <u-icon name="share" color="#676767" size="30"></u-icon>
  96. 分享
  97. <!-- <button class="share-btn" data-name="shareBtn" open-type="share">
  98. <u-icon name="share" color="#676767" size="30"></u-icon>
  99. 分享
  100. </button> -->
  101. </view>
  102. <view class="icon-wrap" v-if="details.isCredit!=1" @click="$u.route('/shopping/cart')">
  103. <u-icon name="shopping-cart" color="#676767" size="30"></u-icon>
  104. 购物车
  105. <u-badge class="badge" numberType="overflow" type="error " max="99" :value="cartTotal" :absolute="true" :offset="[0,0]"></u-badge>
  106. </view>
  107. </view>
  108. <view class="right" v-if="details.stock>0">
  109. <view class="u-flex" v-if="details.isCredit==1">
  110. <view class="btn add-btn" @click="addCreditOrder(details.id)">立即兑换</view>
  111. </view>
  112. <view class=" u-flex" v-else>
  113. <view class="btn add-btn" @click="addCart(details.id)">加入购物车</view>
  114. <view class="btn buy-btn" @click="buyNow(details.id)">立即购买</view>
  115. </view>
  116. </view>
  117. <view class="right" v-else>
  118. <view class="btn gray">暂无库存</view>
  119. </view>
  120. </view>
  121. </view>
  122. <!-- 分享选择弹出内容 -->
  123. <view class="share-option" :class="{shareShow:shareShow}">
  124. <view class="overlay" v-if="shareShow" @click="shareShow=false"></view>
  125. <button class="share-option-item wx-share" data-name="shareBtn" open-type="share">
  126. 发送给朋友
  127. </button>
  128. <view class="share-option-item" @click="getPoster">生成海报</view>
  129. <view class="share-option-item" @click="shareShow=false">取消</view>
  130. </view>
  131. <u-popup :show="posterShow" @close="posterShow=false" ref="uni-popup">
  132. <view class="poster-wrap u-flex u-col-center">
  133. <view class="poster-inner">
  134. <view class="close-wrap" @click="posterShow=false">
  135. <u-icon name="close-circle" color="#fff" size="56rpx"></u-icon>
  136. </view>
  137. <view class="poster" id="poster" ref="poster" >
  138. <img class="poster-bg" :src="staticUrl+'/img/poster-bg.png'" alt="">
  139. <img class="placard" :src="details.placard" alt="">
  140. <!-- <u--image :showLoading="true" :src="details.placard" width="100%" mode="widthFix"></u--image> -->
  141. <view class="bottom u-flex u-row-between">
  142. <view class="left">
  143. <view class="price">
  144. ¥<text class="num">{{details.salePrice}}</text>
  145. </view>
  146. <view class="goods-name ellipsis-2">{{details.goodsName}}</view>
  147. <view class="slogan" v-if="details.slogan" :style="{color:details.sloganColor||'#00A447'}">{{details.slogan}}</view>
  148. </view>
  149. <view class="right">
  150. <u--image :showLoading="true" :src="details.qrcodeUrl" width="108rpx" height="108rpx"></u--image>
  151. <view class="img-tip">长按扫码购买</view>
  152. </view>
  153. </view>
  154. </view>
  155. <view class="poster-btn" @click="savePoster">保存图片</view>
  156. </view>
  157. </view>
  158. </u-popup>
  159. <u-toast ref="uToast"></u-toast>
  160. </view>
  161. </template>
  162. <script>
  163. export default {
  164. data() {
  165. return {
  166. staticUrl:this.$commonConfig.staticUrl,
  167. loadingPage:true,
  168. id:'',
  169. cartTotal:0,
  170. currentNum:0,
  171. swiperList: [],
  172. details:{
  173. slideImgList:[]
  174. },
  175. hasAddr:false,
  176. shareShow:false,
  177. posterShow:true
  178. }
  179. },
  180. onLoad(page) {
  181. this.id = page.id;
  182. // console.log('this.id',this.id);
  183. this.getDetails(this.id);
  184. },
  185. onShow(){
  186. this.getCartList();
  187. this.getAddrList();
  188. this.goodsAddView(this.id)
  189. },
  190. methods: {
  191. leftClick(e){
  192. let pages = getCurrentPages();
  193. if(pages.length==1){
  194. uni.$u.route('/pages/index/index')
  195. }else{
  196. uni.navigateBack()
  197. };
  198. },
  199. getCartList(isAdd){
  200. this.$u.api.cartList().then(res=>{
  201. if(isAdd){
  202. if(res.data.total==this.cartTotal){
  203. this.$refs.uToast.show({
  204. type:"success",
  205. message:'已在购物车'
  206. });
  207. }
  208. }
  209. this.cartTotal = res.data.total;
  210. console.log('getCartList',res);
  211. }).catch(err=>{
  212. console.log('getCartList',err.data);
  213. })
  214. },
  215. getDetails(id){
  216. this.$u.api.memberGoodDetails({id:id}).then(res=>{
  217. this.loadingPage = false;
  218. console.log('res',res.data);
  219. this.details = res.data;
  220. if(!res.data.slideImgList&&res.data.mainImg){
  221. this.details.slideImgList = [];
  222. this.details.slideImgList.push(res.data.mainImg)
  223. }
  224. }).catch(err=>{
  225. console.log('getDetails',err.data);
  226. })
  227. },
  228. goodsAddView(id){
  229. this.$u.api.goodsAddView({id:id}).then(res=>{
  230. // console.log('res',res.data);
  231. }).catch(err=>{
  232. console.log('goodsAddView',err.data);
  233. })
  234. },
  235. async addCart(id,buyNow){
  236. try {
  237. let authResult = await this.checkAuth();
  238. console.log('实名认证结果:', authResult);
  239. // 在此处可以继续执行需要进行实名认证的业务逻辑
  240. // 例如下单购买商品等操作
  241. } catch (err) {
  242. console.log('实名认证未通过:', err);
  243. return
  244. // 在此处可以处理用户未通过实名认证的情况
  245. // 例如返回上一页或者跳转到实名认证页等操作
  246. }
  247. this.checkAuth();
  248. this.$u.api.addCart({goodsId:id}).then(res=>{
  249. this.$refs.uToast.show({
  250. type:"success",
  251. message:res.msg
  252. });
  253. if(buyNow){
  254. uni.$u.route('/shopping/cart', {
  255. buyNowId: id,
  256. buyNowName:this.details.goodsName
  257. });
  258. }
  259. this.getCartList('isAdd');
  260. console.log('res',res.data);
  261. }).catch(err=>{
  262. console.log('addCart',err);
  263. })
  264. },
  265. async buyNow(id){
  266. try {
  267. let authResult = await this.checkAuth();
  268. console.log('实名认证结果:', authResult);
  269. // 在此处可以继续执行需要进行实名认证的业务逻辑
  270. // 例如下单购买商品等操作
  271. } catch (err) {
  272. console.log('实名认证未通过:', err);
  273. return
  274. // 在此处可以处理用户未通过实名认证的情况
  275. // 例如返回上一页或者跳转到实名认证页等操作
  276. }
  277. // this.addCart(id,'buyNow')//跳购物车
  278. let that = this;
  279. if(!this.hasAddr){
  280. uni.showModal({
  281. title: '温馨提示',
  282. content: '请先设置地址!',
  283. success: res => {
  284. if (res.confirm) {
  285. let url = encodeURIComponent(`/shopping/productdetails?id=${that.id}`) ;
  286. uni.$u.route('/center/addrlist', {
  287. from: 'productdetails',
  288. backUrl:url
  289. });
  290. }
  291. }
  292. })
  293. return
  294. }
  295. this.$u.vuex('buyNowGoods',[{goodsId:this.id,quantity:1}]);
  296. uni.$u.route('/shopping/submitorder', {fromPage: 'productdetails'});
  297. },
  298. async addCreditOrder(id){
  299. try {
  300. let authResult = await this.checkAuth();
  301. console.log('实名认证结果:', authResult);
  302. // 在此处可以继续执行需要进行实名认证的业务逻辑
  303. // 例如下单购买商品等操作
  304. } catch (err) {
  305. console.log('实名认证未通过:', err);
  306. return
  307. // 在此处可以处理用户未通过实名认证的情况
  308. // 例如返回上一页或者跳转到实名认证页等操作
  309. }
  310. let that = this;
  311. let creditGoods = [];
  312. creditGoods.push({id:that.details.id,quantity:1})
  313. // console.log('creditGoods',creditGoods);
  314. that.$u.vuex('cartGoods',creditGoods);
  315. uni.$u.route('/shopping/submitorder', {fromPage:'creditOrder'});
  316. },
  317. onShareAppMessage: function( options ){
  318. var that = this;
  319. // 设置菜单中的转发按钮触发转发事件时的转发内容
  320. var shareObj = {
  321. title: this.details.goodsName, // 默认是小程序的名称(可以写slogan等)
  322. path: '/shopping/productdetails', // 默认是当前页面,必须是以‘/'开头的完整路径
  323. imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  324. success: function(res){
  325. // 转发成功之后的回调
  326. if(res.errMsg == 'shareAppMessage:ok'){
  327. }
  328. },
  329. fail: function(){
  330. // 转发失败之后的回调
  331. if(res.errMsg == 'shareAppMessage:fail cancel'){
  332. // 用户取消转发
  333. }else if(res.errMsg == 'shareAppMessage:fail'){
  334. // 转发失败,其中 detail message 为详细失败信息
  335. }
  336. },
  337. complete:function(){
  338. // 转发结束之后的回调(转发成不成功都会执行)
  339. }
  340. };
  341. // 来自页面内的按钮的转发
  342. if( options.from == 'button' ){
  343. var eData = options.target.dataset;
  344. console.log('options.target.dataset',options.target.dataset);
  345. console.log('id' ,this.details.id); // shareBtn
  346. // 此处可以修改 shareObj 中的内容
  347. shareObj.path = '/shopping/productdetails?id='+this.details.id;
  348. }
  349. // 返回shareObj
  350. return shareObj;
  351. },
  352. getAddrList(){
  353. this.$u.api.addrList().then(res=>{
  354. // this.dataList = res.data.rows;
  355. console.log('getAddrList',res);
  356. if( res.data.total>0){
  357. this.hasAddr = true;
  358. }else{
  359. this.hasAddr = false;
  360. }
  361. }).catch(err=>{
  362. console.log('getAddrList',err.data);
  363. })
  364. },
  365. checkAuth() {
  366. // console.log('details-----',this.details);
  367. let that = this;
  368. return new Promise((resolve, reject) => {
  369. console.log('vuex_member_info', this.vuex_member_info.isAuth);
  370. if (that.details.isBuy&&that.details.isBuy!=1) {
  371. uni.showModal({
  372. title: '温馨提示',
  373. content: '购买该商品需要实名认证,请先实名认证!',
  374. success: res => {
  375. if (res.confirm) {
  376. let url = encodeURIComponent(`/shopping/productdetails?id=${that.id}`);
  377. uni.$u.route('/center/factorauth', {
  378. from: 'productdetails',
  379. backUrl: url
  380. });
  381. reject('needAuth'); // 实名认证未通过,使用 reject 方法返回结果
  382. }
  383. }
  384. });
  385. } else {
  386. resolve('noNeedAuth'); // 实名认证已通过,使用 resolve 方法返回结果
  387. }
  388. });
  389. },
  390. getPoster(){
  391. this.posterShow = true;
  392. this.shareShow = false;
  393. },
  394. savePoster(){
  395. console.log('savePoster');
  396. }
  397. }
  398. }
  399. </script>
  400. <style lang="scss" scoped>
  401. .indicator-num {
  402. padding: 2px 0;
  403. background-color: rgba(0, 0, 0, 0.35);
  404. border-radius: 100px;
  405. width: 35px;
  406. @include flex;
  407. justify-content: center;
  408. &__text {
  409. color: #FFFFFF;
  410. font-size: 12px;
  411. }
  412. }
  413. .product-info{
  414. .price-num{
  415. font-size: 60rpx;
  416. }
  417. .exchangeCredit{
  418. font-size: 60rpx;
  419. }
  420. .name{
  421. margin-top: 30rpx;
  422. font-size: 36rpx;
  423. font-weight: 600;
  424. color: #333;
  425. line-height: 50rpx;
  426. }
  427. }
  428. .info-line{
  429. margin-bottom: 20rpx;
  430. }
  431. .info-til{
  432. color: #999;
  433. margin-right: 40rpx;
  434. }
  435. .info-con{
  436. color: #666;
  437. }
  438. .addr{
  439. font-size: 30rpx;
  440. .addr-line:not(:last-child){
  441. margin-bottom: 20rpx;
  442. }
  443. }
  444. .comment{
  445. color: #999;
  446. .til{
  447. font-size: 30rpx;
  448. font-weight: 600;
  449. margin-right: 20rpx;
  450. color: #333;
  451. }
  452. }
  453. .detail{
  454. .til{
  455. font-size: 30rpx;
  456. color: #333;
  457. font-weight: 600;
  458. margin-bottom: 20rpx;
  459. }
  460. .con{
  461. // background-color: #F5F5F5;
  462. img{max-width: 100%;}
  463. }
  464. }
  465. .details-tool-wrap{
  466. height: 98rpx;
  467. .details-tool{
  468. position: fixed;
  469. left: 0;
  470. right: 0;
  471. bottom: 0;
  472. height: 98rpx;
  473. background-color: #fff;
  474. }
  475. .left{
  476. text-align: center;
  477. color: #666;
  478. font-size: 24rpx;
  479. .icon-wrap{
  480. position: relative;
  481. margin-left: 20rpx;
  482. }
  483. }
  484. .right{
  485. .btn{
  486. padding: 19rpx 40rpx;
  487. border-radius: 40rpx;
  488. color: #fff;
  489. margin-right: 20rpx;
  490. }
  491. .add-btn{
  492. background-color: #FFB100;
  493. }
  494. .buy-btn{
  495. background-color: #FF3C3F;
  496. }
  497. .gray{
  498. background-color: #ddd;
  499. color: #999;
  500. }
  501. }
  502. .share-btn{
  503. padding: 0;
  504. margin: 0;
  505. border: 0;
  506. font-size: 24rpx;
  507. color: #666;
  508. line-height: 1;
  509. background-color: transparent;
  510. outline: none;
  511. &::after{
  512. border: none;
  513. }
  514. }
  515. }
  516. .share-option{
  517. transform: translateY(100%);
  518. .overlay{
  519. position: fixed;
  520. left: 0;
  521. top: 0;
  522. width: 100vw;
  523. height: 100vh;
  524. background-color: rgba(0, 0, 0, 0.35);
  525. transform: translateY(-100%);
  526. }
  527. &.shareShow{
  528. transform: translateY(0);
  529. }
  530. position: fixed;
  531. width: 100%;
  532. left: 0;
  533. bottom: 0;
  534. z-index: 50;
  535. background-color: #fff;
  536. .share-option-item{
  537. position: relative;
  538. height: 46px;
  539. line-height: 46px;
  540. border: 0;
  541. background-color: #fff;
  542. text-align: center;
  543. border-radius: 0;
  544. border-bottom: 1px solid #eee;
  545. font-size: 30rpx;
  546. }
  547. .wx-share{
  548. border-bottom: 0;
  549. }
  550. }
  551. .poster-wrap{
  552. position: fixed;
  553. left: 0;
  554. top: 0;
  555. width: 100%;
  556. height: 100vh;
  557. .poster-inner{
  558. flex: 1;
  559. margin: 0 75rpx;
  560. .close-wrap{
  561. display: flex;
  562. justify-content: flex-end;
  563. margin-bottom: 16rpx;
  564. }
  565. }
  566. .poster{
  567. position: relative;
  568. padding-bottom: 90rpx;
  569. background-color: #fff;
  570. .poster-bg{
  571. position: absolute;
  572. left: 0;
  573. bottom: 0;
  574. right: 0;
  575. width: 100%;
  576. z-index: 1;
  577. }
  578. .placard{
  579. position: relative;
  580. z-index: 10;
  581. }
  582. .bottom{
  583. position: relative;
  584. z-index: 20;
  585. margin: 33rpx 40rpx 0;
  586. .left{
  587. margin-right: 58rpx;
  588. .price{
  589. font-size: 22rpx;
  590. font-weight: 600;
  591. color: #FF3538;
  592. line-height: 30rpx;
  593. margin-bottom: 10rpx;
  594. .num{
  595. font-size: 40rpx;
  596. font-weight: 600;
  597. margin-left: 5rpx;
  598. }
  599. }
  600. .goods-name{
  601. font-size: 30rpx;
  602. font-weight: 400;
  603. color: #333333;
  604. line-height: 38rpx;
  605. margin-bottom: 16rpx;
  606. }
  607. .slogan{
  608. font-size: 26rpx;
  609. font-weight: 600;
  610. line-height: 37rpx;
  611. }
  612. }
  613. .right{
  614. text-align: center;
  615. .img-tip{
  616. margin-top: 12rpx;
  617. font-size: 20rpx;
  618. font-weight: 400;
  619. color: #333333;
  620. line-height: 28rpx;
  621. }
  622. }
  623. }
  624. }
  625. .poster-btn{
  626. height: 88rpx;
  627. line-height: 88rpx;
  628. border-radius: 44rpx;
  629. text-align: center;
  630. color: #fff;
  631. margin-top: 40rpx;
  632. font-size: 32rpx;
  633. font-weight: 600;
  634. background: linear-gradient(90deg, #00DC84 0%, #00A447 100%);
  635. }
  636. }
  637. </style>