Home.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template id="Home">
  2. <div>
  3. <van-nav-bar title="电量查询">
  4. </van-nav-bar>
  5. <div class="fyycontent">
  6. <van-cell-group>
  7. <van-cell>
  8. <span class="iconfont color-red fyy-icon">&#xe63f;</span>
  9. 请选择园区
  10. </van-cell>
  11. <van-dropdown-menu>
  12. <van-dropdown-item v-model="selectedAreaId" :options="areaList" @change="areaChange"/>
  13. </van-dropdown-menu>
  14. </van-cell-group>
  15. <van-cell-group>
  16. <van-cell>
  17. <span class="iconfont color-red fyy-icon">&#xe642;</span>
  18. 请选择楼栋号
  19. </van-cell>
  20. <van-dropdown-menu>
  21. <van-dropdown-item v-model="selectedBuildingId" :options="buildingList" @change="buildingChange"/>
  22. </van-dropdown-menu>
  23. </van-cell-group>
  24. <van-cell-group>
  25. <van-cell>
  26. <span class="iconfont color-red fyy-icon">&#xe643;</span>
  27. 请选择房间号
  28. </van-cell>
  29. <van-dropdown-menu>
  30. <van-dropdown-item v-model="selectedRoomId" :options="roomList" @change="roomChange"/>
  31. </van-dropdown-menu>
  32. </van-cell-group>
  33. <div class="fyy-button">
  34. <van-button type="primary" @click="queryPower(selectedRoomId)">查询</van-button>
  35. <p>
  36. 剩余电量:<span v-html="remainingPower" class="power"></span>
  37. <span v-if="remainingPower!=null">度</span>
  38. &nbsp;
  39. 当前状态:<span v-html="stateText"></span>
  40. </p>
  41. </div>
  42. </div>
  43. <div class="fyyfooter">
  44. <van-button type="bigred" @click="recharge()">充值</van-button>
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. import remoteApi from '@/api/remoteApi'
  50. import Cookies from 'js-cookie'
  51. import { Dialog } from 'vant'
  52. export default {
  53. data() {
  54. return {
  55. remainingPower: null,
  56. state:null,
  57. selectedAreaId: null,
  58. selectedBuildingId: null,
  59. selectedRoomId: null,
  60. areaList: [],
  61. buildingList: [],
  62. roomList: []
  63. };
  64. },
  65. computed: {
  66. stateText (){
  67. if(this.state==null){
  68. return "未知";
  69. }
  70. else if(this.state==1){
  71. return "断电";
  72. }
  73. else if(this.state==0){
  74. return "通电";
  75. }
  76. }
  77. },
  78. mounted (){
  79. var self = this
  80. remoteApi.queryRoomList(1,null).then((resp)=>{
  81. console.log(resp);
  82. if(resp.result){
  83. self.areaList = resp.data.map((e)=>{
  84. return {
  85. value : e.id,
  86. text : e.name
  87. }
  88. });
  89. self.selectedAreaId = Cookies.get("selectedAreaId");
  90. return self.areaChange(self.selectedAreaId);
  91. }
  92. }).then((resp)=>{
  93. self.selectedBuildingId = Cookies.get("selectedBuildingId");
  94. return self.buildingChange(self.selectedBuildingId);
  95. }).then((resp)=>{
  96. self.selectedRoomId = Cookies.get("selectedRoomId");
  97. });
  98. },
  99. methods: {
  100. areaChange (value) {
  101. var self = this
  102. return remoteApi.queryRoomList(2,value).then((resp)=>{
  103. console.log(resp);
  104. if(resp.result){
  105. self.buildingList = resp.data.map((e)=>{
  106. return {
  107. value : e.id,
  108. text : e.name
  109. }
  110. });
  111. }
  112. });
  113. },
  114. queryPower (roomId) {
  115. var self = this
  116. self.$toast.loading({
  117. message: '加载中...',
  118. forbidClick: true,
  119. loadingType: 'spinner',
  120. duration: 10000
  121. });
  122. Cookies.set("selectedAreaId",self.selectedAreaId,{ expires: 7 })
  123. Cookies.set("selectedBuildingId",self.selectedBuildingId,{ expires: 7 })
  124. Cookies.set("selectedRoomId",self.selectedRoomId,{ expires: 7 })
  125. remoteApi.queryPower(roomId).then((resp)=>{
  126. console.log(resp);
  127. self.$toast.clear();
  128. if(resp.result){
  129. self.$toast.success('查询成功!')
  130. self.remainingPower = resp.data.remain
  131. self.state = resp.data.state
  132. }
  133. else {
  134. self.$toast.fail(resp.message)
  135. }
  136. });
  137. },
  138. buildingChange (value) {
  139. var self = this
  140. return remoteApi.queryRoomList(3,value).then((resp)=>{
  141. console.log(resp);
  142. if(resp.result){
  143. self.roomList = resp.data.map((e)=>{
  144. return {
  145. value : e.id,
  146. text : e.name
  147. }
  148. });
  149. }
  150. });
  151. },
  152. roomChange (roomId) {
  153. this.queryPower(roomId);
  154. },
  155. recharge (){
  156. if(this.selectedRoomId == null) {
  157. this.$toast.fail("请先选择房间!");
  158. }
  159. else{
  160. this.$router.push({
  161. path : '/Pay',
  162. query: {
  163. roomId : this.selectedRoomId
  164. }
  165. });
  166. }
  167. }
  168. }
  169. };
  170. </script>
  171. <style scoped>
  172. .power{
  173. font-size:150%;
  174. }
  175. </style>