dfxq.vue 9.0 KB

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