dfxq.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="container">
  3. <view class="line"></view>
  4. <view class="same-month">
  5. <view class="title">
  6. <view class="vertical-line"></view>
  7. <view class="title-txt"><text class="caption">当月详情</text><text class="hah">/</text>时间更新到{{sameMonthData.dataTime}}</view>
  8. </view>
  9. <view class="content-details">
  10. <view class="item">
  11. <view class="num">{{sameMonthData.zongStart}}</view>
  12. <view class="description">起码(度)</view>
  13. </view>
  14. <view class="item">
  15. <view class="num">{{sameMonthData.zongEnd}}</view>
  16. <view class="description">止码(度)</view>
  17. </view>
  18. <view class="item">
  19. <view class="num">{{sameMonthData.zongPower}}</view>
  20. <view class="description">用量(度)</view>
  21. </view>
  22. <view class="item">
  23. <view class="num">{{sameMonthData.zongMoney}}</view>
  24. <view class="description">消费(元)</view>
  25. </view>
  26. </view>
  27. <view class="txt-color">(注:电费标准:{{moneyPer}}元/度)</view>
  28. </view>
  29. <view class="line"></view>
  30. <view class="same-month">
  31. <view class="title">
  32. <view class="vertical-line"></view>
  33. <view class="title-txt"><text class="caption">每月账单</text></view>
  34. </view>
  35. <view class="content-details">
  36. <uni-table :border="true" :stripe="true" emptyText="暂无更多数据">
  37. <!-- 表头行 -->
  38. <uni-tr>
  39. <uni-th width="66" align="center">时间</uni-th>
  40. <uni-th width="64" align="center">起码(度)</uni-th>
  41. <uni-th width="64" align="center">止码(度)</uni-th>
  42. <uni-th width="64" align="center">用量(度)</uni-th>
  43. <uni-th width="64" align="center">消费</uni-th>
  44. </uni-tr>
  45. <!-- 表格数据行 -->
  46. <uni-tr v-for="(item, index) in tableData" :key="index">
  47. <uni-td align="center">{{item.dataTime}}</uni-td>
  48. <uni-td align="center">{{item.zongStart}}</uni-td>
  49. <uni-td align="center">{{item.zongEnd}}</uni-td>
  50. <uni-td align="center">{{item.totalPower}}</uni-td>
  51. <uni-td align="center">{{item.totalMoney}}</uni-td>
  52. </uni-tr>
  53. </uni-table>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. sameMonthData: {
  63. dataTime: '',
  64. zongEnd: 0.00.toFixed(2),
  65. zongMoney: 0.00.toFixed(2),
  66. zongPower: 0.00.toFixed(2),
  67. zongStart: 0.00.toFixed(2)
  68. },
  69. moneyPer: 0.62.toFixed(2),
  70. tableData: [],
  71. ceshi: 'code',
  72. stu_number: '', // 学号
  73. roomSelect: '', // 选择的宿舍号
  74. dom: ''
  75. }
  76. },
  77. onLoad(options) {
  78. try {
  79. this.stu_number = uni.getStorageSync('stu_number');
  80. this.roomSelect = uni.getStorageSync('roomSelect');
  81. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(this
  82. .roomSelect) == 'undefined') {
  83. // console.log(options);
  84. this.stu_number = options.card_number;
  85. this.roomSelect = options.roomSelect;
  86. }
  87. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(this
  88. .roomSelect) == 'undefined') {
  89. // 获取学号
  90. this.stu_number = this.$store.state.userInfo.card_number
  91. this.roomSelect = this.$store.state.building.roomSelect
  92. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(
  93. 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: '../../pages/index/index'
  102. })
  103. uni.showToast({
  104. icon: 'none',
  105. title: '学号或宿舍号为空,请授权',
  106. duration: 1500
  107. })
  108. return
  109. }
  110. }
  111. }
  112. // console.log(this.stu_number);
  113. // console.log(this.roomSelect);
  114. // 判断是否选择了宿舍号
  115. if (this.haveSelectRoom()) {
  116. uni.showToast({
  117. title: '宿舍号为空',
  118. icon: 'success'
  119. });
  120. }
  121. } catch (e) {
  122. console.log(e.message);
  123. }
  124. },
  125. methods: {
  126. /**
  127. * 判断是否选择了宿舍号
  128. */
  129. haveSelectRoom() {
  130. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  131. return true
  132. } else {
  133. // 当月详情
  134. try {
  135. this.get_sameMonthDetails()
  136. } catch (e) {
  137. uni.showToast({
  138. title: '当月详情'
  139. })
  140. }
  141. // 每月账单
  142. try {
  143. this.get_history()
  144. } catch (e) {
  145. uni.showToast({
  146. title: '每月账单异常'
  147. })
  148. }
  149. }
  150. },
  151. /**
  152. * 当月详情
  153. */
  154. async get_sameMonthDetails() {
  155. let res = await this.$myRequest({
  156. host: this.ceshi,
  157. url: '/HotWaters/elnowElc.action',
  158. method: 'POST',
  159. header: {
  160. 'content-type': 'application/x-www-form-urlencoded'
  161. },
  162. data: {
  163. 'roomSelect': this.roomSelect
  164. }
  165. })
  166. // console.log(res.data)
  167. if (res.data.mess === '返回成功') {
  168. if (res.data.data.length == 0) {
  169. return
  170. }
  171. let zongEnd = res.data.data[0].zongEnd
  172. let zongMoney = res.data.data[0].zongMoney
  173. let zongPower = res.data.data[0].zongPower
  174. let zongStart = res.data.data[0].zongStart
  175. let dataTime = res.data.data[0].dataTime
  176. let dt = dataTime.split('-')
  177. this.sameMonthData.dataTime = dt[0] + '年' + parseInt(dt[1]) + '月'
  178. this.sameMonthData.zongEnd = zongEnd.toFixed(2)
  179. this.sameMonthData.zongMoney = zongMoney.toFixed(2)
  180. this.sameMonthData.zongPower = zongPower.toFixed(2)
  181. this.sameMonthData.zongStart = zongStart.toFixed(2)
  182. } else {
  183. uni.showToast({
  184. title: '加载数据异常',
  185. duration: 1500
  186. })
  187. return
  188. }
  189. },
  190. /**
  191. * 每月账单
  192. */
  193. async get_history() {
  194. var reg = /[\u4e00-\u9fa5]/g;
  195. var str = this.roomSelect;
  196. this.dom = str.replace(reg, "");
  197. let res = await this.$myRequest({
  198. host: this.ceshi,
  199. url: '/HotWaters/elMonthlist.action',
  200. method: 'POST',
  201. header: {
  202. 'content-type': 'application/x-www-form-urlencoded'
  203. },
  204. data: {
  205. 'dom': this.dom,
  206. 'page': 1,
  207. 'rows': 12
  208. }
  209. })
  210. // console.log(res.data)
  211. if (res.data.rows.length == 0) {
  212. return;
  213. }
  214. if (typeof res.data.rows === 'undefined') {
  215. uni.showToast({
  216. title: '加载数据异常',
  217. duration: 1500
  218. });
  219. return;
  220. } else {
  221. var tableData = []
  222. for (let i = 0; i < res.data.rows.length; i++) {
  223. let dataTime = res.data.rows[i].dataTime;
  224. let zongStart = res.data.rows[i].zongStart;
  225. let zongEnd = res.data.rows[i].zongEnd;
  226. let totalPower = res.data.rows[i].totalPower;
  227. let totalMoney = res.data.rows[i].totalMoney;
  228. zongStart = zongStart.toFixed(2);
  229. zongEnd = zongEnd.toFixed(2);
  230. totalPower = totalPower.toFixed(2);
  231. totalMoney = totalMoney.toFixed(2);
  232. if (this.moneyPer <= 0.00) {
  233. if (totalPower > 0.00 && totalMoney > 0.00) {
  234. let moneyPer = totalMoney / totalPower;
  235. this.moneyPer = moneyPer.toFixed(2);
  236. if (this.moneyPer <= 0.00) {
  237. this.moneyPer = 0.61;
  238. }
  239. }
  240. }
  241. totalMoney = '¥' + totalMoney;
  242. tableData.push({
  243. dataTime,
  244. zongStart,
  245. zongEnd,
  246. totalPower,
  247. totalMoney
  248. });
  249. }
  250. // 过滤掉重复数据
  251. this.tableData = tableData.filter(function(item, index, self) {
  252. return index === self.findIndex(function(t) {
  253. return t.dataTime === item.dataTime && t.totalPower === item.totalPower && t.totalMoney === item.totalMoney;
  254. });
  255. });
  256. }
  257. }
  258. }
  259. }
  260. </script>
  261. <style scoped lang="scss">
  262. .container {
  263. display: flex;
  264. flex-direction: column;
  265. font-size: 29upx;
  266. font-family: "Microsoft YaHei";
  267. .line {
  268. height: 10rpx;
  269. background-color: #f5f5f5;
  270. }
  271. .same-month {
  272. display: flex;
  273. flex-direction: column;
  274. padding: 20rpx 30rpx;
  275. .title {
  276. display: flex;
  277. align-items: center;
  278. margin-bottom: 30rpx;
  279. .vertical-line {
  280. display: inline-block;
  281. margin-right: 20rpx;
  282. width: 10rpx;
  283. height: 45rpx;
  284. background-color: #0282F8;
  285. }
  286. .title-txt {
  287. display: flex;
  288. flex-direction: row;
  289. align-items: flex-end;
  290. color: #C1C1C1;
  291. .caption {
  292. color: #2b2b2b;
  293. font-size: 40upx;
  294. }
  295. .hah {
  296. display: flex;
  297. margin: 0 10rpx;
  298. }
  299. }
  300. }
  301. .content-details {
  302. display: flex;
  303. justify-content: space-around;
  304. .item {
  305. display: flex;
  306. flex-direction: column;
  307. align-items: center;
  308. .num {
  309. font-size: 40upx;
  310. }
  311. .description {
  312. color: #9a9a9a;
  313. }
  314. }
  315. /deep/ .uni-table {
  316. .uni-table-th {
  317. padding: 6px 8px;
  318. font-size: 26upx;
  319. white-space: nowrap;
  320. text-align: center;
  321. background-color: #E5F2FE;
  322. color: #5b5b5d;
  323. }
  324. .uni-table-td {
  325. padding: 3px 5px;
  326. font-size: 26upx;
  327. white-space: nowrap;
  328. text-align: center;
  329. color: #000000;
  330. }
  331. }
  332. }
  333. .txt-color {
  334. margin: 20rpx 0;
  335. color: #C1C1C1;
  336. }
  337. }
  338. }
  339. </style>