productdetails.vue 13 KB

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