productdetails.vue 8.9 KB

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