show.vue 7.6 KB

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