charge.vue 10.0 KB

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