index.vue 5.7 KB

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