productdetails.vue 9.3 KB

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