show.vue 8.5 KB

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