sfxq.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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.totalPower}}</view>
  20. <view class="description">用量(吨)</view>
  21. </view>
  22. <view class="item">
  23. <view class="num">{{sameMonthData.totalMoney}}</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. totalMoney: 0.00.toFixed(2),
  66. totalPower: 0.00.toFixed(2),
  67. zongStart: 0.00.toFixed(2)
  68. },
  69. moneyPer: 2.1.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.roomSelect == 'undefined') {
  88. // 获取学号
  89. this.stu_number = this.$store.state.userInfo.card_number
  90. this.roomSelect = this.$store.state.building.roomSelect
  91. if (this.stu_number == '' || this.roomSelect == '' || typeof this.stu_number == 'undefined' || typeof this.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);
  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. return false
  147. }
  148. },
  149. /**
  150. * 当月详情
  151. */
  152. async get_sameMonthDetails() {
  153. let res = await this.$myRequest({
  154. host: this.ceshi,
  155. url: '/HotWaters/cwaterqueryNow.action',
  156. method: 'POST',
  157. header: {
  158. 'content-type': 'application/x-www-form-urlencoded'
  159. },
  160. data: {
  161. 'roomSelect': this.roomSelect
  162. }
  163. })
  164. // console.log(res.data)
  165. if (res.data.mess === '返回成功') {
  166. if (res.data.data.length == 0) {
  167. return
  168. }
  169. let zongEnd = res.data.data[0].zongEnd
  170. let totalMoney = res.data.data[0].totalMoney
  171. let totalPower = res.data.data[0].totalPower
  172. let zongStart = res.data.data[0].zongStart
  173. let dataTime = res.data.data[0].dataTime
  174. let dt = dataTime.split('-')
  175. this.sameMonthData.dataTime = dt[0] + '年' + parseInt(dt[1]) + '月'
  176. this.sameMonthData.zongEnd = zongEnd.toFixed(2)
  177. this.sameMonthData.totalMoney = totalMoney.toFixed(2)
  178. this.sameMonthData.totalPower = totalPower.toFixed(2)
  179. this.sameMonthData.zongStart = zongStart.toFixed(2)
  180. } else {
  181. uni.showToast({
  182. title: '月详情加载异常',
  183. duration: 1500
  184. })
  185. return
  186. }
  187. },
  188. /**
  189. * 每月账单
  190. */
  191. async get_history() {
  192. var reg = /[\u4e00-\u9fa5]/g;
  193. var str = this.roomSelect;
  194. this.dom = str.replace(reg, "");
  195. let res = await this.$myRequest({
  196. host: this.ceshi,
  197. url: '/HotWaters/cwaterMonthlist.action',
  198. method: 'POST',
  199. header: {
  200. 'content-type': 'application/x-www-form-urlencoded'
  201. },
  202. data: {
  203. 'dom': this.dom,
  204. 'page': 1,
  205. 'rows': 12
  206. }
  207. })
  208. // console.log(res.data)
  209. if (res.data.rows.length == 0) {
  210. return
  211. }
  212. if (typeof res.data.rows === 'undefined') {
  213. uni.showToast({
  214. title: '月账单加载异常',
  215. duration: 1500
  216. });
  217. return;
  218. } else {
  219. var tableData = []
  220. for (let i = 0; i < res.data.rows.length; i++) {
  221. let dataTime = res.data.rows[i].dataTime;
  222. let zongStart = res.data.rows[i].zongStart;
  223. let zongEnd = res.data.rows[i].zongEnd;
  224. let totalPower = res.data.rows[i].totalPower;
  225. let totalMoney = res.data.rows[i].totalMoney;
  226. zongStart = zongStart.toFixed(2);
  227. zongEnd = zongEnd.toFixed(2);
  228. totalPower = totalPower.toFixed(2);
  229. totalMoney = totalMoney.toFixed(2);
  230. if (this.moneyPer <= 0.00) {
  231. if (totalPower > 0.00 && totalMoney > 0.00) {
  232. let moneyPer = totalMoney / totalPower;
  233. this.moneyPer = moneyPer.toFixed(2);
  234. if (this.moneyPer <= 0.00) {
  235. this.moneyPer = 0.61;
  236. }
  237. }
  238. }
  239. totalMoney = '¥' + totalMoney;
  240. tableData.push({
  241. dataTime,
  242. zongStart,
  243. zongEnd,
  244. totalPower,
  245. totalMoney
  246. });
  247. }
  248. // 过滤掉重复数据
  249. this.tableData = tableData.filter(function(item, index, self) {
  250. return index === self.findIndex(function(t) {
  251. return t.dataTime === item.dataTime && t.totalPower === item.totalPower && t.totalMoney === item.totalMoney;
  252. });
  253. });
  254. }
  255. }
  256. }
  257. }
  258. </script>
  259. <style scoped lang="scss">
  260. .container {
  261. display: flex;
  262. flex-direction: column;
  263. font-size: 29upx;
  264. font-family: "Microsoft YaHei";
  265. .line {
  266. height: 10rpx;
  267. background-color: #f5f5f5;
  268. }
  269. .same-month {
  270. display: flex;
  271. flex-direction: column;
  272. padding: 20rpx 30rpx;
  273. .title {
  274. display: flex;
  275. align-items: center;
  276. margin-bottom: 30rpx;
  277. .vertical-line {
  278. display: inline-block;
  279. margin-right: 20rpx;
  280. width: 10rpx;
  281. height: 45rpx;
  282. background-color: #0282F8;
  283. }
  284. .title-txt {
  285. display: flex;
  286. flex-direction: row;
  287. align-items: flex-end;
  288. color: #C1C1C1;
  289. .caption {
  290. color: #2b2b2b;
  291. font-size: 40upx;
  292. }
  293. .hah {
  294. display: flex;
  295. margin: 0 10rpx;
  296. }
  297. }
  298. }
  299. .content-details {
  300. display: flex;
  301. justify-content: space-around;
  302. .item {
  303. display: flex;
  304. flex-direction: column;
  305. align-items: center;
  306. .num {
  307. font-size: 40upx;
  308. }
  309. .description {
  310. color: #9a9a9a;
  311. }
  312. }
  313. /deep/ .uni-table {
  314. .uni-table-th {
  315. padding: 6px 8px;
  316. font-size: 26upx;
  317. white-space: nowrap;
  318. text-align: center;
  319. background-color: #E5F2FE;
  320. color: #39393A;
  321. }
  322. .uni-table-td {
  323. padding: 3px 5px;
  324. font-size: 26upx;
  325. white-space: nowrap;
  326. text-align: center;
  327. }
  328. }
  329. }
  330. .txt-color {
  331. margin: 20rpx 0;
  332. color: #C1C1C1;
  333. }
  334. }
  335. }
  336. </style>