productdetails.vue 9.2 KB

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