charge.vue 10 KB

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