FavoriteGoods.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view class="div container">
  3. <view class="div" v-if="favorites_list && favorites_list.length">
  4. <view class="div goods-item" v-for="(item, index) in favorites_list" v-bind:key="item.fav_id" @click="goNavigate('/pages/home/goodsdetail/Goodsdetail',{'goods_id': item.goods_id})">
  5. <view class="goods-info">
  6. <view class="div p-img" :style="'width:'+windowWidth+'px;height:'+windowWidth+'px;flex:0 0 ' +windowWidth+'px'">
  7. <image mode="aspectFit" class="img collection-img" v-bind:src="item.goods_image_url"/>
  8. </view>
  9. <view class="div p-info">
  10. <view class="p-name">{{ item.goods_name }}</view>
  11. <view class="price-wrapper">
  12. <view class="p-price">¥{{ item.goods_price}}</view>
  13. <text class="p-del" @click.stop="delFavoriteGoods($event,item.fav_id)">取消收藏</text>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <empty-record v-else-if="favorites_list && !favorites_list.length"></empty-record>
  20. <uni-popup background-color="#fff" ref="confirm" type="dialog">
  21. <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content" :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
  22. </uni-popup>
  23. </view>
  24. </template>
  25. <script>
  26. import { urlencode,getFontSize } from '@/util/common'
  27. import EmptyRecord from '../../EmptyRecord'
  28. import { getFavoriteGoodsList, delFavoriteGoods } from '../../../api/memberFavorite'
  29. export default {
  30. components:{
  31. EmptyRecord
  32. },
  33. name: 'MemberFavoriteGoods',
  34. data(){
  35. return {
  36. dialog:{},
  37. favorites_list: false
  38. }
  39. },
  40. created: function () {
  41. this.getFavoriteGoodsList()
  42. },
  43. computed:{
  44. windowWidth: function () {
  45. const res = uni.getSystemInfoSync()
  46. var width=res.windowWidth
  47. var size=getFontSize()
  48. return (width-3*.6*size)/4
  49. },
  50. },
  51. methods:{
  52. closeDialog(){
  53. },
  54. confirmDialog(value){
  55. this.getCancelCollection(this.dialog.data)
  56. },
  57. goNavigate(path,query=false){
  58. uni.navigateTo({url:path+(query?('?'+urlencode(query)):'')})
  59. },
  60. delFavoriteGoods (e,favId) {
  61. this.dialog={content:'是否要取消收藏此商品?',title: '确认删除',data:favId}
  62. this.$refs.confirm.open()
  63. },
  64. // 取消收藏机构数据
  65. getCancelCollection (favId) {
  66. delFavoriteGoods(favId).then(res => {
  67. if (res) {
  68. this.getFavoriteGoodsList()
  69. }
  70. })
  71. },
  72. getFavoriteGoodsList () {
  73. uni.showLoading({ title: '加载中' })
  74. getFavoriteGoodsList(this.page, {}).then(res => {
  75. uni.hideLoading()
  76. this.favorites_list = res.result.favorites_list
  77. }).catch(function (error) {
  78. uni.hideLoading()
  79. uni.showToast({icon:'none',title:error.message})
  80. })
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. .goods-item{background: #fff;padding:.3rem $pageSpace;box-sizing: border-box;}
  87. .goods-item .goods-info{box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.06);display: flex;}
  88. .goods-item .goods-info .p-img{}
  89. .goods-item .goods-info .p-img .img{border-radius: .5rem;}
  90. .goods-item .goods-info .p-info{margin:0 .6rem;width: 60%;display: flex;flex-wrap: wrap;padding: .3rem 0;box-sizing: border-box;align-items: center;}
  91. .goods-item .goods-info .p-info .p-name{color: #333;width: 100%;font-size: .7rem; line-height: .8rem;height: 1.6rem;overflow: hidden;display: -webkit-box; -webkit-box-orient: vertical;-webkit-line-clamp: 2;box-sizing: border-box;}
  92. .goods-item .goods-info .p-info .price-wrapper{display: flex;align-items: end;width: 100%;}
  93. .goods-item .goods-info .p-info .price-wrapper .p-price{color: $primaryColor;}
  94. .goods-item .goods-info .p-info .price-wrapper .p-del{margin-left: auto;display: flex;font-size: .6rem;color: #fff;background: $primaryColor;padding: .2rem .3rem;border-radius: .5rem;}
  95. </style>