show.vue 9.2 KB

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