productdetails.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="产品详情"
  5. :autoBack="false"
  6. @leftClick="leftClick"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar>
  10. <u-swiper
  11. v-if="details.slideImgList.length>0"
  12. :list="details.slideImgList"
  13. @change="e => currentNum = e.current"
  14. :autoplay="false"
  15. indicatorStyle="right: 20px"
  16. >
  17. <view
  18. slot="indicator"
  19. class="indicator-num"
  20. >
  21. <text class="indicator-num__text">{{ currentNum + 1 }}/{{ details.slideImgList.length }}</text>
  22. </view>
  23. </u-swiper>
  24. <view class="product-info view-wrap">
  25. <view class="red">
  26. <view class="" v-if="vuex_member_info.priceType>1">
  27. <text class="price">¥ <text class="price-num">{{details.vipPrice}}</text></text>
  28. <text class="vip-icon">VIP</text>
  29. <text class="exchangeCredit" v-if="details.isCredit==1">+{{details.exchangeCredit}}积分</text>
  30. </view>
  31. <view class="" v-else>
  32. <text class="price">¥ <text class="price-num">{{details.salePrice}}</text></text>
  33. <text class="exchangeCredit" v-if="details.isCredit==1">+{{details.exchangeCredit}}积分</text>
  34. </view>
  35. </view>
  36. <view class="u-flex u-row-between gray">
  37. <text v-if="vuex_member_info.priceType>1" class="line-through">¥ <text class="">{{details.salePrice}}</text></text>
  38. <text class="">库存 {{details.stock}}</text>
  39. </view>
  40. <view class="name">{{details.goodsName}}</view>
  41. </view>
  42. <view class="specification info-line u-flex view-wrap" v-if="details.specification">
  43. <view class="info-til">规格</view>
  44. <view class="info-con u-flex">{{details.specification}}</view>
  45. </view>
  46. <view class="addr view-wrap">
  47. <view class="addr-line u-flex">
  48. <view class="info-til">快递</view>
  49. <view class="info-con u-flex">
  50. 包邮
  51. </view>
  52. </view>
  53. <!-- <view class="addr-line u-flex">
  54. <text class="addr-til">送至</text>
  55. <view class="addr-con u-flex u-flex-1">
  56. <view class="u-flex u-row-between u-flex-1">
  57. <text>贵阳市 南明区</text>
  58. <u-icon name="arrow-right" color="#676767" size="20"></u-icon>
  59. </view>
  60. </view>
  61. </view> -->
  62. </view>
  63. <view class="comment view-wrap u-flex u-row-between">
  64. <view class="left">
  65. <text class="til">评价</text>
  66. <text class="num">({{details.commentNum}})</text>
  67. </view>
  68. <view class="right u-flex" @click="$u.route('/shopping/comment',{id:details.id})">
  69. <text>查看全部</text>
  70. <u-icon name="arrow-right" color="#676767" size="20"></u-icon>
  71. </view>
  72. </view>
  73. <view class="detail view-wrap">
  74. <view class="til">详情</view>
  75. <view class="con">
  76. <!-- <view class="" v-html="details.detail"></view> -->
  77. <u-parse :content="details.detail"></u-parse>
  78. <!-- {{details.detail}} -->
  79. </view>
  80. </view>
  81. <view class="details-tool-wrap">
  82. <view class="details-tool u-flex u-row-between">
  83. <view class="left u-flex">
  84. <view class="icon-wrap">
  85. <button class="share-btn" data-name="shareBtn" open-type="share">
  86. <u-icon name="share" color="#676767" size="30"></u-icon>
  87. 分享
  88. </button>
  89. </view>
  90. <view class="icon-wrap" v-if="details.isCredit!=1" @click="$u.route('/shopping/cart')">
  91. <u-icon name="shopping-cart" color="#676767" size="30"></u-icon>
  92. 购物车
  93. <u-badge class="badge" numberType="overflow" type="error " max="99" :value="cartTotal" :absolute="true" :offset="[0,0]"></u-badge>
  94. </view>
  95. </view>
  96. <view class="right u-flex" v-if="details.isCredit==1">
  97. <view class="btn add-btn" @click="addCreditOrder(details.id)">立即兑换</view>
  98. </view>
  99. <view class="right u-flex" v-else>
  100. <view class="btn add-btn" @click="addCart(details.id)">加入购物车</view>
  101. <view class="btn buy-btn" @click="buyNow(details.id)">立即购买</view>
  102. </view>
  103. </view>
  104. </view>
  105. <u-toast ref="uToast"></u-toast>
  106. </view>
  107. </template>
  108. <script>
  109. export default {
  110. data() {
  111. return {
  112. id:'',
  113. cartTotal:0,
  114. currentNum:0,
  115. swiperList: [],
  116. details:{
  117. slideImgList:[]
  118. }
  119. }
  120. },
  121. onShow() {
  122. },
  123. onLoad(page) {
  124. this.id = page.id;
  125. // console.log('this.id',this.id);
  126. this.getDetails(this.id);
  127. },
  128. onShow(){
  129. this.getCartList()
  130. },
  131. methods: {
  132. leftClick(e){
  133. let pages = getCurrentPages();
  134. if(pages.length==1){
  135. uni.$u.route('/pages/index/index')
  136. }else{
  137. uni.navigateBack()
  138. };
  139. },
  140. getCartList(isAdd){
  141. this.$u.api.cartList().then(res=>{
  142. if(isAdd){
  143. if(res.data.total==this.cartTotal){
  144. this.$refs.uToast.show({
  145. type:"success",
  146. message:'已在购物车'
  147. });
  148. }
  149. }
  150. this.cartTotal = res.data.total;
  151. console.log('getCartList',res);
  152. }).catch(err=>{
  153. console.log('getCartList',err.data);
  154. })
  155. },
  156. getDetails(id){
  157. this.$u.api.memberGoodDetails({id:id}).then(res=>{
  158. console.log('res',res.data);
  159. this.details = res.data;
  160. if(!res.data.slideImgList&&res.data.mainImg){
  161. this.details.slideImgList = [];
  162. this.details.slideImgList.push(res.data.mainImg)
  163. }
  164. }).catch(err=>{
  165. console.log('getDetails',err.data);
  166. })
  167. },
  168. addCart(id,buyNow){
  169. this.$u.api.addCart({goodsId:id}).then(res=>{
  170. this.$refs.uToast.show({
  171. type:"success",
  172. message:res.msg
  173. });
  174. if(buyNow){
  175. uni.$u.route('/shopping/cart', {
  176. buyNowId: id,
  177. buyNowName:this.details.goodsName
  178. });
  179. }
  180. this.getCartList('isAdd');
  181. console.log('res',res.data);
  182. }).catch(err=>{
  183. console.log('addCart',err);
  184. })
  185. },
  186. buyNow(id){
  187. this.addCart(id,'buyNow')
  188. },
  189. addCreditOrder(id){
  190. let that = this;
  191. let creditGoods = [];
  192. creditGoods.push({id:that.details.id,quantity:1})
  193. // console.log('creditGoods',creditGoods);
  194. that.$u.vuex('cartGoods',creditGoods);
  195. uni.$u.route('/shopping/submitorder', {fromPage:'creditOrder'});
  196. },
  197. onShareAppMessage: function( options ){
  198. var that = this;
  199. // 设置菜单中的转发按钮触发转发事件时的转发内容
  200. var shareObj = {
  201. title: this.details.goodsName, // 默认是小程序的名称(可以写slogan等)
  202. path: '/shopping/productdetails', // 默认是当前页面,必须是以‘/'开头的完整路径
  203. imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  204. success: function(res){
  205. // 转发成功之后的回调
  206. if(res.errMsg == 'shareAppMessage:ok'){
  207. }
  208. },
  209. fail: function(){
  210. // 转发失败之后的回调
  211. if(res.errMsg == 'shareAppMessage:fail cancel'){
  212. // 用户取消转发
  213. }else if(res.errMsg == 'shareAppMessage:fail'){
  214. // 转发失败,其中 detail message 为详细失败信息
  215. }
  216. },
  217. complete:function(){
  218. // 转发结束之后的回调(转发成不成功都会执行)
  219. }
  220. };
  221. // 来自页面内的按钮的转发
  222. if( options.from == 'button' ){
  223. var eData = options.target.dataset;
  224. console.log('options.target.dataset',options.target.dataset);
  225. console.log('id' ,this.details.id); // shareBtn
  226. // 此处可以修改 shareObj 中的内容
  227. shareObj.path = '/shopping/productdetails?id='+this.details.id;
  228. }
  229. // 返回shareObj
  230. return shareObj;
  231. }
  232. }
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .indicator-num {
  237. padding: 2px 0;
  238. background-color: rgba(0, 0, 0, 0.35);
  239. border-radius: 100px;
  240. width: 35px;
  241. @include flex;
  242. justify-content: center;
  243. &__text {
  244. color: #FFFFFF;
  245. font-size: 12px;
  246. }
  247. }
  248. .product-info{
  249. .price-num{
  250. font-size: 60rpx;
  251. }
  252. .exchangeCredit{
  253. font-size: 60rpx;
  254. }
  255. .name{
  256. margin-top: 30rpx;
  257. font-size: 36rpx;
  258. font-weight: 600;
  259. color: #333;
  260. line-height: 50rpx;
  261. }
  262. }
  263. .info-line{
  264. margin-bottom: 20rpx;
  265. }
  266. .info-til{
  267. color: #999;
  268. margin-right: 40rpx;
  269. }
  270. .info-con{
  271. color: #666;
  272. }
  273. .addr{
  274. font-size: 30rpx;
  275. .addr-line:not(:last-child){
  276. }
  277. }
  278. .comment{
  279. color: #999;
  280. .til{
  281. font-size: 30rpx;
  282. font-weight: 600;
  283. margin-right: 20rpx;
  284. color: #333;
  285. }
  286. }
  287. .detail{
  288. .til{
  289. font-size: 30rpx;
  290. color: #333;
  291. font-weight: 600;
  292. margin-bottom: 20rpx;
  293. }
  294. .con{
  295. // background-color: #F5F5F5;
  296. img{max-width: 100%;}
  297. }
  298. }
  299. .details-tool-wrap{
  300. height: 98rpx;
  301. .details-tool{
  302. position: fixed;
  303. left: 0;
  304. right: 0;
  305. bottom: 0;
  306. height: 98rpx;
  307. background-color: #fff;
  308. }
  309. .left{
  310. text-align: center;
  311. color: #666;
  312. font-size: 24rpx;
  313. .icon-wrap{
  314. position: relative;
  315. margin-left: 20rpx;
  316. }
  317. }
  318. .right{
  319. .btn{
  320. padding: 19rpx 40rpx;
  321. border-radius: 40rpx;
  322. color: #fff;
  323. margin-right: 20rpx;
  324. }
  325. .add-btn{
  326. background-color: #FFB100;
  327. }
  328. .buy-btn{
  329. background-color: #FF3C3F;
  330. }
  331. }
  332. .share-btn{
  333. padding: 0;
  334. margin: 0;
  335. border: 0;
  336. font-size: 24rpx;
  337. color: #666;
  338. line-height: 1;
  339. background-color: transparent;
  340. outline: none;
  341. &::after{
  342. border: none;
  343. }
  344. }
  345. }
  346. </style>