productdetails.vue 13 KB

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