productdetails.vue 10 KB

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