productdetails.vue 8.7 KB

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