sfxq.vue 8.9 KB

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