productdetails.vue 9.6 KB

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