index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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" @click="toRecord">
  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: 10,
  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. onPullDownRefresh: async function() {
  65. const that = this;
  66. that.clearPage();
  67. await that.search();
  68. uni.stopPullDownRefresh();
  69. },
  70. methods: {
  71. // 查询基本设置
  72. searchConfig() {
  73. const that = this;
  74. uni.getStorage({
  75. key: 'config',
  76. success: function(res) {
  77. if (res.data) that.$set(that, `config`, res.data)
  78. },
  79. fail: function(err) {
  80. console.log(err);
  81. }
  82. })
  83. },
  84. watchLogin() {
  85. const that = this;
  86. uni.getStorage({
  87. key: 'token',
  88. success: function(res) {
  89. let user = that.$jwt(res.data);
  90. that.$set(that, `user`, user)
  91. that.search()
  92. }
  93. })
  94. },
  95. // 查询列表
  96. async search() {
  97. const that = this;
  98. let user = that.user;
  99. if (user._id) {
  100. let info = {
  101. skip: that.skip,
  102. limit: that.limit,
  103. customer: user._id,
  104. }
  105. let res = await that.$api(`/point`, 'GET', {
  106. ...info,
  107. })
  108. if (res.errcode == '0') {
  109. let list = [...that.list, ...res.data];
  110. for (let val of list) {
  111. let status = that.statusList.find(i => i.value == val.status)
  112. if (status) val.zhStatus = status.label;
  113. let source = that.sourceList.find(i => i.value == val.source)
  114. if (source) val.zhSource = source.label;
  115. }
  116. that.$set(that, `list`, list);
  117. that.$set(that, `total`, res.total)
  118. }
  119. let arr = await that.$api(`/point/computedTotal`, 'GET', {
  120. customer: user._id
  121. })
  122. if (arr.errcode == '0') that.$set(that, `integral`, arr.data);
  123. }
  124. },
  125. // 分页
  126. toPage(e) {
  127. const that = this;
  128. let list = that.list;
  129. let limit = that.limit;
  130. if (that.total > list.length) {
  131. uni.showLoading({
  132. title: '加载中',
  133. mask: true
  134. })
  135. let page = that.page + 1;
  136. that.$set(that, `page`, page)
  137. let skip = page * limit;
  138. that.$set(that, `skip`, skip)
  139. that.search();
  140. uni.hideLoading();
  141. } else that.$set(that, `is_bottom`, true)
  142. },
  143. toScroll(e) {
  144. const that = this;
  145. let up = that.scrollTop;
  146. that.$set(that, `scrollTop`, e.detail.scrollTop);
  147. let num = Math.sign(up - e.detail.scrollTop);
  148. if (num == 1) that.$set(that, `is_bottom`, false);
  149. },
  150. // 查询其他信息
  151. async searchOther() {
  152. const that = this;
  153. let res;
  154. res = await that.$api(`/dictData`, 'GET', {
  155. code: "point_status"
  156. });
  157. if (res.errcode == '0') {
  158. that.$set(that, `statusList`, res.data)
  159. }
  160. res = await that.$api(`/dictData`, 'GET', {
  161. code: "point_source"
  162. });
  163. if (res.errcode == '0') {
  164. that.$set(that, `sourceList`, res.data)
  165. }
  166. },
  167. // 兑换记录
  168. toRecord() {
  169. uni.navigateTo({
  170. url: `/pagesIntegral/record/index`
  171. })
  172. },
  173. // 清空列表
  174. clearPage() {
  175. const that = this;
  176. that.$set(that, `list`, [])
  177. that.$set(that, `skip`, 0)
  178. that.$set(that, `limit`, 6)
  179. that.$set(that, `page`, 0)
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. .main {
  186. display: flex;
  187. flex-direction: column;
  188. width: 100vw;
  189. height: 100vh;
  190. .one {
  191. background-color: var(--fFB1Color);
  192. padding: 5vw 2vw;
  193. display: flex;
  194. justify-content: space-between;
  195. .one_1 {
  196. color: #fff;
  197. font-size: 25px;
  198. font-weight: bold;
  199. text:last-child {
  200. padding: 0 0 0 2vw;
  201. font-size: 15px;
  202. }
  203. }
  204. .one_2 {
  205. button {
  206. background: #fff;
  207. color: var(--fFB1Color);
  208. border-radius: 25px;
  209. font-size: 14px;
  210. }
  211. }
  212. }
  213. .two {
  214. position: relative;
  215. flex-grow: 1;
  216. padding: 2vw 0 0 0;
  217. .list {
  218. width: 92vw;
  219. border: 0.5vw solid var(--f1Color);
  220. margin: 2vw 2vw 0 1.5vw;
  221. padding: 2vw;
  222. border-radius: 5px;
  223. .other {
  224. .other_1 {
  225. font-size: var(--font16Size);
  226. margin: 0 0 1vw 0;
  227. .integral {
  228. color: var(--fFB1Color);
  229. }
  230. text {
  231. margin: 0 0 0 2vw;
  232. color: var(--f85Color);
  233. font-size: var(--font14Size);
  234. }
  235. }
  236. }
  237. }
  238. }
  239. }
  240. .scroll-view {
  241. position: absolute;
  242. top: 0;
  243. left: 0;
  244. right: 0;
  245. bottom: 0;
  246. .list-scroll-view {
  247. display: flex;
  248. flex-direction: column;
  249. }
  250. }
  251. .is_bottom {
  252. text-align: center;
  253. text {
  254. padding: 2vw 0;
  255. display: inline-block;
  256. color: #858585;
  257. font-size: 14px;
  258. }
  259. }
  260. </style>