charge.vue 11 KB

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