productdetails.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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">
  95. <button class="share-btn" data-name="shareBtn" open-type="share">
  96. <u-icon name="share" color="#676767" size="30"></u-icon>
  97. 分享
  98. </button>
  99. </view>
  100. <view class="icon-wrap" v-if="details.isCredit!=1" @click="$u.route('/shopping/cart')">
  101. <u-icon name="shopping-cart" color="#676767" size="30"></u-icon>
  102. 购物车
  103. <u-badge class="badge" numberType="overflow" type="error " max="99" :value="cartTotal" :absolute="true" :offset="[0,0]"></u-badge>
  104. </view>
  105. </view>
  106. <view class="right" v-if="details.stock>0">
  107. <view class="u-flex" v-if="details.isCredit==1">
  108. <view class="btn add-btn" @click="addCreditOrder(details.id)">立即兑换</view>
  109. </view>
  110. <view class=" u-flex" v-else>
  111. <view class="btn add-btn" @click="addCart(details.id)">加入购物车</view>
  112. <view class="btn buy-btn" @click="buyNow(details.id)">立即购买</view>
  113. </view>
  114. </view>
  115. <view class="right" v-else>
  116. <view class="btn gray">暂无库存</view>
  117. </view>
  118. </view>
  119. </view>
  120. <u-toast ref="uToast"></u-toast>
  121. </view>
  122. </template>
  123. <script>
  124. export default {
  125. data() {
  126. return {
  127. loadingPage:true,
  128. id:'',
  129. cartTotal:0,
  130. currentNum:0,
  131. swiperList: [],
  132. details:{
  133. slideImgList:[]
  134. },
  135. hasAddr:false,
  136. }
  137. },
  138. onLoad(page) {
  139. this.id = page.id;
  140. // console.log('this.id',this.id);
  141. this.getDetails(this.id);
  142. },
  143. onShow(){
  144. this.getCartList();
  145. this.getAddrList();
  146. this.goodsAddView(this.id)
  147. },
  148. methods: {
  149. leftClick(e){
  150. let pages = getCurrentPages();
  151. if(pages.length==1){
  152. uni.$u.route('/pages/index/index')
  153. }else{
  154. uni.navigateBack()
  155. };
  156. },
  157. getCartList(isAdd){
  158. this.$u.api.cartList().then(res=>{
  159. if(isAdd){
  160. if(res.data.total==this.cartTotal){
  161. this.$refs.uToast.show({
  162. type:"success",
  163. message:'已在购物车'
  164. });
  165. }
  166. }
  167. this.cartTotal = res.data.total;
  168. console.log('getCartList',res);
  169. }).catch(err=>{
  170. console.log('getCartList',err.data);
  171. })
  172. },
  173. getDetails(id){
  174. this.$u.api.memberGoodDetails({id:id}).then(res=>{
  175. this.loadingPage = false;
  176. console.log('res',res.data);
  177. this.details = res.data;
  178. if(!res.data.slideImgList&&res.data.mainImg){
  179. this.details.slideImgList = [];
  180. this.details.slideImgList.push(res.data.mainImg)
  181. }
  182. }).catch(err=>{
  183. console.log('getDetails',err.data);
  184. })
  185. },
  186. goodsAddView(id){
  187. this.$u.api.goodsAddView({id:id}).then(res=>{
  188. // console.log('res',res.data);
  189. }).catch(err=>{
  190. console.log('goodsAddView',err.data);
  191. })
  192. },
  193. async addCart(id,buyNow){
  194. try {
  195. let authResult = await this.checkAuth();
  196. console.log('实名认证结果:', authResult);
  197. // 在此处可以继续执行需要进行实名认证的业务逻辑
  198. // 例如下单购买商品等操作
  199. } catch (err) {
  200. console.log('实名认证未通过:', err);
  201. return
  202. // 在此处可以处理用户未通过实名认证的情况
  203. // 例如返回上一页或者跳转到实名认证页等操作
  204. }
  205. this.checkAuth();
  206. this.$u.api.addCart({goodsId:id}).then(res=>{
  207. this.$refs.uToast.show({
  208. type:"success",
  209. message:res.msg
  210. });
  211. if(buyNow){
  212. uni.$u.route('/shopping/cart', {
  213. buyNowId: id,
  214. buyNowName:this.details.goodsName
  215. });
  216. }
  217. this.getCartList('isAdd');
  218. console.log('res',res.data);
  219. }).catch(err=>{
  220. console.log('addCart',err);
  221. })
  222. },
  223. async buyNow(id){
  224. try {
  225. let authResult = await this.checkAuth();
  226. console.log('实名认证结果:', authResult);
  227. // 在此处可以继续执行需要进行实名认证的业务逻辑
  228. // 例如下单购买商品等操作
  229. } catch (err) {
  230. console.log('实名认证未通过:', err);
  231. return
  232. // 在此处可以处理用户未通过实名认证的情况
  233. // 例如返回上一页或者跳转到实名认证页等操作
  234. }
  235. // this.addCart(id,'buyNow')//跳购物车
  236. let that = this;
  237. if(!this.hasAddr){
  238. uni.showModal({
  239. title: '温馨提示',
  240. content: '请先设置地址!',
  241. success: res => {
  242. if (res.confirm) {
  243. let url = encodeURIComponent(`/shopping/productdetails?id=${that.id}`) ;
  244. uni.$u.route('/center/addrlist', {
  245. from: 'productdetails',
  246. backUrl:url
  247. });
  248. }
  249. }
  250. })
  251. return
  252. }
  253. this.$u.vuex('buyNowGoods',[{goodsId:this.id,quantity:1}]);
  254. uni.$u.route('/shopping/submitorder', {fromPage: 'productdetails'});
  255. },
  256. async addCreditOrder(id){
  257. try {
  258. let authResult = await this.checkAuth();
  259. console.log('实名认证结果:', authResult);
  260. // 在此处可以继续执行需要进行实名认证的业务逻辑
  261. // 例如下单购买商品等操作
  262. } catch (err) {
  263. console.log('实名认证未通过:', err);
  264. return
  265. // 在此处可以处理用户未通过实名认证的情况
  266. // 例如返回上一页或者跳转到实名认证页等操作
  267. }
  268. let that = this;
  269. let creditGoods = [];
  270. creditGoods.push({id:that.details.id,quantity:1})
  271. // console.log('creditGoods',creditGoods);
  272. that.$u.vuex('cartGoods',creditGoods);
  273. uni.$u.route('/shopping/submitorder', {fromPage:'creditOrder'});
  274. },
  275. onShareAppMessage: function( options ){
  276. var that = this;
  277. // 设置菜单中的转发按钮触发转发事件时的转发内容
  278. var shareObj = {
  279. title: this.details.goodsName, // 默认是小程序的名称(可以写slogan等)
  280. path: '/shopping/productdetails', // 默认是当前页面,必须是以‘/'开头的完整路径
  281. imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  282. success: function(res){
  283. // 转发成功之后的回调
  284. if(res.errMsg == 'shareAppMessage:ok'){
  285. }
  286. },
  287. fail: function(){
  288. // 转发失败之后的回调
  289. if(res.errMsg == 'shareAppMessage:fail cancel'){
  290. // 用户取消转发
  291. }else if(res.errMsg == 'shareAppMessage:fail'){
  292. // 转发失败,其中 detail message 为详细失败信息
  293. }
  294. },
  295. complete:function(){
  296. // 转发结束之后的回调(转发成不成功都会执行)
  297. }
  298. };
  299. // 来自页面内的按钮的转发
  300. if( options.from == 'button' ){
  301. var eData = options.target.dataset;
  302. console.log('options.target.dataset',options.target.dataset);
  303. console.log('id' ,this.details.id); // shareBtn
  304. // 此处可以修改 shareObj 中的内容
  305. shareObj.path = '/shopping/productdetails?id='+this.details.id;
  306. }
  307. // 返回shareObj
  308. return shareObj;
  309. },
  310. getAddrList(){
  311. this.$u.api.addrList().then(res=>{
  312. // this.dataList = res.data.rows;
  313. console.log('getAddrList',res);
  314. if( res.data.total>0){
  315. this.hasAddr = true;
  316. }else{
  317. this.hasAddr = false;
  318. }
  319. }).catch(err=>{
  320. console.log('getAddrList',err.data);
  321. })
  322. },
  323. checkAuth() {
  324. // console.log('details-----',this.details);
  325. let that = this;
  326. return new Promise((resolve, reject) => {
  327. console.log('vuex_member_info', this.vuex_member_info.isAuth);
  328. if (that.details.isBuy&&that.details.isBuy!=1) {
  329. uni.showModal({
  330. title: '温馨提示',
  331. content: '购买该商品需要实名认证,请先实名认证!',
  332. success: res => {
  333. if (res.confirm) {
  334. let url = encodeURIComponent(`/shopping/productdetails?id=${that.id}`);
  335. uni.$u.route('/center/factorauth', {
  336. from: 'productdetails',
  337. backUrl: url
  338. });
  339. reject('needAuth'); // 实名认证未通过,使用 reject 方法返回结果
  340. }
  341. }
  342. });
  343. } else {
  344. resolve('noNeedAuth'); // 实名认证已通过,使用 resolve 方法返回结果
  345. }
  346. });
  347. }
  348. }
  349. }
  350. </script>
  351. <style lang="scss" scoped>
  352. .indicator-num {
  353. padding: 2px 0;
  354. background-color: rgba(0, 0, 0, 0.35);
  355. border-radius: 100px;
  356. width: 35px;
  357. @include flex;
  358. justify-content: center;
  359. &__text {
  360. color: #FFFFFF;
  361. font-size: 12px;
  362. }
  363. }
  364. .product-info{
  365. .price-num{
  366. font-size: 60rpx;
  367. }
  368. .exchangeCredit{
  369. font-size: 60rpx;
  370. }
  371. .name{
  372. margin-top: 30rpx;
  373. font-size: 36rpx;
  374. font-weight: 600;
  375. color: #333;
  376. line-height: 50rpx;
  377. }
  378. }
  379. .info-line{
  380. margin-bottom: 20rpx;
  381. }
  382. .info-til{
  383. color: #999;
  384. margin-right: 40rpx;
  385. }
  386. .info-con{
  387. color: #666;
  388. }
  389. .addr{
  390. font-size: 30rpx;
  391. .addr-line:not(:last-child){
  392. margin-bottom: 20rpx;
  393. }
  394. }
  395. .comment{
  396. color: #999;
  397. .til{
  398. font-size: 30rpx;
  399. font-weight: 600;
  400. margin-right: 20rpx;
  401. color: #333;
  402. }
  403. }
  404. .detail{
  405. .til{
  406. font-size: 30rpx;
  407. color: #333;
  408. font-weight: 600;
  409. margin-bottom: 20rpx;
  410. }
  411. .con{
  412. // background-color: #F5F5F5;
  413. img{max-width: 100%;}
  414. }
  415. }
  416. .details-tool-wrap{
  417. height: 98rpx;
  418. .details-tool{
  419. position: fixed;
  420. left: 0;
  421. right: 0;
  422. bottom: 0;
  423. height: 98rpx;
  424. background-color: #fff;
  425. }
  426. .left{
  427. text-align: center;
  428. color: #666;
  429. font-size: 24rpx;
  430. .icon-wrap{
  431. position: relative;
  432. margin-left: 20rpx;
  433. }
  434. }
  435. .right{
  436. .btn{
  437. padding: 19rpx 40rpx;
  438. border-radius: 40rpx;
  439. color: #fff;
  440. margin-right: 20rpx;
  441. }
  442. .add-btn{
  443. background-color: #FFB100;
  444. }
  445. .buy-btn{
  446. background-color: #FF3C3F;
  447. }
  448. .gray{
  449. background-color: #ddd;
  450. color: #999;
  451. }
  452. }
  453. .share-btn{
  454. padding: 0;
  455. margin: 0;
  456. border: 0;
  457. font-size: 24rpx;
  458. color: #666;
  459. line-height: 1;
  460. background-color: transparent;
  461. outline: none;
  462. &::after{
  463. border: none;
  464. }
  465. }
  466. }
  467. </style>