productdetails.vue 10 KB

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