productdetails.vue 10 KB

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