index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. uni.startPullDownRefresh();
  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. customer: user._id,
  99. }
  100. let res = await that.$api(`/point`, '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(`/point/computedTotal`, 'GET', {
  115. customer: user._id
  116. })
  117. if (arr.errcode == '0') that.$set(that, `integral`, arr.data);
  118. }
  119. },
  120. // 查询其他信息
  121. async searchOther() {
  122. const that = this;
  123. let res;
  124. res = await that.$api(`/dictData`, 'GET', {
  125. code: "point_status"
  126. });
  127. if (res.errcode == '0') {
  128. that.$set(that, `statusList`, res.data)
  129. }
  130. res = await that.$api(`/dictData`, 'GET', {
  131. code: "point_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. padding: 5vw 2vw;
  191. display: flex;
  192. justify-content: space-between;
  193. .one_1 {
  194. color: #fff;
  195. font-size: 25px;
  196. font-weight: bold;
  197. text:last-child {
  198. padding: 0 0 0 2vw;
  199. font-size: 15px;
  200. }
  201. }
  202. .one_2 {
  203. button {
  204. background: #fff;
  205. color: #ff0000;
  206. border-radius: 25px;
  207. font-size: 14px;
  208. }
  209. }
  210. }
  211. .two {
  212. position: relative;
  213. flex-grow: 1;
  214. padding: 2vw 0 0 0;
  215. .list {
  216. width: 92vw;
  217. border: 0.5vw solid var(--f1Color);
  218. margin: 2vw 2vw 0 1.5vw;
  219. padding: 2vw;
  220. border-radius: 5px;
  221. .other {
  222. .other_1 {
  223. font-size: var(--font16Size);
  224. margin: 0 0 1vw 0;
  225. .integral {
  226. color: #ff0000;
  227. }
  228. text {
  229. margin: 0 0 0 2vw;
  230. color: var(--f85Color);
  231. font-size: var(--font14Size);
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. .scroll-view {
  239. position: absolute;
  240. top: 0;
  241. left: 0;
  242. right: 0;
  243. bottom: 0;
  244. .list-scroll-view {
  245. display: flex;
  246. flex-direction: column;
  247. }
  248. }
  249. .is_bottom {
  250. text-align: center;
  251. text {
  252. padding: 2vw 0;
  253. display: inline-block;
  254. color: #858585;
  255. font-size: 14px;
  256. }
  257. }
  258. </style>