show.vue 8.9 KB

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