耀实惠小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
5.7 KiB

  1. <template>
  2. <view>
  3. <view class="title_box">
  4. <image class="bg" :src="img_url + 'gold_bg.png'" mode=""></image>
  5. <text class="my_title">我的消费金</text>
  6. <text class="my_money">{{ userInfo.consumption }}</text>
  7. </view>
  8. <u-picker mode="time" v-model="show_time" :params="params" @confirm="getTime"></u-picker>
  9. <!-- 数据展示 -->
  10. <view class="item_box">
  11. <view class="item_title" @click="toChangeTime">
  12. <text class="time">{{ data_time }}</text>
  13. <u-icon name="arrow-down"></u-icon>
  14. </view>
  15. <view class="item" v-for="(item, index) in list" :key="index">
  16. <view class="left_box">
  17. <image :src="img_url + 'gold_icon.png'" mode=""></image>
  18. <view class="text_box">
  19. <text class="title">{{ item.name }}</text>
  20. <text class="time">{{ item.createTime }}</text>
  21. </view>
  22. </view>
  23. <text class="get_num">{{ item.payType == 0 ? '+' + item.money : '-' + item.money }}</text>
  24. </view>
  25. </view>
  26. <view class="empty_box" v-if="list.length==0">
  27. <image :src="img_url+'empty.png'" alt=""></image>
  28. <text class="text_">暂无订单信息</text>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import config_img from '@/utils/js/config.js';
  34. export default {
  35. data() {
  36. return {
  37. img_url: config_img.img_url,
  38. data_time: '',
  39. default_time: '',
  40. show_time: false,
  41. params: {
  42. year: true,
  43. month: true,
  44. day: false,
  45. hour: false,
  46. minute: false,
  47. second: false
  48. },
  49. pageNo: 1,
  50. pageSize: 10,
  51. total: null,
  52. isLock: false, //上拉加载锁
  53. list: [],
  54. userInfo: {}
  55. };
  56. },
  57. onLoad() {
  58. // 获取用户信息
  59. this.getUserInfo();
  60. // this.userInfo = this.$store.state.userInfo
  61. this.default_time = new Date().getFullYear() + '-' + (new Date().getMonth() + 1 > 10 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1));
  62. this.data_time = new Date().getFullYear() + '年' + (new Date().getMonth() + 1) + '月';
  63. this.getConsumptionGold({
  64. pageNo: this.pageNo,
  65. pageSize: this.pageSize,
  66. stringDate: this.default_time.replace(/-/, '/')
  67. });
  68. },
  69. computed: {
  70. // userInfo() {
  71. // return this.$store.state.userInfo
  72. // }
  73. },
  74. async onPullDownRefresh() {
  75. this.pageNo= 1;
  76. this.total = null;
  77. this.list = [];
  78. await this.getUserInfo();
  79. await this.getConsumptionGold({
  80. pageNo: this.pageNo,
  81. pageSize: this.pageSize,
  82. stringDate: this.default_time.replace(/-/,'/')
  83. })
  84. },
  85. onReachBottom() {
  86. if(this.isLock) {
  87. if(this.total !== null && this.pageNo * this.pageSize >= this.total){
  88. this.isLock = false;
  89. this.$Toast('没有更多数据了哦!');
  90. setTimeout(()=>{
  91. this.isLock = true;
  92. },3000)
  93. return
  94. }
  95. this.pageNo+=1;
  96. this.getConsumptionGold({
  97. pageNo: this.pageNo,
  98. pageSize: this.pageSize,
  99. stringDate: this.default_time.replace(/-/,'/')
  100. })
  101. }
  102. },
  103. methods: {
  104. // 获取用户信息
  105. getUserInfo () {
  106. return new Promise((resolve, reject) => {
  107. this.$api('getUserInfo').then(res => {
  108. let { code, result, message} = res;
  109. if(code == 200){
  110. let userInfo = {...result.account, ...result.userInfo }
  111. // 更新用户信息缓存
  112. this.userInfo = userInfo
  113. this.$storage.setStorage("__user_info", userInfo)
  114. resolve()
  115. }else {
  116. reject(message)
  117. }
  118. }).catch(err => {
  119. reject(err.message)
  120. })
  121. })
  122. },
  123. toChangeTime() {
  124. this.show_time = true;
  125. },
  126. getConsumptionGold(params = {}) {
  127. uni.showLoading();
  128. this.$api('getConsumptionGold', params)
  129. .then(res => {
  130. let { code, result, message } = res;
  131. if (code === 200) {
  132. console.log(result.records);
  133. this.list = this.list.concat(result.records);
  134. uni.stopPullDownRefresh();
  135. uni.hideLoading();
  136. } else {
  137. this.$Toast(message);
  138. uni.stopPullDownRefresh();
  139. uni.hideLoading();
  140. }
  141. this.isLock = true;
  142. })
  143. .catch(err => {
  144. this.isLock = true;
  145. uni.stopPullDownRefresh();
  146. this.$Toast(err.message);
  147. });
  148. },
  149. getTime(e) {
  150. this.data_time = e.year + '年' + (e.month > 10 ? e.month : e.month.replace(/0/, '')) + '月';
  151. this.default_time = `${e.year}-${e.month}`;
  152. // 初始化数据
  153. this.list = [];
  154. this.pageNo = 1;
  155. this.total = null;
  156. const params = {
  157. pageNo: this.pageNo,
  158. pageSize: this.pageSize,
  159. stringDate: `${e.year}/${e.month}`
  160. };
  161. this.getConsumptionGold(params);
  162. }
  163. }
  164. };
  165. </script>
  166. <style lang="scss" scoped>
  167. .title_box {
  168. position: relative;
  169. display: flex;
  170. flex-direction: column;
  171. text-align: center;
  172. margin-bottom: 68rpx;
  173. color: #fff;
  174. .bg {
  175. position: absolute;
  176. height: 239rpx;
  177. z-index: -1;
  178. }
  179. .my_title {
  180. margin-top: 30rpx;
  181. font-size: 36rpx;
  182. }
  183. .my_money {
  184. font-size: 55rpx;
  185. font-weight: bold;
  186. margin-top: 26rpx;
  187. }
  188. }
  189. .empty_box{
  190. width: 100%;
  191. height: 100%;
  192. display: flex;
  193. flex-direction: column;
  194. justify-content: center;
  195. align-items: center;
  196. image{
  197. width: 371rpx;
  198. height: 371rpx;
  199. }
  200. .text_{
  201. margin-top: 10rpx;
  202. font-size: 36rpx;
  203. font-weight: bold;
  204. color: #01AEEA;
  205. }
  206. }
  207. .item_box {
  208. .item_title {
  209. padding-top: 33rpx;
  210. margin-left: 60rpx;
  211. .time {
  212. margin-right: 22rpx;
  213. font-size: 32rpx;
  214. }
  215. }
  216. .item {
  217. width: 670rpx;
  218. margin: 0 auto;
  219. border-bottom: 1rpx solid #e0e0e0;
  220. display: flex;
  221. justify-content: space-between;
  222. align-items: center;
  223. &:last-child {
  224. border-bottom: none;
  225. }
  226. .get_num {
  227. font-size: 30rpx;
  228. color: #dd0f00;
  229. }
  230. .left_box {
  231. display: flex;
  232. align-items: center;
  233. margin-top: 21rpx;
  234. padding-bottom: 20rpx;
  235. image {
  236. width: 58rpx;
  237. height: 58rpx;
  238. margin-right: 30rpx;
  239. }
  240. .text_box {
  241. display: flex;
  242. flex-direction: column;
  243. .title {
  244. font-size: 32rpx;
  245. font-weight: bold;
  246. color: #333333;
  247. }
  248. .time {
  249. font-size: 26rpx;
  250. color: #9a9a9a;
  251. }
  252. }
  253. }
  254. }
  255. }
  256. </style>