charge.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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" @click="moneyClick(item.id)"
  9. :class="!otherNum&&moneyActiveClass == item.id ? 'active' : ''" v-for="(item,index) in moneyList"
  10. :key="item.id">
  11. {{item.name}}元
  12. </view>
  13. <view class="recharge-item" :class="otherNum ? 'active' : ''" style="
  14. padding: 8px 0px;">
  15. <u-input v-model="otherNum" @input="ckInput" type="digit" placeholder="其他充值金额" />
  16. </view>
  17. <view style="color: rgba(153, 153, 153, 100);
  18. font-size: 12px;
  19. text-align: left;
  20. font-family: AlibabaPuHui-regular;"><span style="color:red">*</span>充电金额输入范围为1元-500元的整数。实际充电金额与所选金额会略有出入(一般误差约几分钱),最终结算金额将以实际充入电量为准。</view>
  21. </view>
  22. <p>其他充电模式</p>
  23. <view @click="moneyClick(-1)" :class="!otherNum&&moneyActiveClass == -1? 'active' : ''" class="self-stop ">
  24. 充满自停
  25. </view>
  26. <!-- 优惠券 -->
  27. <view class="discounts" v-if="false">
  28. <view class="title">
  29. <view class="title-1">
  30. 优惠券
  31. </view>
  32. <view class="title-2">
  33. 每次只能使用1张
  34. </view>
  35. <view class="title-3">
  36. -¥6.00
  37. </view>
  38. </view>
  39. <view class="select">
  40. <u-radio-group v-model="value" @change="radioGroupChange" wrap="true">
  41. <u-radio @change="radioChange" v-for="(item, index) in list" :key="index" :name="item.name"
  42. :disabled="item.disabled">
  43. {{item.name}}
  44. </u-radio>
  45. <view class="explain">使用说明</view>
  46. </u-radio-group>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="bottom">
  51. <view class="botton"
  52. @click="submit"
  53. >开始充电</view>
  54. </view>
  55. <!-- <view class="but-box" style="margin-bottom: 20px;">
  56. <u-button
  57. style=" background-color: rgba(0, 185, 98, 100);
  58. color: rgba(255, 255, 255, 100);
  59. font-size: 16px;
  60. text-align: center;"
  61. @click="submit" shape="circle">开始充电</u-button>
  62. </view> -->
  63. </view>
  64. </template>
  65. <script>
  66. import * as API from '@/apis/chargeProcess.js'
  67. export default {
  68. data() {
  69. return {
  70. moneyActiveClass: "5",
  71. detail: {},
  72. //提交信息
  73. submitForm: {
  74. deviceNo: '',
  75. channelNo: '',
  76. carNumber: '',
  77. chargeStrategy: 2,
  78. amount: 0
  79. //paytype:'YE',
  80. },
  81. user: {},
  82. otherNum: '',
  83. moneyList: [{
  84. id: '5',
  85. name: '5'
  86. },
  87. {
  88. id: '10',
  89. name: '10'
  90. },
  91. {
  92. id: '20',
  93. name: '20'
  94. },
  95. {
  96. id: '50',
  97. name: '50'
  98. },
  99. {
  100. id: '100',
  101. name: '100'
  102. },
  103. ],
  104. // 优惠券
  105. list: [{
  106. name: '满50元减6元',
  107. disabled: false
  108. },
  109. {
  110. name: '满30元减3元',
  111. disabled: false
  112. },
  113. {
  114. name: '满100减15元 未满足使用条件',
  115. disabled: false
  116. }
  117. ],
  118. }
  119. },
  120. onLoad(op) {
  121. if (op.deviceNo) {
  122. this.submitForm.deviceNo = op.deviceNo;
  123. this.submitForm.channelNo = op.gun;
  124. this.submitForm.carNumber = op.carNumber;
  125. }
  126. },
  127. onShow() {
  128. this.getHomePage()
  129. },
  130. methods: {
  131. ckInput(text) {
  132. if (text.indexOf('.') > 0) {
  133. this.$nextTick(() => {
  134. this.otherNum = text.substring(0, text.indexOf('.'))
  135. uni.showToast({
  136. title: "请输入正整数"
  137. })
  138. })
  139. }
  140. var t = Number(text);
  141. if (t < 1) {
  142. this.$nextTick(() => {
  143. this.otherNum = '';
  144. })
  145. }
  146. if (t > 500) {
  147. this.$nextTick(() => {
  148. this.otherNum = 500;
  149. })
  150. }
  151. },
  152. moneyClick(index) {
  153. this.moneyActiveClass = index;
  154. },
  155. confirm() {
  156. //console.log(JSON.stringify(this.submitForm))
  157. uni.showLoading({
  158. title: "加载中",
  159. mask: true,
  160. })
  161. //this.submitForm.deviceNo = this.detail.deviceNo;
  162. API.startCarCharging(this.submitForm).then((res) => {
  163. console.log(JSON.stringify(this.res))
  164. this.gotoUrl("pages/searchPile/chargeProcess/dcCharging?id=" + res.data.recordId);
  165. }).catch(error => {
  166. uni.hideLoading()
  167. if (error == '用户账户余额不足!') {
  168. uni.showModal({
  169. title: '支付',
  170. content: '用户账户余额不足,是否充值?',
  171. success: res => {
  172. if (res.confirm) {
  173. //付钱 改为组件
  174. this.gotoUrl("pages/user/finance/recharge");
  175. } else if (res.cancel) {
  176. console.log('用户点击取消');
  177. }
  178. }
  179. });
  180. } else {
  181. uni.showToast({
  182. title: error
  183. })
  184. }
  185. })
  186. },
  187. getHomePage() {
  188. uni.showLoading({
  189. title: "加载中",
  190. mask: true,
  191. })
  192. API.personalCenter().then((res) => {
  193. this.user = res.data
  194. this.isReady = true;
  195. uni.hideLoading()
  196. }).catch(error => {
  197. uni.showToast({
  198. title: error
  199. })
  200. })
  201. },
  202. submit() {
  203. if (this.moneyActiveClass == -1 && !this.otherNum) {
  204. this.submitForm.chargeStrategy = 0;
  205. this.submitForm.amount = 0
  206. } else {
  207. this.submitForm.chargeStrategy = 2;
  208. if (this.otherNum) {
  209. this.submitForm.amount = this.otherNum
  210. } else {
  211. this.submitForm.amount = this.moneyActiveClass
  212. }
  213. }
  214. if (!this.submitForm.channelNo) {
  215. uni.showToast({
  216. title: '请先选择充电通道'
  217. })
  218. return
  219. }
  220. if (this.submitForm.chargeStrategy == 0 && this.user.balance < 5) {
  221. uni.showModal({
  222. title: '支付',
  223. content: '余额不足5元无法开启充满自停,是否充值?',
  224. success: res => {
  225. if (res.confirm) {
  226. //付钱 改为组件
  227. this.gotoUrl("pages/user/finance/recharge");
  228. } else if (res.cancel) {
  229. console.log('用户点击取消');
  230. }
  231. }
  232. });
  233. } else {
  234. this.confirm()
  235. }
  236. },
  237. }
  238. }
  239. </script>
  240. <style>
  241. page {
  242. background-color: #fff;
  243. }
  244. </style>
  245. <style lang="scss" scoped>
  246. /deep/.u-radio-group {
  247. width: 100%;
  248. }
  249. /deep/.u-radio {
  250. position: relative;
  251. }
  252. /deep/.u-radio__icon-wrap {
  253. position: absolute;
  254. right: 0;
  255. }
  256. .recharge-item:last-child {
  257. font-size: 14px !important;
  258. color: #999999;
  259. }
  260. .u-input {
  261. text-align: center !important;
  262. }
  263. .recharge {
  264. padding: 16px;
  265. padding-bottom: 80px;
  266. .title {
  267. font-size: 16px;
  268. }
  269. p {
  270. color: #666;
  271. margin-top: 4px;
  272. }
  273. .self-stop.active {
  274. background-color: #EFFFF7;
  275. border-color: #00B962;
  276. color: #00B962;
  277. }
  278. .rechargeMain {
  279. display: flex;
  280. flex-wrap: wrap;
  281. justify-content: space-between;
  282. margin-top: 12px;
  283. margin-bottom: 20px;
  284. .recharge-item {
  285. width: 31%;
  286. border: 1px solid #e3e3e3;
  287. padding: 15px 0;
  288. border-radius: 4px;
  289. text-align: center;
  290. margin-bottom: 10px;
  291. font-size: 16px;
  292. }
  293. .active {
  294. background-color: #EFFFF7;
  295. border-color: #00B962;
  296. color: #00B962;
  297. }
  298. }
  299. .self-stop {
  300. width: 105px;
  301. height: 48px;
  302. line-height: 48px;
  303. border-radius: 4px;
  304. color: #101010;
  305. font-size: 16px;
  306. text-align: center;
  307. font-family: Arial;
  308. border: 1px solid rgba(227, 227, 227, 100);
  309. margin-top: 12px;
  310. }
  311. }
  312. .recharge-input {
  313. margin-top: 8px;
  314. margin-bottom: 32px;
  315. }
  316. .recharge-radio {
  317. margin-top: 10px;
  318. .recharge-radio-item {
  319. display: flex;
  320. align-items: center;
  321. }
  322. .recharge-radio-name {
  323. margin-left: 8px;
  324. }
  325. }
  326. .but-box {
  327. width: 89.3%;
  328. height: 44px;
  329. margin: 0 auto;
  330. position: fixed;
  331. bottom: 0;
  332. right: 0;
  333. left: 0;
  334. }
  335. //优惠券
  336. .discounts {
  337. margin-top: 20px;
  338. width: 100%;
  339. .title {
  340. width: 100%;
  341. display: flex;
  342. .title-1 {
  343. width: 48px;
  344. height: 22px;
  345. color: rgba(16, 16, 16, 100);
  346. font-size: 16px;
  347. }
  348. .title-2 {
  349. margin-left: 4px;
  350. font-size: 14px;
  351. line-height: 20px;
  352. }
  353. .title-3 {
  354. margin-left: 126px;
  355. height: 19px;
  356. font-size: 16px;
  357. }
  358. }
  359. .select {
  360. position: relative;
  361. /deep/.u-radio {
  362. padding: 18px 16px;
  363. margin-top: 12px;
  364. width: 100%;
  365. height: 48px;
  366. border-radius: 4px;
  367. background-color: rgba(255, 255, 255, 100);
  368. text-align: center;
  369. border: 1px solid rgba(227, 227, 227, 100);
  370. position: relative;
  371. }
  372. /deep/.u-radio:nth-child(3) {
  373. background-color: #e3e3e3 !important;
  374. }
  375. /deep/.u-radio__icon-wrap {
  376. left: 16px;
  377. background-color: #fff;
  378. }
  379. /deep/.u-radio__label {
  380. margin-left: 40px;
  381. }
  382. }
  383. .explain {
  384. width: 64px;
  385. height: 24px;
  386. line-height: 24px;
  387. position: absolute;
  388. top: 24px;
  389. right: 12px;
  390. border-radius: 4px;
  391. background-color: rgba(255, 255, 255, 100);
  392. text-align: center;
  393. border: 1px solid rgba(227, 227, 227, 100);
  394. color: rgba(0, 185, 98, 100);
  395. font-size: 12px;
  396. }
  397. }
  398. // 尾部
  399. .bottom {
  400. background-color: #fff;
  401. width: 100%;
  402. height: 64px;
  403. line-height: 64px;
  404. position: fixed;
  405. bottom: 0;
  406. left: 0;
  407. z-index: 999;
  408. padding: 12px 16px;
  409. .botton {
  410. //width: 343px;
  411. height: 40px;
  412. line-height: 40px;
  413. border-radius: 50px;
  414. background-color: rgba(0, 185, 98, 100);
  415. color: rgba(255, 255, 255, 100);
  416. font-size: 16px;
  417. text-align: center;
  418. margin: 0 auto;
  419. }
  420. }
  421. </style>