BatteryCharger.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view>
  3. <view class="communication">
  4. <view class="battery_title">
  5. <view class="first">
  6. <image class="img" src="../../../static/equipment/cangwei.png" />
  7. </image><text class="p"> {{chargerCode}}号充电机</text>
  8. <view :class="[buttonState[0],buttonState === 1?'is-disabled':'']" @click.stop="sendCharger">
  9. {{buttonState === 1 ?'不可操作':buttonState[1]}}
  10. </view>
  11. </view>
  12. </view>
  13. <view :class="statustext[1]">{{statustext[0]}}</view>
  14. </view>
  15. <!-- 顶部公共提示信息 -->
  16. <uni-popup ref="Exchangepopup" type="message">
  17. <uni-popup-message :type="popupType" :message="popupMessage" :duration="2000"></uni-popup-message>
  18. </uni-popup>
  19. <!-- 顶部提示信息结束-->
  20. </view>
  21. </template>
  22. <script>
  23. // import {
  24. // startCharge,
  25. // stopCharge
  26. // } from '@/common/http.js'
  27. export default {
  28. name: "BatteryCharger",
  29. props: ['chargerCode', 'comState', 'chgState', "sn", "storeState"],
  30. data() {
  31. return {
  32. loading: false,
  33. popupType:'',
  34. popupMessage:''
  35. }
  36. },
  37. computed: {
  38. statustext() {
  39. if (this.comState === 1) {
  40. return ['通讯正常', 'success']
  41. } else {
  42. return ['通讯异常', 'warning']
  43. }
  44. },
  45. buttonState() {
  46. if ((this.chgState === 0 || this.chgState === 3)&& this.storeState === 1) {
  47. return ['btnState', '充电']
  48. } else if (this.chgState === 2&& this.storeState === 1) {
  49. return ['purple', '断电']
  50. } else {
  51. return 1
  52. }
  53. }
  54. },
  55. methods: {
  56. //顶部公共消息提示
  57. ExchangeMessage(type, message) {
  58. this.popupType = type
  59. this.popupMessage = message?message:'后端接口404错误!'
  60. this.$refs.Exchangepopup.open()
  61. },
  62. //充电、断电操作
  63. sendCharger() {
  64. console.log(this.chargerId)
  65. if (this.buttonState == 1) {
  66. return
  67. }
  68. let params = {}
  69. if (this.chgState === 0 || this.chgState === 3) {
  70. params = {
  71. chargerId: this.chargerCode * 1,
  72. sn: this.sn
  73. }
  74. } else if (this.chgState === 2) {
  75. params = {
  76. chargerId: this.chargerCode * 1
  77. }
  78. }
  79. this.loading = true
  80. let that = this
  81. uni.showModal({
  82. title: `确认发起${this.buttonState[1]}`,
  83. content: '',
  84. success: function(res) {
  85. if (res.confirm) { //点击确定
  86. //充电操作
  87. if (that.chgState === 0 || that.chgState === 3) {
  88. that.ExchangeMessage('success','充电指令已下发')
  89. that.$http.startCharge(params)
  90. .then(res => {
  91. that.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0?'充电成功':'充电失败')
  92. }).catch(err => {
  93. console.error(err)
  94. })
  95. }
  96. //断电操作
  97. else if (that.chgState === 2) {
  98. that.ExchangeMessage('success','断电指令已下发')
  99. that.$http.stopCharge(params)
  100. .then(res => {
  101. that.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0?'断电成功':'断电失败')
  102. }).catch(err => {
  103. console.error(err)
  104. })
  105. }
  106. } else if (res.cancel) {
  107. return false
  108. //用户点击取消按钮触发
  109. }
  110. that.loading = false
  111. }
  112. })
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. .communication {
  119. display: flex;
  120. margin-bottom: 10px;
  121. view {
  122. line-height: 32px;
  123. font-size: 14px;
  124. font-weight: 600;
  125. height: 32px;
  126. width: 200px;
  127. text-align: center;
  128. }
  129. .battery_title {
  130. background-color: #1b263a;
  131. border: #25334d solid 1px;
  132. color: white;
  133. line-height: 32px;
  134. display: flex;
  135. justify-content: space-between;
  136. padding: 0 5px;
  137. .is-disabled {
  138. width: 75px;
  139. height: 24px;
  140. line-height: 24px;
  141. padding: 0 0 0 15px;
  142. border-radius: 15px;
  143. margin-top: 4px;
  144. color: #5f6571;
  145. border-color: #353c4c;
  146. background: url('@/static/equipment/d3.png') #353c4c no-repeat 6px center;
  147. position: absolute;
  148. right: 0px;
  149. }
  150. .first {
  151. display: flex;
  152. position: relative;
  153. .p {
  154. margin: 0;
  155. padding: 0;
  156. }
  157. .img {
  158. width: 22px;
  159. height: 22px;
  160. vertical-align: middle;
  161. margin-top: 6px;
  162. margin-right: 5px;
  163. }
  164. }
  165. .btnState {
  166. width: 45px;
  167. height: 24px;
  168. padding: 0 0 0 15px;
  169. font-size: 14px;
  170. color: #fff;
  171. border-radius: 15px;
  172. margin-top: 4px;
  173. line-height: 24px;
  174. cursor: pointer;
  175. border: none;
  176. letter-spacing: 1px;
  177. background: url('@/static/equipment/d1.png') rgb(105, 184, 137) no-repeat 6px center;
  178. background-position-x: 5px;
  179. position: absolute;
  180. right: 0px;
  181. }
  182. .purple {
  183. width: 45px;
  184. height: 24px;
  185. padding: 0 0 0 15px;
  186. font-size: 14px;
  187. color: #fff;
  188. line-height: 24px;
  189. border-radius: 15px;
  190. margin-top: 4px;
  191. cursor: pointer;
  192. border: none;
  193. letter-spacing: 1px;
  194. background: url('@/static/equipment/d2.png') rgb(224, 125, 68) no-repeat 6px center;
  195. background-position-x: 5px;
  196. position: absolute;
  197. right: 0px;
  198. }
  199. }
  200. .success {
  201. color: #92fdb9;
  202. text-align: right;
  203. }
  204. .warning {
  205. color: #c85e60;
  206. text-align: right;
  207. }
  208. }
  209. </style>