productdetails.vue 8.5 KB

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