show.vue 8.6 KB

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