dfxq.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. // console.log(options);
  80. this.stu_number = options.card_number;
  81. this.roomSelect = options.roomSelect;
  82. // this.stu_number = this.$store.state.userInfo.card_number
  83. // this.roomSelect = this.$store.state.building.roomSelect
  84. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(this
  85. .roomSelect) == 'undefined') {
  86. // 获取学号
  87. this.stu_number = this.$store.state.userInfo.card_number
  88. this.roomSelect = this.$store.state.building.roomSelect
  89. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(
  90. this
  91. .roomSelect) == 'undefined') {
  92. const userinfo = uni.getStorageSync('userinfo_storage_key')
  93. if (userinfo) {
  94. this.stu_number = userinfo.card_number
  95. this.roomSelect = userinfo.campus + userinfo.dorm_number
  96. } else {
  97. uni.redirectTo({
  98. url: '/pages/index/index'
  99. })
  100. uni.showToast({
  101. icon: 'none',
  102. title: '学号或宿舍号为空,请授权',
  103. duration: 1500
  104. })
  105. return
  106. }
  107. }
  108. }
  109. // console.log(this.stu_number);
  110. // console.log(this.roomSelect);
  111. // 判断是否选择了宿舍号
  112. if (this.haveSelectRoom()) {
  113. uni.showToast({
  114. title: '宿舍号为空',
  115. icon: 'success'
  116. });
  117. }
  118. } catch (e) {
  119. console.log(e.message);
  120. }
  121. },
  122. methods: {
  123. /**
  124. * 判断是否选择了宿舍号
  125. */
  126. haveSelectRoom() {
  127. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  128. return true
  129. } else {
  130. // 当月详情
  131. try {
  132. this.get_sameMonthDetails()
  133. } catch (e) {
  134. uni.showToast({
  135. title: '当月详情'
  136. })
  137. }
  138. // 每月账单
  139. try {
  140. this.get_history()
  141. } catch (e) {
  142. uni.showToast({
  143. title: '每月账单异常'
  144. })
  145. }
  146. }
  147. },
  148. /**
  149. * 当月详情
  150. */
  151. async get_sameMonthDetails() {
  152. let res = await this.$myRequest({
  153. host: this.ceshi,
  154. url: '/HotWaters/elnowElc.action',
  155. method: 'POST',
  156. header: {
  157. 'content-type': 'application/x-www-form-urlencoded'
  158. },
  159. data: {
  160. 'roomSelect': this.roomSelect
  161. }
  162. })
  163. // console.log(res.data)
  164. if (res.data.mess === '返回成功') {
  165. if (res.data.data.length == 0) {
  166. return
  167. }
  168. let zongEnd = res.data.data[0].zongEnd
  169. let zongMoney = res.data.data[0].zongMoney
  170. let zongPower = res.data.data[0].zongPower
  171. let zongStart = res.data.data[0].zongStart
  172. let dataTime = res.data.data[0].dataTime
  173. let dt = dataTime.split('-')
  174. this.sameMonthData.dataTime = dt[0] + '年' + parseInt(dt[1]) + '月'
  175. this.sameMonthData.zongEnd = zongEnd.toFixed(2)
  176. this.sameMonthData.zongMoney = zongMoney.toFixed(2)
  177. this.sameMonthData.zongPower = zongPower.toFixed(2)
  178. this.sameMonthData.zongStart = zongStart.toFixed(2)
  179. } else {
  180. uni.showToast({
  181. title: '加载数据异常',
  182. duration: 1500
  183. })
  184. return
  185. }
  186. },
  187. /**
  188. * 每月账单
  189. */
  190. async get_history() {
  191. var reg = /[\u4e00-\u9fa5]/g;
  192. var str = this.roomSelect;
  193. this.dom = str.replace(reg, "");
  194. let res = await this.$myRequest({
  195. host: this.ceshi,
  196. url: '/HotWaters/elMonthlist.action',
  197. method: 'POST',
  198. header: {
  199. 'content-type': 'application/x-www-form-urlencoded'
  200. },
  201. data: {
  202. 'dom': this.dom,
  203. 'page': 1,
  204. 'rows': 12
  205. }
  206. })
  207. // console.log(res.data)
  208. if (res.data.rows.length == 0) {
  209. return;
  210. }
  211. if (typeof res.data.rows === 'undefined') {
  212. uni.showToast({
  213. title: '加载数据异常',
  214. duration: 1500
  215. });
  216. return;
  217. } else {
  218. var tableData = []
  219. for (let i = 0; i < res.data.rows.length; i++) {
  220. let dataTime = res.data.rows[i].dataTime;
  221. let zongStart = res.data.rows[i].zongStart;
  222. let zongEnd = res.data.rows[i].zongEnd;
  223. let totalPower = res.data.rows[i].totalPower;
  224. let totalMoney = res.data.rows[i].totalMoney;
  225. zongStart = zongStart.toFixed(2);
  226. zongEnd = zongEnd.toFixed(2);
  227. totalPower = totalPower.toFixed(2);
  228. totalMoney = totalMoney.toFixed(2);
  229. if (this.moneyPer <= 0.00) {
  230. if (totalPower > 0.00 && totalMoney > 0.00) {
  231. let moneyPer = totalMoney / totalPower;
  232. this.moneyPer = moneyPer.toFixed(2);
  233. if (this.moneyPer <= 0.00) {
  234. this.moneyPer = 0.61;
  235. }
  236. }
  237. }
  238. totalMoney = '¥' + totalMoney;
  239. tableData.push({
  240. dataTime,
  241. zongStart,
  242. zongEnd,
  243. totalPower,
  244. totalMoney
  245. });
  246. }
  247. this.tableData = tableData.filter(function(item, index, self) {
  248. return index === self.findIndex(function(t) {
  249. return t.dataTime === item.dataTime && t.totalPower === item.totalPower && t.totalMoney === item.totalMoney;
  250. });
  251. });
  252. }
  253. }
  254. }
  255. }
  256. </script>
  257. <style scoped lang="scss">
  258. .container {
  259. display: flex;
  260. flex-direction: column;
  261. font-size: 29upx;
  262. font-family: "Microsoft YaHei";
  263. .line {
  264. height: 10rpx;
  265. background-color: #f5f5f5;
  266. }
  267. .same-month {
  268. display: flex;
  269. flex-direction: column;
  270. padding: 20rpx 30rpx;
  271. .title {
  272. display: flex;
  273. align-items: center;
  274. margin-bottom: 30rpx;
  275. .vertical-line {
  276. display: inline-block;
  277. margin-right: 20rpx;
  278. width: 10rpx;
  279. height: 45rpx;
  280. background-color: #0282F8;
  281. }
  282. .title-txt {
  283. display: flex;
  284. flex-direction: row;
  285. align-items: flex-end;
  286. color: #C1C1C1;
  287. .caption {
  288. color: #2b2b2b;
  289. font-size: 40upx;
  290. }
  291. .hah {
  292. display: flex;
  293. margin: 0 10rpx;
  294. }
  295. }
  296. }
  297. .content-details {
  298. display: flex;
  299. justify-content: space-around;
  300. .item {
  301. display: flex;
  302. flex-direction: column;
  303. align-items: center;
  304. .num {
  305. font-size: 40upx;
  306. }
  307. .description {
  308. color: #9a9a9a;
  309. }
  310. }
  311. /deep/ .uni-table {
  312. .uni-table-th {
  313. padding: 6px 8px;
  314. font-size: 26upx;
  315. white-space: nowrap;
  316. text-align: center;
  317. background-color: #E5F2FE;
  318. color: #5b5b5d;
  319. }
  320. .uni-table-td {
  321. padding: 3px 5px;
  322. font-size: 26upx;
  323. white-space: nowrap;
  324. text-align: center;
  325. color: #000000;
  326. }
  327. }
  328. }
  329. .txt-color {
  330. margin: 20rpx 0;
  331. color: #C1C1C1;
  332. }
  333. }
  334. }
  335. </style>