charge.vue 9.0 KB

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