productdetails.vue 7.8 KB

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