productdetails.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. uni.showModal({
  183. title: '提示',
  184. content: '将扣除积分是否继续!',
  185. success: res => {
  186. if (res.confirm) {
  187. let creditGoods = [];
  188. creditGoods.push({id:that.details.id,quantity:1})
  189. console.log('creditGoods',creditGoods);
  190. that.$u.vuex('cartGoods',creditGoods);
  191. uni.$u.route('/shopping/submitorder', {fromPage:'creditOrder'});
  192. }
  193. }
  194. });
  195. },
  196. onShareAppMessage: function( options ){
  197. var that = this;
  198. // 设置菜单中的转发按钮触发转发事件时的转发内容
  199. var shareObj = {
  200. title: this.details.goodsName, // 默认是小程序的名称(可以写slogan等)
  201. path: '/shopping/productdetails', // 默认是当前页面,必须是以‘/'开头的完整路径
  202. imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  203. success: function(res){
  204. // 转发成功之后的回调
  205. if(res.errMsg == 'shareAppMessage:ok'){
  206. }
  207. },
  208. fail: function(){
  209. // 转发失败之后的回调
  210. if(res.errMsg == 'shareAppMessage:fail cancel'){
  211. // 用户取消转发
  212. }else if(res.errMsg == 'shareAppMessage:fail'){
  213. // 转发失败,其中 detail message 为详细失败信息
  214. }
  215. },
  216. complete:function(){
  217. // 转发结束之后的回调(转发成不成功都会执行)
  218. }
  219. };
  220. // 来自页面内的按钮的转发
  221. if( options.from == 'button' ){
  222. var eData = options.target.dataset;
  223. console.log('options.target.dataset',options.target.dataset);
  224. console.log('id' ,this.details.id); // shareBtn
  225. // 此处可以修改 shareObj 中的内容
  226. shareObj.path = '/shopping/productdetails?id='+this.details.id;
  227. }
  228. // 返回shareObj
  229. return shareObj;
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. .indicator-num {
  236. padding: 2px 0;
  237. background-color: rgba(0, 0, 0, 0.35);
  238. border-radius: 100px;
  239. width: 35px;
  240. @include flex;
  241. justify-content: center;
  242. &__text {
  243. color: #FFFFFF;
  244. font-size: 12px;
  245. }
  246. }
  247. .product-info{
  248. .price-num{
  249. font-size: 60rpx;
  250. }
  251. .exchangeCredit{
  252. font-size: 60rpx;
  253. }
  254. .name{
  255. margin-top: 30rpx;
  256. font-size: 36rpx;
  257. font-weight: 600;
  258. color: #333;
  259. line-height: 50rpx;
  260. }
  261. }
  262. .info-line{
  263. margin-bottom: 20rpx;
  264. }
  265. .info-til{
  266. color: #999;
  267. margin-right: 40rpx;
  268. }
  269. .info-con{
  270. color: #666;
  271. }
  272. .addr{
  273. font-size: 30rpx;
  274. .addr-line:not(:last-child){
  275. }
  276. }
  277. .comment{
  278. color: #999;
  279. .til{
  280. font-size: 30rpx;
  281. font-weight: 600;
  282. margin-right: 20rpx;
  283. color: #333;
  284. }
  285. }
  286. .detail{
  287. .til{
  288. font-size: 30rpx;
  289. color: #333;
  290. font-weight: 600;
  291. margin-bottom: 20rpx;
  292. }
  293. .con{
  294. // background-color: #F5F5F5;
  295. img{max-width: 100%;}
  296. }
  297. }
  298. .details-tool-wrap{
  299. height: 98rpx;
  300. .details-tool{
  301. position: fixed;
  302. left: 0;
  303. right: 0;
  304. bottom: 0;
  305. height: 98rpx;
  306. background-color: #fff;
  307. }
  308. .left{
  309. text-align: center;
  310. color: #666;
  311. font-size: 24rpx;
  312. .icon-wrap{
  313. position: relative;
  314. margin-left: 20rpx;
  315. }
  316. }
  317. .right{
  318. .btn{
  319. padding: 19rpx 40rpx;
  320. border-radius: 40rpx;
  321. color: #fff;
  322. margin-right: 20rpx;
  323. }
  324. .add-btn{
  325. background-color: #FFB100;
  326. }
  327. .buy-btn{
  328. background-color: #FF3C3F;
  329. }
  330. }
  331. .share-btn{
  332. padding: 0;
  333. margin: 0;
  334. border: 0;
  335. font-size: 24rpx;
  336. color: #666;
  337. line-height: 1;
  338. background-color: transparent;
  339. outline: none;
  340. &::after{
  341. border: none;
  342. }
  343. }
  344. }
  345. </style>