productdetails.vue 9.1 KB

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