charge.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view>
  3. <u-navbar title="充电"></u-navbar>
  4. <view class="recharge">
  5. <view class="title">请选择充电金额</view>
  6. <p>当前余额¥{{user.balance}}</p>
  7. <view class="rechargeMain">
  8. <view class="recharge-item"
  9. @click="moneyClick(item.id)"
  10. :class="!otherNum&&moneyActiveClass == item.id ? 'active' : ''"
  11. v-for="(item,index) in moneyList" :key="item.id">
  12. {{item.name}}元
  13. </view>
  14. <view class="recharge-item"
  15. :class="otherNum ? 'active' : ''"
  16. style="
  17. padding: 8px 0px;">
  18. <u-input v-model="otherNum" @input="ckInput" type="digit" placeholder="其他充值金额" />
  19. </view>
  20. <view style="color: rgba(153, 153, 153, 100);
  21. font-size: 12px;
  22. text-align: left;
  23. font-family: AlibabaPuHui-regular;">*金额范围为1元-500元</view>
  24. </view>
  25. <p>其他充电模式</p>
  26. <view
  27. @click="moneyClick(-1)"
  28. :class="!otherNum&&moneyActiveClass == -1? 'active' : ''"
  29. class="self-stop ">
  30. 充满自停
  31. </view>
  32. </view>
  33. <view class="but-box">
  34. <u-button @click="submit" shape="circle">开始充电</u-button>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import * as API from '@/apis/chargeProcess.js'
  40. export default {
  41. data() {
  42. return {
  43. moneyActiveClass:"5",
  44. detail: {},
  45. //提交信息
  46. submitForm: {
  47. deviceNo: '',
  48. channelNo: '',
  49. carNumber: '',
  50. chargeStrategy: 2,
  51. amount:0
  52. //paytype:'YE',
  53. },
  54. user: {},
  55. otherNum: '',
  56. moneyList: [{
  57. id: '5',
  58. name: '5'
  59. },
  60. {
  61. id: '10',
  62. name: '10'
  63. },
  64. {
  65. id: '20',
  66. name: '20'
  67. },
  68. {
  69. id: '50',
  70. name: '50'
  71. },
  72. {
  73. id: '100',
  74. name: '100'
  75. },
  76. ],
  77. }
  78. },
  79. onLoad(op) {
  80. if (op.deviceNo) {
  81. this.submitForm.deviceNo = op.deviceNo;
  82. this.submitForm.channelNo = op.gun;
  83. this.submitForm.carNumber = '鄂DD12352';
  84. }
  85. },
  86. onShow() {
  87. this.getHomePage()
  88. },
  89. methods: {
  90. ckInput(text){
  91. if(text.indexOf('.')>0){
  92. this.$nextTick(()=>{
  93. this.otherNum=text.substring(0,text.indexOf('.'))
  94. uni.showToast({
  95. title:"请输入正整数"
  96. })
  97. })
  98. }
  99. var t =Number(text);
  100. if(t<1){
  101. this.$nextTick(()=>{
  102. this.otherNum='';
  103. })
  104. }
  105. if(t>500){
  106. this.$nextTick(()=>{
  107. this.otherNum=500;
  108. })
  109. }
  110. },
  111. moneyClick(index) {
  112. this.moneyActiveClass = index;
  113. },
  114. confirm() {
  115. //console.log(JSON.stringify(this.submitForm))
  116. uni.showLoading({
  117. title: "加载中",
  118. mask: true,
  119. })
  120. //this.submitForm.deviceNo = this.detail.deviceNo;
  121. API.startCarCharging(this.submitForm).then((res) => {
  122. console.log(JSON.stringify(this.res))
  123. this.gotoUrl("/pages/searchPile/chargeProcess/dcCharging");
  124. }).catch(error => {
  125. uni.hideLoading()
  126. if (error == '用户账户余额不足!') {
  127. uni.showModal({
  128. title: '支付',
  129. content: '用户账户余额不足,是否充值?',
  130. success: res => {
  131. if (res.confirm) {
  132. //付钱 改为组件
  133. this.gotoUrl("pages/user/finance/recharge");
  134. } else if (res.cancel) {
  135. console.log('用户点击取消');
  136. }
  137. }
  138. });
  139. } else {
  140. uni.showToast({
  141. title: error
  142. })
  143. }
  144. })
  145. },
  146. getHomePage() {
  147. uni.showLoading({
  148. title: "加载中",
  149. mask: true,
  150. })
  151. API.personalCenter().then((res) => {
  152. this.user = res.data
  153. this.isReady = true;
  154. uni.hideLoading()
  155. }).catch(error => {
  156. uni.showToast({
  157. title: error
  158. })
  159. })
  160. },
  161. submit() {
  162. if(this.moneyActiveClass==-1&&!this.otherNum){
  163. this.submitForm.chargeStrategy=0;
  164. this.submitForm.amount=0
  165. }else{
  166. this.submitForm.chargeStrategy=2;
  167. if(this.otherNum){
  168. this.submitForm.amount=this.otherNum
  169. }else{
  170. this.submitForm.amount=this.moneyActiveClass
  171. }
  172. }
  173. if (!this.submitForm.channelNo) {
  174. uni.showToast({
  175. title: '请先选择充电通道'
  176. })
  177. return
  178. }
  179. if (this.submitForm.chargeStrategy == 0 && this.user.balance < 5) {
  180. uni.showModal({
  181. title: '支付',
  182. content: '余额不足5元无法开启充满自停,是否充值?',
  183. success: res => {
  184. if (res.confirm) {
  185. //付钱 改为组件
  186. this.gotoUrl("pages/user/finance/recharge");
  187. } else if (res.cancel) {
  188. console.log('用户点击取消');
  189. }
  190. }
  191. });
  192. } else {
  193. this.confirm()
  194. }
  195. },
  196. }
  197. }
  198. </script>
  199. <style>
  200. page {
  201. background-color: #fff;
  202. }
  203. </style>
  204. <style lang="scss" scoped>
  205. /deep/.u-radio-group {
  206. width: 100%;
  207. }
  208. /deep/.u-radio {
  209. position: relative;
  210. }
  211. /deep/.u-radio__icon-wrap {
  212. position: absolute;
  213. right: 0;
  214. }
  215. .recharge-item:last-child {
  216. font-size: 14px !important;
  217. color: #999999;
  218. }
  219. .recharge {
  220. padding: 16px;
  221. .title {
  222. font-size: 16px;
  223. }
  224. p {
  225. color: #666;
  226. margin-top: 4px;
  227. }
  228. .self-stop.active{
  229. background-color: #EFFFF7;
  230. border-color: #00B962;
  231. color: #00B962;
  232. }
  233. .rechargeMain {
  234. display: flex;
  235. flex-wrap: wrap;
  236. justify-content: space-between;
  237. margin-top: 12px;
  238. margin-bottom: 20px;
  239. .recharge-item {
  240. width: 31%;
  241. border: 1px solid #e3e3e3;
  242. padding: 15px 0;
  243. border-radius: 4px;
  244. text-align: center;
  245. margin-bottom: 10px;
  246. font-size: 16px;
  247. }
  248. .active {
  249. background-color: #EFFFF7;
  250. border-color: #00B962;
  251. color: #00B962;
  252. }
  253. }
  254. .self-stop {
  255. width: 105px;
  256. height: 48px;
  257. line-height: 48px;
  258. border-radius: 4px;
  259. color: #101010;
  260. font-size: 16px;
  261. text-align: center;
  262. font-family: Arial;
  263. border: 1px solid rgba(227, 227, 227, 100);
  264. margin-top: 12px;
  265. }
  266. }
  267. .recharge-input {
  268. margin-top: 8px;
  269. margin-bottom: 32px;
  270. }
  271. .recharge-radio {
  272. margin-top: 10px;
  273. .recharge-radio-item {
  274. display: flex;
  275. align-items: center;
  276. }
  277. .recharge-radio-name {
  278. margin-left: 8px;
  279. }
  280. }
  281. .but-box {
  282. width: 335px;
  283. height: 44px;
  284. margin: 0 auto;
  285. .u-size-default[data-v-3bf2dba7] {
  286. background-color: rgba(0, 185, 98, 100);
  287. color: rgba(255, 255, 255, 100);
  288. font-size: 16px;
  289. text-align: center;
  290. }
  291. }
  292. </style>