productdetails.vue 10 KB

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