fav.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="uni-tab-bar">
  3. <view class="uni-product-list favList">
  4. <scroll-view scroll-y="false" class="scroll-Y" @scrolltolower="loadMore()">
  5. <view class="uni-product uni-flex" v-for="(item,index) in newsitems[0].data" :key="index">
  6. <view class="image-view" @click="goProduct(item)">
  7. <image class="uni-product-image" :src="item.pic" />
  8. </view>
  9. <view class="uni-product-wrap uni-flex uni-column">
  10. <view class="uni-product-title">{{item.title}}</view>
  11. <view class="uni-flex uni-product-price uni-flex-item">
  12. <view class="uni-flex uni-flex-item uni-product-price-original">
  13. ¥{{item.salePrice}}
  14. </view>
  15. <view class="uni-flex uni-flex-item uni-product-price-favour">
  16. ¥{{item.marketPrice}}
  17. </view>
  18. </view>
  19. </view>
  20. <view class="delCollection-wrap uni-flex">
  21. <view class="delCollection" @click="fav(item,index)">取消收藏</view>
  22. </view>
  23. </view>
  24. <view class="uni-tab-bar-loading">
  25. <uni-load-more :loadingType="newsitems[0].loadingType" :contentText="loadingText"></uni-load-more>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. mapState,
  34. mapMutations
  35. } from 'vuex'
  36. import favr from '../../../common/favr.js';
  37. import uniLoadMore from '@/components/uni-load-more.vue';
  38. export default {
  39. computed: {
  40. ...mapState(['hasLogin', 'jyyUser', 'favs'])
  41. },
  42. components: {
  43. uniLoadMore
  44. },
  45. data() {
  46. return {
  47. loadingText: {
  48. contentdown: "上拉显示更多",
  49. contentrefresh: "正在加载...",
  50. contentnomore: "没有更多数据了"
  51. },
  52. user: {},
  53. newsitems: [{
  54. "loadingType": 0,
  55. "pageIndex": 1,
  56. "data": []
  57. }],
  58. show: true
  59. }
  60. },
  61. onLoad(e) {
  62. if (!this.hasLogin) {
  63. uni.navigateTo({
  64. url: '../login/login',
  65. });
  66. } else {
  67. this.user = JSON.parse(this.jyyUser);
  68. }
  69. },
  70. onReady() {
  71. this.init();
  72. },
  73. methods: {
  74. ...mapMutations(['setFavs']),
  75. init() {
  76. this.getData();
  77. },
  78. fav(e, index) {
  79. let id = e.favid
  80. uni.request({
  81. url: this.webUrl + 'Fav',
  82. method: 'POST',
  83. data: {
  84. id: id,
  85. mode: 1,
  86. userid: this.user.id,
  87. show: !this.show
  88. },
  89. header: {
  90. 'content-type': 'application/x-www-form-urlencoded'
  91. },
  92. success: res => {
  93. uni.hideLoading();
  94. if (res.data.result.isSuccess) {
  95. this.setFavs(JSON.stringify(res.data.result.resultInfo2));
  96. uni.showToast({
  97. title: res.data.result.resultInfo,
  98. icon: "none"
  99. })
  100. this.newsitems[0].data.splice(index, 1)
  101. } else {
  102. uni.showModal({
  103. title: "系统提示",
  104. content: res.data.result.resultInfo,
  105. icon: "none"
  106. })
  107. }
  108. },
  109. fail: () => {},
  110. complete: () => {}
  111. });
  112. },
  113. goProduct(e) {
  114. console.log(e)
  115. uni.navigateTo({
  116. url: '../../merchant/product/product?id=' + e.favid
  117. });
  118. },
  119. loadMore() {
  120. setTimeout(() => {
  121. this.addData();
  122. }, 1200);
  123. },
  124. addData() {
  125. this.getData();
  126. },
  127. getData() {
  128. if (this.newsitems[0].loadingType === 2) {
  129. return;
  130. }
  131. this.newsitems[0].loadingType = 1;
  132. uni.request({
  133. url: this.webUrl + 'Favs',
  134. method: 'POST',
  135. data: {
  136. pageIndex: this.newsitems[0].pageIndex,
  137. userid: this.user.id
  138. },
  139. header: {
  140. 'content-type': 'application/x-www-form-urlencoded'
  141. },
  142. success: res => {
  143. if (res.data.result.uniFavs.length > 0) {
  144. this.newsitems[0].data = this.newsitems[0].data.concat(res.data.result.uniFavs);
  145. } else {
  146. this.newsitems[0].loadingType = 2;
  147. return;
  148. }
  149. if (this.newsitems[0].pageIndex == parseInt(res.data.result.pages)) {
  150. this.newsitems[0].loadingType = 2;
  151. return;
  152. } else {
  153. this.newsitems[0].loadingType = 0;
  154. }
  155. this.newsitems[0].pageIndex++;
  156. },
  157. fail: () => {},
  158. complete: () => {}
  159. });
  160. }
  161. }
  162. }
  163. </script>
  164. <style>
  165. .favList {
  166. margin-top: 20upx;
  167. }
  168. .favList .uni-product-wrap {
  169. position: relative;
  170. }
  171. .delCollection-wrap {
  172. align-items: center;
  173. justify-content: center;
  174. }
  175. .delCollection-wrap .delCollection {
  176. width: 150upx;
  177. height: 55upx;
  178. line-height: 55upx;
  179. text-align: center;
  180. margin-right: 30upx;
  181. margin-bottom: 5upx;
  182. display: inline-block;
  183. background: #fc6f05;
  184. color: #fff;
  185. border-radius: 60upx;
  186. font-size: 24upx;
  187. }
  188. .image-view {
  189. width: 160upx;
  190. height: 160upx;
  191. margin-left: 25upx;
  192. border-radius: 10upx;
  193. }
  194. .image-view .uni-product-image {
  195. width: 160upx;
  196. height: 160upx;
  197. border-radius: 10upx;
  198. }
  199. .uni-product-price-favour {
  200. margin-left: 0;
  201. }
  202. .uni-product-list {
  203. overflow-y: scroll;
  204. }
  205. .uni-product-wrap {
  206. flex: 1;
  207. margin-left: 30upx;
  208. align-content: space-around;
  209. }
  210. .uni-product-number-wrap {
  211. display: flex;
  212. justify-content: space-between;
  213. align-items: flex-end;
  214. }
  215. .uni-product {
  216. width: 90%;
  217. margin: 2%;
  218. flex-direction: row;
  219. background: #FFFFFF;
  220. border-radius: 35upx;
  221. }
  222. .uni-product-number {
  223. margin-right: 0;
  224. }
  225. .sellgroup {
  226. width: 150upx;
  227. height: 55upx;
  228. line-height: 55upx;
  229. text-align: center;
  230. margin-right: 10upx;
  231. margin-bottom: 5upx;
  232. display: inline-block;
  233. background: #fc6f05;
  234. color: #fff;
  235. border-radius: 60upx;
  236. font-size: 24upx;
  237. }
  238. .uni-product-price-original {
  239. margin-top: 10upx;
  240. }
  241. .uni-product-price-favour {
  242. margin-top: 10upx;
  243. }
  244. .uni-tab-bar-container {
  245. width: calc(100% - 20upx);
  246. overflow: hidden;
  247. margin-left: 10upx;
  248. }
  249. ::-webkit-scrollbar {
  250. /*隐藏滚轮*/
  251. display: none;
  252. }
  253. .uni-product-price {
  254. flex-direction: column;
  255. }
  256. .uni-tab-bar-loading {
  257. margin: 0 auto;
  258. }
  259. </style>