index.vue 5.5 KB

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