productdetails.vue 7.6 KB

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