rechargeRecord.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="container">
  3. <view class="line"></view>
  4. <view class="uni-list-cell-db">
  5. <picker mode="date" :value="date" fields="month" :start="startDate" :end="endDate" @change="bindDateChange">
  6. <view class="uni-input">
  7. <text>{{date}}</text>
  8. <text class="iconfont icon-arrow-down"></text>
  9. </view>
  10. </picker>
  11. </view>
  12. <view class="line"></view>
  13. <scroll-view scroll-y="true" :style="{height: screenHeight}" @scrolltoupper="scroll_to_upper"
  14. @scrolltolower="scroll_to_lower">
  15. <view class="item-list" v-for="(item, i) in chongzhi_items" :key="i">
  16. <view class="item-left">
  17. <image src="../static/images/chongzhi-icon.png" mode=""></image>
  18. <view class="left-desc">
  19. <text class="item-list-title">{{item.desc}}</text>
  20. <text class="item-list-time">{{item.begin_time}}</text>
  21. </view>
  22. </view>
  23. <text class="item-right">{{numFilter(item.use_amount)}}</text>
  24. </view>
  25. </scroll-view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. screenHeight: 0,
  33. stu_number: '', // 学号
  34. date: this.$getDate({
  35. format: true
  36. }),
  37. startDate: this.$getDate('start_date'),
  38. endDate: this.$getDate('end_date'),
  39. chongzhi_items: [{
  40. desc: '手机充值',
  41. begin_time: '10-12 11:15:15',
  42. use_amount: '-20.00'
  43. }, {
  44. desc: '手机充值',
  45. begin_time: '10-12 11:15:15',
  46. use_amount: '-20.00'
  47. }, {
  48. desc: '手机充值',
  49. begin_time: '10-12 11:15:15',
  50. use_amount: '-20.00'
  51. }], // 消费记录
  52. ceshi: 'code',
  53. }
  54. },
  55. onLoad() {
  56. if (this.stu_number && typeof(this.stu_number) != 'undefined') {
  57. // 获取基本信息
  58. this.get_base_info('options', 'onShow')
  59. }
  60. },
  61. onShow() {
  62. // 从新计算高度
  63. // setTimeout(() => {
  64. this.calc_screen_height()
  65. // }, 1500)
  66. },
  67. methods: {
  68. /**
  69. * 滚动到顶部提示
  70. */
  71. scroll_to_upper() {
  72. uni.showToast({
  73. title: '到顶了!',
  74. icon: 'none',
  75. duration: 500
  76. })
  77. },
  78. /**
  79. * 滚动到底部提示
  80. */
  81. scroll_to_lower() {
  82. uni.showToast({
  83. title: '到底了!',
  84. icon: 'none',
  85. duration: 500
  86. })
  87. },
  88. /**
  89. * 保留小数点数值后两位,尾数四舍五入
  90. * @param {Object} value
  91. */
  92. numFilter(value) {
  93. // 截取当前数据到小数点后两位
  94. let realVal = parseFloat(value).toFixed(2)
  95. return realVal
  96. },
  97. /**
  98. * 获取基本信息
  99. */
  100. get_base_info(options, param) {
  101. // console.log(options);
  102. try {
  103. // 获取学号
  104. this.stu_number = this.$store.state.userInfo.card_number
  105. if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') {
  106. const userinfo = uni.getStorageSync('userinfo_storage_key')
  107. if (userinfo) {
  108. this.stu_number = userinfo.card_number
  109. } else {
  110. uni.navigateTo({
  111. url: '../index/index?from=' + options.from
  112. })
  113. uni.showToast({
  114. icon: 'none',
  115. title: '学号为空,请进行授权',
  116. duration: 3000
  117. });
  118. return
  119. }
  120. }
  121. } catch (e) {
  122. console.log('获取基本信息:' + e.message);
  123. }
  124. if (param == 'onShow') {
  125. if (this.$store.state.payInfo.from == 'reshui_pay') {
  126. uni.showToast({
  127. title: this.$store.state.payInfo.resultMsg,
  128. icon: 'success',
  129. success: () => {
  130. this.$store.state.payInfo.resultMsg = ''
  131. this.$store.state.payInfo.from = ''
  132. }
  133. })
  134. }
  135. }
  136. // 获取code
  137. this.getCode(options, param)
  138. },
  139. /**
  140. * 获得code
  141. */
  142. getCode(options, param) {
  143. uni.login({
  144. success: (res) => {
  145. // console.log('getCode', res);
  146. if (res.code) {
  147. // 请求服务器,获得openid
  148. this.getOpenId(options, res.code, param)
  149. } else {
  150. uni.showToast({
  151. title: res.errMsg,
  152. icon: 'none'
  153. });
  154. }
  155. }
  156. })
  157. },
  158. /**
  159. * 请求服务器,获得openid
  160. */
  161. async getOpenId(options, param_code, param) {
  162. const res = await this.$myRequest({
  163. host: this.ceshi,
  164. url: '/HotWaters/wpget_stu.action',
  165. method: 'POST',
  166. header: {
  167. 'content-type': 'application/x-www-form-urlencoded'
  168. },
  169. data: {
  170. code: param_code
  171. }
  172. })
  173. // console.log(res);
  174. if (res.data.mess == '返回成功') {
  175. // stu_number是否存在
  176. let cardNumber = res.data.info[0].card_number
  177. if (typeof(cardNumber) != 'undefined' && cardNumber != '' && JSON.stringify(cardNumber) != '{}') {
  178. // 学号 和 姓名
  179. this.stu_number = res.data.info[0].stu_number
  180. this.user_name = res.data.info[0].user_name
  181. // 剩余金额
  182. this.amount = res.data.info[0].balance.toFixed(2)
  183. // if (this.amount > 0)
  184. this.$store.state.reshui_amount = this.amount
  185. // 组合楼栋宿舍号
  186. this.dorm_number = res.data.info[0].build + res.data.info[0].dom
  187. // 校区
  188. // this.compus = res.data.info[0].campus
  189. if (param == 'onLoad' && typeof(options.from) != 'undefined' && options.from != 0) {
  190. // 初始化蓝牙
  191. this.openBluetoothAdapter()
  192. }
  193. // 请求选定的月份消费记录
  194. this.request_consumption_records()
  195. } else {
  196. uni.showToast({
  197. title: '未获取到学号!',
  198. icon: 'success'
  199. });
  200. uni.navigateTo({
  201. url: '../index/index?from=' + options.from
  202. })
  203. }
  204. } else if (res.data.mess == '未查询到用户信息') {
  205. // 数据库中 未查询到用户信息,就清除本地存储
  206. uni.removeStorageSync('userinfo_storage_key');
  207. uni.showToast({
  208. title: '获取用户信息失败!'
  209. })
  210. if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
  211. uni.navigateTo({
  212. url: '../index/index?from=' + options.from
  213. })
  214. } else {
  215. uni.redirectTo({
  216. url: '../index/index?from=0'
  217. });
  218. }
  219. }
  220. },
  221. /**
  222. * 选择消费年月
  223. */
  224. bindDateChange(e) {
  225. this.date = e.detail.value
  226. this.changeDate = true
  227. // 请求选定的月份消费记录
  228. this.request_consumption_records()
  229. },
  230. /**
  231. * 请求选定的月份消费记录
  232. */
  233. async request_consumption_records() {
  234. try {
  235. if (this.stu_number != '' && typeof(this.stu_number) != 'undefined') {
  236. const res = await this.$myRequest({
  237. host: this.ceshi,
  238. url: '/HotWaters/wpqueryConsume.action',
  239. method: 'POST',
  240. header: {
  241. 'content-type': 'application/x-www-form-urlencoded'
  242. },
  243. data: {
  244. stu_number: this.stu_number,
  245. begin_time: this.date
  246. }
  247. });
  248. // console.log(res);
  249. if (res.data.mess == '返回成功') {
  250. this.chongzhi_items = []
  251. // 消费记录
  252. let items = res.data.data
  253. for (var i = 0; i < items.length; i++) {
  254. this.chongzhi_items.push(items[i])
  255. }
  256. } else {
  257. if (this.changeDate) {
  258. uni.showToast({
  259. icon: 'success',
  260. title: res.data.mess,
  261. success: () => {
  262. this.changeDate = false
  263. }
  264. })
  265. if (res.data.mess == '本月无消费记录') {
  266. this.chongzhi_items = []
  267. }
  268. }
  269. }
  270. } else {
  271. uni.showToast({
  272. icon: 'success',
  273. title: '未获得学号'
  274. })
  275. }
  276. } catch (e) {
  277. console.log('请求选定的月份消费记录:' + e.message);
  278. }
  279. },
  280. /**
  281. * 计算屏幕的高度
  282. */
  283. calc_screen_height() {
  284. uni.getSystemInfo({
  285. success: res => {
  286. let h = ((res.screenHeight * (750 / res.windowWidth)) - 280) //将px 转换rpx
  287. this.screenHeight = Math.floor(h) + 'rpx'
  288. }
  289. });
  290. }
  291. }
  292. }
  293. </script>
  294. <style lang="scss">
  295. .container {
  296. display: flex;
  297. flex-direction: column;
  298. font-size: 28rpx;
  299. font-family: "Microsoft YaHei-3970(82674968)";
  300. width: 730rpx;
  301. padding: 10rpx;
  302. .line {
  303. height: 20rpx;
  304. }
  305. .uni-list-cell-db {
  306. .uni-input {
  307. display: flex;
  308. justify-content: space-around;
  309. align-items: center;
  310. width: 200rpx;
  311. height: 60rpx;
  312. border: 2rpx solid #CCCCCC;
  313. border-radius: 6rpx;
  314. font-size: 32upx;
  315. }
  316. }
  317. .item-list {
  318. display: flex;
  319. justify-content: space-between;
  320. align-items: center;
  321. padding: 20rpx 10rpx;
  322. border-bottom: 1rpx solid #CCCCCC;
  323. .item-left {
  324. display: flex;
  325. align-items: center;
  326. image {
  327. width: 80rpx;
  328. height: 80rpx;
  329. }
  330. .left-desc {
  331. display: flex;
  332. flex-direction: column;
  333. justify-content: space-around;
  334. margin-left: 20rpx;
  335. .item-list-title {
  336. font-size: 32upx;
  337. font-weight: bold;
  338. }
  339. .item-list-time {
  340. color: #808080;
  341. }
  342. }
  343. }
  344. .item-right {
  345. font-size: 36upx;
  346. font-weight: bold;
  347. color: #333333;
  348. }
  349. }
  350. }
  351. </style>