show.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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/image/show.png"></image>
  7. </view>
  8. <view class="show-item-label">能耗走势图</view>
  9. </view>
  10. <view class="charts-box">
  11. <qiun-data-charts type="demotype" :chartData="chartData" :opts="chartOpts"
  12. tooltipFormat="tooltipDemo1" />
  13. </view>
  14. <view class="select-show">
  15. <button :class="[btn ? 'first-button-bg' : 'first-button']"
  16. @tap="getEnergyConsumption('day')">日</button>
  17. <button :class="[btn ? 'first-button' : 'first-button-bg']"
  18. @tap="getEnergyConsumption('month')">月</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/image/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. <text class="item-list-txt">{{item.re_time}}</text>
  40. </view>
  41. <text class="item-list-txt show-money">{{item.account}}</text>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. btn: false,
  53. chartData: {
  54. categories: [],
  55. series: [{
  56. data: [],
  57. }]
  58. },
  59. chartOpts: {
  60. yAxis: {
  61. data: [{
  62. max: 0
  63. }]
  64. }
  65. },
  66. date: this.$getDate({
  67. format: true
  68. }),
  69. startDate: this.$getDate('start_date'),
  70. endDate: this.$getDate('end_date'),
  71. all_data: '', // 所有数据
  72. list: [], // 消费列表
  73. code: '',
  74. ceshi: 'code',
  75. stu_number: '', // 学号
  76. roomSelect: '', // 选择的宿舍号
  77. changeDate: false // 是否是手动选择日期
  78. }
  79. },
  80. onLoad() {
  81. try {
  82. // 获取学号
  83. this.stu_number = this.$store.state.userInfo.card_number
  84. this.roomSelect = this.$store.state.building.roomSelect
  85. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(this
  86. .roomSelect) == 'undefined') {
  87. const userinfo = uni.getStorageSync('userinfo_storage_key')
  88. if (userinfo) {
  89. this.stu_number = userinfo.card_number
  90. this.roomSelect = userinfo.campus + userinfo.dorm_number
  91. } else {
  92. uni.redirectTo({
  93. url: '../index/index'
  94. })
  95. uni.showToast({
  96. icon: 'none',
  97. title: '学号或宿舍号为空,请授权',
  98. duration: 3000
  99. })
  100. return
  101. }
  102. }
  103. // console.log(this.stu_number);
  104. // console.log(this.roomSelect);
  105. // 能耗记录
  106. this.getEnergyConsumption('month')
  107. // 缴费记录
  108. this.get_jiaofeijilu()
  109. } catch (e) {
  110. console.log(e);
  111. }
  112. },
  113. methods: {
  114. /**
  115. * 按日、月获取能耗
  116. */
  117. getEnergyConsumption(dayOrMonth) {
  118. // 按日、月显示能耗
  119. this.get_nenghaojilu(dayOrMonth)
  120. },
  121. /**
  122. * 获取选择日期
  123. */
  124. bindDateChange: function(e) {
  125. this.date = e.detail.value
  126. this.changeDate = true
  127. // 缴费记录
  128. this.get_jiaofeijilu()
  129. },
  130. /**
  131. * 获取缴费记录
  132. */
  133. async get_jiaofeijilu() {
  134. // console.log(this.stu_number);
  135. if (this.stu_number != '') {
  136. const res = await this.$myRequest({
  137. host: this.ceshi,
  138. url: '/HotWaters/elqueyRecordEle.action',
  139. method: 'POST',
  140. header: {
  141. 'content-type': 'application/x-www-form-urlencoded'
  142. },
  143. data: {
  144. 'stu_number': this.stu_number,
  145. 're_time': this.date
  146. }
  147. })
  148. // console.log(res);
  149. if (res.data.mess == '未查到记录') {
  150. if (this.changeDate) {
  151. uni.showToast({
  152. title: '该月无缴费记录',
  153. icon: 'success',
  154. success: (res) => {
  155. this.changeDate = false
  156. }
  157. });
  158. this.list = []
  159. }
  160. } else {
  161. // 充值绑定显示到界面
  162. for (var i = 0; i < res.data.data.length; i++) {
  163. this.list.push(res.data.data[i])
  164. }
  165. }
  166. } else {
  167. uni.showToast({
  168. title: '学号为空',
  169. icon: 'success'
  170. });
  171. }
  172. },
  173. /**
  174. * 能耗记录
  175. */
  176. async get_nenghaojilu(dayOrMonth) {
  177. // console.log(this.roomSelect);
  178. var reg = /[\u4e00-\u9fa5]/g;
  179. var str = this.roomSelect;
  180. var dom = str.replace(reg, "");
  181. if (dom != '' && typeof(dom) != 'undefined') {
  182. let res = null;
  183. if (dayOrMonth == 'day') {
  184. this.btn = true
  185. res = await this.$myRequest({
  186. host: this.ceshi,
  187. url: '/HotWaters/elqueryDayPower.action',
  188. method: 'POST',
  189. header: {
  190. 'content-type': 'application/x-www-form-urlencoded'
  191. },
  192. data: {
  193. 'dom': dom
  194. }
  195. })
  196. // console.log(res.data.data);
  197. if (res.data.code != 200) {
  198. return
  199. }
  200. let chrt_data = {
  201. categories: [],
  202. series: [{
  203. data: [],
  204. }],
  205. }
  206. let elc_max = -1.0
  207. let dt = ''
  208. for (var i = 0; i < res.data.data.length; i++) {
  209. dt = res.data.data[i].dataTime
  210. chrt_data.categories.push(dt.substr(dt.indexOf('-') + 1, dt.length))
  211. chrt_data.series[0].data.push(res.data.data[i].use_elc)
  212. if (parseFloat(res.data.data[i].use_elc) > parseFloat(elc_max)) {
  213. elc_max = res.data.data[i].use_elc
  214. }
  215. }
  216. let m = parseFloat(Math.abs(elc_max))
  217. // console.log(chrt_data);
  218. if (elc_max == 0.0) {
  219. setTimeout(() => {
  220. this.chartOpts.yAxis.data[0].max = parseInt(10)
  221. this.chartData = chrt_data;
  222. }, 1000);
  223. } else {
  224. setTimeout(() => {
  225. this.chartOpts.yAxis.data[0].max = parseInt(m + 5)
  226. this.chartData = chrt_data;
  227. }, 1000);
  228. }
  229. } else {
  230. this.btn = false
  231. res = await this.$myRequest({
  232. host: this.ceshi,
  233. url: '/HotWaters/buildgetMonthBill.action',
  234. method: 'POST',
  235. header: {
  236. 'content-type': 'application/x-www-form-urlencoded'
  237. },
  238. data: {
  239. 'roomSelect': this.roomSelect
  240. }
  241. })
  242. // console.log(res);
  243. if (res.data.mess == '未查询到数据') {
  244. return
  245. }
  246. let chrt_data = {
  247. categories: [],
  248. series: [{
  249. data: [],
  250. }],
  251. }
  252. let elc_max = 0.0
  253. for (var i = 0; i < res.data.date_time.length; i++) {
  254. chrt_data.categories.push(res.data.date_time[i])
  255. chrt_data.series[0].data.push(res.data.use_elc[i])
  256. if (parseFloat(res.data.use_elc[i]) > parseFloat(elc_max)) {
  257. elc_max = res.data.use_elc[i]
  258. }
  259. }
  260. let m = parseFloat(Math.abs(elc_max))
  261. // console.log(chrt_data);
  262. setTimeout(() => {
  263. this.chartOpts.yAxis.data[0].max = parseInt(m + (m / 4.0))
  264. this.chartData = chrt_data;
  265. }, 1000);
  266. }
  267. } else {
  268. uni.showToast({
  269. title: '宿舍号为空',
  270. icon: 'success'
  271. });
  272. }
  273. }
  274. }
  275. }
  276. </script>
  277. <style>
  278. @import url("show.css");
  279. </style>