index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <view class="one_1">
  6. <text>¥</text><text>{{money}}</text>
  7. </view>
  8. <view class="one_2">
  9. 当前可用
  10. </view>
  11. </view>
  12. <view class="two">
  13. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  14. <view class="list-scroll-view">
  15. <view class="list" v-for="(item, index) in list" :key="index">
  16. <view class="other" @tap="toDetail(item)">
  17. <view class="other_1">
  18. <view class="source">{{item.zhSource}}</view>
  19. <view class="time">{{item.time}}</view>
  20. </view>
  21. <view class="other_2">
  22. <view class="money">{{item.money}}</view>
  23. <text class="iconfont icon-jiantouyou"></text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="is_bottom" v-if="is_bottom">
  28. <text>{{config.bottom_title}}</text>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. </view>
  33. </view>
  34. </mobile-frame>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. // 系统设置
  41. config: {},
  42. user: {},
  43. money: 0,
  44. list: [],
  45. total: 0,
  46. skip: 0,
  47. limit: 6,
  48. page: 0,
  49. // 来源
  50. sourceList: [],
  51. // 数据是否触底
  52. is_bottom: false,
  53. scrollTop: 0,
  54. };
  55. },
  56. onShow: async function(e) {
  57. const that = this;
  58. that.searchConfig();
  59. await that.searchOther();
  60. await that.watchLogin();
  61. },
  62. onHide: function() {
  63. const that = this;
  64. that.clearPage();
  65. },
  66. methods: {
  67. // 查询基本设置
  68. searchConfig() {
  69. const that = this;
  70. uni.getStorage({
  71. key: 'config',
  72. success: function(res) {
  73. if (res.data) that.$set(that, `config`, res.data)
  74. },
  75. fail: function(err) {
  76. console.log(err);
  77. }
  78. })
  79. },
  80. watchLogin() {
  81. const that = this;
  82. uni.getStorage({
  83. key: 'token',
  84. success: function(res) {
  85. let user = that.$jwt(res.data);
  86. that.$set(that, `user`, user)
  87. that.search()
  88. }
  89. })
  90. },
  91. // 查询列表
  92. async search() {
  93. const that = this;
  94. let user = that.user;
  95. if (user._id) {
  96. let info = {
  97. skip: that.skip,
  98. limit: that.limit,
  99. inviter: user._id,
  100. }
  101. let res = await that.$api(`/cashBack`, 'GET', {
  102. ...info,
  103. })
  104. if (res.errcode == '0') {
  105. let list = [...that.list, ...res.data];
  106. for (let val of list) {
  107. let source = that.sourceList.find(i => i.value == val.source)
  108. if (source) val.zhSource = source.label;
  109. }
  110. that.$set(that, `list`, list);
  111. that.$set(that, `total`, res.total)
  112. }
  113. let arr = await that.$api(`/cashBack/computedTotal`, 'GET', {
  114. customer: user._id
  115. })
  116. if (arr.errcode == '0') that.$set(that, `money`, arr.data);
  117. }
  118. },
  119. // 查询其他信息
  120. async searchOther() {
  121. const that = this;
  122. let res;
  123. res = await that.$api(`/dictData`, 'GET', {
  124. code: "cashBack_source"
  125. });
  126. if (res.errcode == '0') {
  127. that.$set(that, `sourceList`, res.data)
  128. }
  129. },
  130. // 分页
  131. toPage(e) {
  132. const that = this;
  133. let list = that.list;
  134. let limit = that.limit;
  135. if (that.total > list.length) {
  136. uni.showLoading({
  137. title: '加载中',
  138. mask: true
  139. })
  140. let page = that.page + 1;
  141. that.$set(that, `page`, page)
  142. let skip = page * limit;
  143. that.$set(that, `skip`, skip)
  144. that.search();
  145. uni.hideLoading();
  146. } else that.$set(that, `is_bottom`, true)
  147. },
  148. toScroll(e) {
  149. const that = this;
  150. let up = that.scrollTop;
  151. that.$set(that, `scrollTop`, e.detail.scrollTop);
  152. let num = Math.sign(up - e.detail.scrollTop);
  153. if (num == 1) that.$set(that, `is_bottom`, false);
  154. },
  155. // 清空列表
  156. clearPage() {
  157. const that = this;
  158. that.$set(that, `list`, [])
  159. that.$set(that, `skip`, 0)
  160. that.$set(that, `limit`, 6)
  161. that.$set(that, `page`, 0)
  162. },
  163. // 明细
  164. toDetail(item) {
  165. const that = this;
  166. that.clearPage();
  167. uni.navigateTo({
  168. url: `/pagesMy/assets/info?id=${item._id}`
  169. })
  170. },
  171. },
  172. onPullDownRefresh: async function() {
  173. const that = this;
  174. that.$set(that, `list`, [])
  175. that.$set(that, `skip`, 0)
  176. that.$set(that, `limit`, 6)
  177. that.$set(that, `page`, 0)
  178. await that.search();
  179. uni.stopPullDownRefresh();
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. .main {
  185. display: flex;
  186. flex-direction: column;
  187. width: 100vw;
  188. height: 100vh;
  189. .one {
  190. background-color: var(--fFB1Color);
  191. text-align: center;
  192. padding: 5vw 0;
  193. .one_1 {
  194. font-size: 25px;
  195. font-weight: bold;
  196. color: #fff;
  197. margin: 0 0 2vw 0;
  198. text:nth-child(1) {
  199. font-size: 15px;
  200. padding: 0 1vw 0 0;
  201. }
  202. }
  203. .one_2 {
  204. font-size: 16px;
  205. color: #fff;
  206. }
  207. }
  208. .two {
  209. position: relative;
  210. flex-grow: 1;
  211. padding: 2vw 0 0 0;
  212. .list {
  213. width: 92vw;
  214. border-bottom: 0.5vw solid var(--f1Color);
  215. margin: 2vw 2vw 0 2vw;
  216. padding: 2vw;
  217. border-radius: 5px;
  218. .other {
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. .other_1 {
  223. font-size: var(--font16Size);
  224. margin: 0 0 1vw 0;
  225. .time {
  226. margin: 1vw 0 0 0;
  227. color: var(--f85Color);
  228. font-size: var(--font12Size);
  229. }
  230. }
  231. .other_2 {
  232. display: flex;
  233. align-items: center;
  234. width: 10vw;
  235. .money {
  236. font-size: var(--font18Size);
  237. font-weight: bold;
  238. margin: 0 1vw;
  239. }
  240. .iconfont {
  241. font-size: 16px;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. }
  248. .scroll-view {
  249. position: absolute;
  250. top: 0;
  251. left: 0;
  252. right: 0;
  253. bottom: 0;
  254. .list-scroll-view {
  255. display: flex;
  256. flex-direction: column;
  257. }
  258. }
  259. .is_bottom {
  260. text-align: center;
  261. text {
  262. padding: 2vw 0;
  263. display: inline-block;
  264. color: #858585;
  265. font-size: 14px;
  266. }
  267. }
  268. </style>