productdetails.vue 9.8 KB

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