show.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  67. "#ea7ccc"
  68. ],
  69. padding: [15, 10, 0, 15],
  70. legend: {},
  71. xAxis: {
  72. disableGrid: true
  73. },
  74. yAxis: {
  75. data: [{
  76. max: 0
  77. }]
  78. },
  79. extra: {
  80. line: {
  81. type: "curve",
  82. width: 2
  83. }
  84. }
  85. },
  86. date: this.$getDate({
  87. format: true
  88. }),
  89. startDate: this.$getDate('start_date'),
  90. endDate: this.$getDate('end_date'),
  91. all_data: '', // 所有数据
  92. list: [], // 消费列表
  93. code: '',
  94. ceshi: 'code',
  95. stu_number: '', // 学号
  96. roomSelect: '', // 选择的宿舍号
  97. changeDate: false // 是否是手动选择日期
  98. }
  99. },
  100. onLoad() {
  101. try {
  102. // 获取学号
  103. this.stu_number = this.$store.state.userInfo.card_number
  104. this.roomSelect = this.$store.state.building.roomSelect
  105. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(this
  106. .roomSelect) == 'undefined') {
  107. const userinfo = uni.getStorageSync('userinfo_storage_key')
  108. if (userinfo) {
  109. this.stu_number = userinfo.card_number
  110. this.roomSelect = userinfo.campus + userinfo.dorm_number
  111. } else {
  112. uni.redirectTo({
  113. url: '../index/index'
  114. })
  115. uni.showToast({
  116. icon: 'none',
  117. title: '学号或宿舍号为空,请授权',
  118. duration: 3000
  119. })
  120. return
  121. }
  122. }
  123. // console.log(this.stu_number);
  124. // console.log(this.roomSelect);
  125. // 缴费记录
  126. this.get_jiaofeijilu()
  127. } catch (e) {
  128. console.log(e);
  129. }
  130. },
  131. onReady() {
  132. // 消费走势
  133. this.getEnergyConsumption('month')
  134. },
  135. methods: {
  136. /**
  137. * 按月、年获取消费记录
  138. */
  139. getEnergyConsumption(dayOrMonth) {
  140. // 按月、年获取消费记录
  141. this.get_nenghaojilu(dayOrMonth)
  142. },
  143. /**
  144. * 获取选择日期
  145. */
  146. bindDateChange: function(e) {
  147. this.date = e.detail.value
  148. this.changeDate = true
  149. // 缴费记录
  150. this.get_jiaofeijilu()
  151. },
  152. /**
  153. * 获取缴费记录
  154. */
  155. async get_jiaofeijilu() {
  156. // console.log(this.stu_number);
  157. if (this.stu_number != '') {
  158. const res = await this.$myRequest({
  159. host: this.ceshi,
  160. url: '/HotWaters/elqueyRecordEle.action',
  161. method: 'POST',
  162. header: {
  163. 'content-type': 'application/x-www-form-urlencoded'
  164. },
  165. data: {
  166. 'stu_number': this.stu_number,
  167. 're_time': this.date
  168. }
  169. })
  170. // console.log(res);
  171. if (res.data.mess == '未查到记录') {
  172. if (this.changeDate) {
  173. uni.showToast({
  174. title: '该月无缴费记录',
  175. icon: 'success',
  176. success: (res) => {
  177. this.changeDate = false
  178. }
  179. });
  180. this.list = []
  181. }
  182. } else {
  183. // 充值绑定显示到界面
  184. for (var i = 0; i < res.data.data.length; i++) {
  185. this.list.push(res.data.data[i])
  186. }
  187. }
  188. } else {
  189. uni.showToast({
  190. title: '学号为空',
  191. icon: 'success'
  192. });
  193. }
  194. },
  195. /**
  196. * 按月、年获取消费记录
  197. */
  198. async get_nenghaojilu(dayOrMonth) {
  199. // console.log(this.roomSelect);
  200. var reg = /[\u4e00-\u9fa5]/g;
  201. var str = this.roomSelect;
  202. var dom = str.replace(reg, "");
  203. if (dom != '' && typeof(dom) != 'undefined') {
  204. let res = null;
  205. if (dayOrMonth == 'month') {
  206. this.btn = true
  207. res = await this.$myRequest({
  208. host: this.ceshi,
  209. // url: '/HotWaters/elqueryDayPower.action',
  210. url: '/HotWaters/elMonthlist.action',
  211. method: 'POST',
  212. header: {
  213. 'content-type': 'application/x-www-form-urlencoded'
  214. },
  215. data: {
  216. 'dom': dom,
  217. 'page': 1,
  218. 'rows': 12
  219. }
  220. })
  221. // console.log(res.data.rows);
  222. // console.log(res.data);
  223. if (res.data.rows.length == 0) {
  224. return
  225. }
  226. if (typeof res.data.rows === 'undefined') {
  227. uni.showToast({
  228. title: '加载数据异常',
  229. duration: 1500
  230. })
  231. return
  232. }
  233. let chrt_data = {
  234. categories: [],
  235. series: [],
  236. }
  237. let elc_max = -1.0
  238. let dt = ''
  239. let temp = 0
  240. let data = []
  241. for (var i = 0; i < res.data.rows.length; i++) {
  242. dt = res.data.rows[i].dataTime
  243. chrt_data.categories.push(parseInt(dt.substr(dt.indexOf('-') + 1, dt.length)) + '月')
  244. temp = res.data.rows[i].totalMoney
  245. temp = temp.toFixed(2)
  246. data.push(temp)
  247. if (parseFloat(temp) > parseFloat(elc_max)) {
  248. elc_max = temp
  249. }
  250. }
  251. let items = {
  252. name: '金额',
  253. data: data
  254. }
  255. chrt_data.series.push(items)
  256. let m = parseFloat(Math.abs(elc_max))
  257. // console.log(chrt_data);
  258. if (elc_max == 0.0) {
  259. setTimeout(() => {
  260. this.chartOpts.yAxis.data[0].max = parseInt(10)
  261. this.chartData = chrt_data;
  262. }, 1000);
  263. } else {
  264. setTimeout(() => {
  265. this.chartOpts.yAxis.data[0].max = parseInt(m + 5)
  266. this.chartData = chrt_data;
  267. }, 1000);
  268. }
  269. } else {
  270. this.btn = false
  271. let _this = this
  272. uni.showToast({
  273. mask: true,
  274. title: '年消费更新中…',
  275. success() {
  276. _this.btn = true
  277. }
  278. })
  279. return
  280. res = await this.$myRequest({
  281. host: this.ceshi,
  282. url: '/HotWaters/buildgetMonthBill.action',
  283. method: 'POST',
  284. header: {
  285. 'content-type': 'application/x-www-form-urlencoded'
  286. },
  287. data: {
  288. 'roomSelect': this.roomSelect
  289. }
  290. })
  291. // console.log(res);
  292. if (res.data.mess == '未查询到数据') {
  293. return
  294. }
  295. let chrt_data = {
  296. categories: [],
  297. series: [{
  298. data: [],
  299. }],
  300. }
  301. let elc_max = 0.0
  302. for (var i = 0; i < res.data.date_time.length; i++) {
  303. chrt_data.categories.push(res.data.date_time[i])
  304. chrt_data.series[0].data.push(res.data.use_elc[i])
  305. if (parseFloat(res.data.use_elc[i]) > parseFloat(elc_max)) {
  306. elc_max = res.data.use_elc[i]
  307. }
  308. }
  309. let m = parseFloat(Math.abs(elc_max))
  310. // console.log(chrt_data);
  311. setTimeout(() => {
  312. this.chartOpts.yAxis.data[0].max = parseInt(m + (m / 4.0))
  313. this.chartData = chrt_data;
  314. }, 1000);
  315. }
  316. } else {
  317. uni.showToast({
  318. title: '宿舍号为空',
  319. icon: 'success'
  320. });
  321. }
  322. }
  323. }
  324. }
  325. </script>
  326. <style>
  327. @import url("show.css");
  328. </style>