show.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. if (this.stu_number != '') {
  164. const res = await this.$myRequest({
  165. host: this.ceshi,
  166. url: '/HotWaters/elqueyRecordEle.action',
  167. method: 'POST',
  168. header: {
  169. 'content-type': 'application/x-www-form-urlencoded'
  170. },
  171. data: {
  172. 'stu_number': this.stu_number,
  173. 're_time': this.date
  174. }
  175. })
  176. // console.log(res);
  177. if (res.data.mess == '未查到记录') {
  178. if (this.changeDate) {
  179. uni.showToast({
  180. title: '该月无缴费记录',
  181. icon: 'success',
  182. success: (res) => {
  183. this.changeDate = false
  184. }
  185. });
  186. this.list = []
  187. }
  188. } else {
  189. // 充值绑定显示到界面
  190. for (var i = 0; i < res.data.data.length; i++) {
  191. this.list.push(res.data.data[i])
  192. }
  193. }
  194. } else {
  195. uni.showToast({
  196. title: '学号为空',
  197. icon: 'success'
  198. });
  199. }
  200. },
  201. /**
  202. * 按月、年获取消费记录
  203. */
  204. async get_nenghaojilu(dayOrMonth) {
  205. // console.log(this.roomSelect);
  206. var reg = /[\u4e00-\u9fa5]/g;
  207. var str = this.roomSelect;
  208. var dom = str.replace(reg, "");
  209. var _this = this;
  210. if (dom != '' && typeof dom != 'undefined') {
  211. let res = null;
  212. if (dayOrMonth == 'month') {
  213. _this.btn = true
  214. res = await _this.$myRequest({
  215. host: _this.ceshi,
  216. // url: '/HotWaters/elqueryDayPower.action',
  217. url: '/HotWaters/elMonthlist.action',
  218. method: 'POST',
  219. header: {
  220. 'content-type': 'application/x-www-form-urlencoded'
  221. },
  222. data: {
  223. 'dom': dom,
  224. 'page': 1,
  225. 'rows': 12
  226. }
  227. })
  228. // console.log(res.data.rows);
  229. // console.log(res.data);
  230. if (res.data.rows.length == 0) {
  231. return
  232. }
  233. if (typeof res.data.rows === 'undefined') {
  234. uni.showToast({
  235. title: '加载数据异常',
  236. duration: 1500
  237. })
  238. return
  239. }
  240. let chrt_data = {
  241. categories: [],
  242. series: [],
  243. }
  244. let elc_max = -1.0
  245. let dt = ''
  246. let temp = 0
  247. let data = []
  248. for (var i = 0; i < res.data.rows.length; i++) {
  249. dt = res.data.rows[i].dataTime
  250. // chrt_data.categories.push(dt.substr(dt.indexOf('-') + 1, dt.length) + '月')
  251. chrt_data.categories.push(parseInt(dt.substr(dt.indexOf('-') + 1, dt.length)) + '月')
  252. temp = (res.data.rows[i].totalMoney).toFixed(2)
  253. // temp = temp
  254. data.push(temp)
  255. if (parseFloat(temp) > parseFloat(elc_max)) {
  256. elc_max = temp
  257. }
  258. }
  259. let items = {
  260. name: '金额',
  261. data: data
  262. }
  263. chrt_data.series.push(items)
  264. let m = parseFloat(Math.abs(elc_max))
  265. // console.log(chrt_data);
  266. if (elc_max == 0.0) {
  267. setTimeout(() => {
  268. _this.chartOpts.yAxis.data[0].max = parseInt(10)
  269. _this.chartData = chrt_data;
  270. }, 500);
  271. } else {
  272. setTimeout(() => {
  273. _this.chartOpts.yAxis.data[0].max = parseInt(m + 10)
  274. _this.chartData = chrt_data;
  275. }, 500);
  276. }
  277. } else {
  278. _this.btn = false
  279. uni.showToast({
  280. mask: true,
  281. title: '年消费更新中…',
  282. success() {
  283. _this.btn = true
  284. }
  285. })
  286. return
  287. res = await _this.$myRequest({
  288. host: _this.ceshi,
  289. url: '/HotWaters/buildgetMonthBill.action',
  290. method: 'POST',
  291. header: {
  292. 'content-type': 'application/x-www-form-urlencoded'
  293. },
  294. data: {
  295. 'roomSelect': _this.roomSelect
  296. }
  297. })
  298. // console.log(res);
  299. if (res.data.mess == '未查询到数据') {
  300. return
  301. }
  302. let chrt_data = {
  303. categories: [],
  304. series: [{
  305. data: [],
  306. }],
  307. }
  308. let elc_max = 0.0
  309. for (var i = 0; i < res.data.date_time.length; i++) {
  310. chrt_data.categories.push(res.data.date_time[i])
  311. chrt_data.series[0].data.push(res.data.use_elc[i])
  312. if (parseFloat(res.data.use_elc[i]) > parseFloat(elc_max)) {
  313. elc_max = res.data.use_elc[i]
  314. }
  315. }
  316. let m = parseFloat(Math.abs(elc_max))
  317. // console.log(chrt_data);
  318. setTimeout(() => {
  319. _this.chartOpts.yAxis.data[0].max = parseInt(m + (m / 4.0))
  320. _this.chartData = chrt_data;
  321. }, 1000);
  322. }
  323. } else {
  324. uni.showToast({
  325. title: '宿舍号为空',
  326. icon: 'success'
  327. });
  328. }
  329. }
  330. }
  331. }
  332. </script>
  333. <style>
  334. @import url("show.css");
  335. </style>