productdetails.vue 13 KB

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