charge.vue 11 KB

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