show.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <view class="container">
  3. <view class="show-item">
  4. <view class="show-elec-label">
  5. <view class="show-item-logol">
  6. <image class="show-item-logo-left" src="../static/images/show.png"></image>
  7. </view>
  8. <view class="show-item-label">消费走势图</view>
  9. </view>
  10. <view class="charts-box">
  11. <qiun-data-charts type="line" :chartData="chartData" :opts="chartOpts" :ontouch="true"
  12. tooltipFormat="tooltipDemo1" />
  13. </view>
  14. <view class="select-show">
  15. <button :class="[btn ? 'first-button-bg' : 'first-button']"
  16. @tap="getEnergyConsumption('month')">月</button>
  17. <button :class="[btn ? 'first-button' : 'first-button-bg']"
  18. @tap="getEnergyConsumption('year')">年</button>
  19. </view>
  20. </view>
  21. <view class="show-item-date">
  22. <view class="show-elec-label">
  23. <view class="show-item-logol">
  24. <image class="show-item-logo-left" src="../static/images/record.png"></image>
  25. </view>
  26. <view class="show-item-label show-label">缴费记录</view>
  27. </view>
  28. <view class="select-date">
  29. <picker mode="date" fields="month" :start="startDate" :end="endDate" @change="bindDateChange">
  30. <view class="uni-input">
  31. <text class="uni-input-label">{{date}}</text>
  32. <text class="iconfont icon-arrow-down"></text>
  33. </view>
  34. </picker>
  35. <view class="uni-list">
  36. <view class="item-list" v-for="(item, i) in list" :key="i">
  37. <view class="item-list-left">
  38. <text class="item-list-txt">{{item.user_name}}</text>
  39. <view class="info-txt">
  40. <view class="up-txt">
  41. <text class="item-list-txt">{{item.school}}</text>
  42. <text class="item-list-txt">{{item.room}}</text>
  43. </view>
  44. <view class="bottom-txt">
  45. <text class="item-list-txt">{{item.re_time}}</text>
  46. </view>
  47. </view>
  48. </view>
  49. <text class="item-list-txt show-money">{{item.account}}</text>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. btn: false,
  61. chartData: {
  62. categories: [],
  63. series: []
  64. },
  65. chartOpts: {
  66. color: ["#1890FF", "#91CB74", "#FAC858"],
  67. padding: [15, 10, 0, 15],
  68. legend: {},
  69. xAxis: {
  70. disableGrid: true
  71. },
  72. yAxis: {
  73. data: [{
  74. max: 0
  75. }]
  76. },
  77. extra: {
  78. line: {
  79. type: "curve",
  80. width: 2
  81. }
  82. }
  83. },
  84. date: this.$getDate({
  85. format: true
  86. }),
  87. startDate: this.$getDate('start_date'),
  88. endDate: this.$getDate('end_date'),
  89. all_data: '', // 所有数据
  90. list: [], // 消费列表
  91. code: '',
  92. ceshi: 'code',
  93. stu_number: '', // 学号
  94. roomSelect: '', // 选择的宿舍号
  95. changeDate: false // 是否是手动选择日期
  96. }
  97. },
  98. onLoad() {
  99. try {
  100. // 获取学号
  101. this.stu_number = this.$store.state.userInfo.card_number
  102. this.roomSelect = this.$store.state.building.roomSelect
  103. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(this
  104. .roomSelect) == 'undefined') {
  105. const userinfo = uni.getStorageSync('userinfo_storage_key')
  106. if (userinfo) {
  107. this.stu_number = userinfo.card_number
  108. this.roomSelect = userinfo.campus + userinfo.dorm_number
  109. } else {
  110. uni.redirectTo({
  111. url: '../index/index'
  112. })
  113. uni.showToast({
  114. icon: 'none',
  115. title: '学号或宿舍号为空,请授权',
  116. duration: 3000
  117. })
  118. return
  119. }
  120. }
  121. // console.log(this.stu_number);
  122. // console.log(this.roomSelect);
  123. // 缴费记录
  124. this.get_jiaofeijilu()
  125. } catch (e) {
  126. console.log(e);
  127. }
  128. },
  129. onReady() {
  130. // 消费走势
  131. this.getEnergyConsumption('month')
  132. },
  133. methods: {
  134. /**
  135. * 按月、年获取消费记录
  136. */
  137. getEnergyConsumption(dayOrMonth) {
  138. // 按月、年获取消费记录
  139. this.get_nenghaojilu(dayOrMonth)
  140. },
  141. /**
  142. * 获取选择日期
  143. */
  144. bindDateChange: function(e) {
  145. this.date = e.detail.value
  146. this.changeDate = true
  147. // 缴费记录
  148. this.get_jiaofeijilu()
  149. },
  150. /**
  151. * 获取缴费记录
  152. */
  153. async get_jiaofeijilu() {
  154. // console.log(this.stu_number);
  155. if (this.stu_number != '') {
  156. const res = await this.$myRequest({
  157. host: this.ceshi,
  158. url: '/HotWaters/elqueyRecordEle.action',
  159. method: 'POST',
  160. header: {
  161. 'content-type': 'application/x-www-form-urlencoded'
  162. },
  163. data: {
  164. 'stu_number': this.stu_number,
  165. 're_time': this.date
  166. }
  167. })
  168. // console.log(res);
  169. if (res.data.mess == '未查到记录') {
  170. if (this.changeDate) {
  171. uni.showToast({
  172. title: '该月无缴费记录',
  173. icon: 'success',
  174. success: (res) => {
  175. this.changeDate = false
  176. }
  177. });
  178. this.list = []
  179. }
  180. } else {
  181. // 充值绑定显示到界面
  182. for (var i = 0; i < res.data.data.length; i++) {
  183. this.list.push(res.data.data[i])
  184. }
  185. }
  186. } else {
  187. uni.showToast({
  188. title: '学号为空',
  189. icon: 'success'
  190. });
  191. }
  192. },
  193. /**
  194. * 按月、年获取消费记录
  195. */
  196. async get_nenghaojilu(dayOrMonth) {
  197. // console.log(this.roomSelect);
  198. var reg = /[\u4e00-\u9fa5]/g;
  199. var str = this.roomSelect;
  200. var dom = str.replace(reg, "");
  201. if (dom != '' && typeof(dom) != 'undefined') {
  202. let res = null;
  203. if (dayOrMonth == 'month') {
  204. this.btn = true
  205. res = await this.$myRequest({
  206. host: this.ceshi,
  207. // url: '/HotWaters/elqueryDayPower.action',
  208. url: '/HotWaters/elMonthlist.action',
  209. method: 'POST',
  210. header: {
  211. 'content-type': 'application/x-www-form-urlencoded'
  212. },
  213. data: {
  214. 'dom': dom,
  215. 'page': 1,
  216. 'rows': 12
  217. }
  218. })
  219. // console.log(res.data.rows);
  220. // console.log(res.data);
  221. if (res.data.rows.length == 0) {
  222. return
  223. }
  224. if (typeof res.data.rows === 'undefined') {
  225. uni.showToast({
  226. title: '加载数据异常',
  227. duration: 1500
  228. })
  229. return
  230. }
  231. let chrt_data = {
  232. categories: [],
  233. series: [],
  234. }
  235. let elc_max = -1.0
  236. let dt = ''
  237. let temp = 0
  238. let data = []
  239. for (var i = 0; i < res.data.rows.length; i++) {
  240. dt = res.data.rows[i].dataTime
  241. chrt_data.categories.push(parseInt(dt.substr(dt.indexOf('-') + 1, dt.length)) + '月')
  242. temp = res.data.rows[i].totalMoney
  243. temp = temp.toFixed(2)
  244. data.push(temp)
  245. if (parseFloat(temp) > parseFloat(elc_max)) {
  246. elc_max = temp
  247. }
  248. }
  249. let items = {
  250. name: '金额',
  251. data: data
  252. }
  253. chrt_data.series.push(items)
  254. let m = parseFloat(Math.abs(elc_max))
  255. // console.log(chrt_data);
  256. if (elc_max == 0.0) {
  257. setTimeout(() => {
  258. this.chartOpts.yAxis.data[0].max = parseInt(10)
  259. this.chartData = chrt_data;
  260. }, 1000);
  261. } else {
  262. setTimeout(() => {
  263. this.chartOpts.yAxis.data[0].max = parseInt(m + 5)
  264. this.chartData = chrt_data;
  265. }, 1000);
  266. }
  267. } else {
  268. this.btn = false
  269. let _this = this
  270. uni.showToast({
  271. mask: true,
  272. title: '年消费更新中…',
  273. success() {
  274. _this.btn = true
  275. }
  276. })
  277. return
  278. res = await this.$myRequest({
  279. host: this.ceshi,
  280. url: '/HotWaters/buildgetMonthBill.action',
  281. method: 'POST',
  282. header: {
  283. 'content-type': 'application/x-www-form-urlencoded'
  284. },
  285. data: {
  286. 'roomSelect': this.roomSelect
  287. }
  288. })
  289. // console.log(res);
  290. if (res.data.mess == '未查询到数据') {
  291. return
  292. }
  293. let chrt_data = {
  294. categories: [],
  295. series: [{
  296. data: [],
  297. }],
  298. }
  299. let elc_max = 0.0
  300. for (var i = 0; i < res.data.date_time.length; i++) {
  301. chrt_data.categories.push(res.data.date_time[i])
  302. chrt_data.series[0].data.push(res.data.use_elc[i])
  303. if (parseFloat(res.data.use_elc[i]) > parseFloat(elc_max)) {
  304. elc_max = res.data.use_elc[i]
  305. }
  306. }
  307. let m = parseFloat(Math.abs(elc_max))
  308. // console.log(chrt_data);
  309. setTimeout(() => {
  310. this.chartOpts.yAxis.data[0].max = parseInt(m + (m / 4.0))
  311. this.chartData = chrt_data;
  312. }, 1000);
  313. }
  314. } else {
  315. uni.showToast({
  316. title: '宿舍号为空',
  317. icon: 'success'
  318. });
  319. }
  320. }
  321. }
  322. }
  323. </script>
  324. <style>
  325. @import url("show.css");
  326. </style>