index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <template>
  2. <view class="content">
  3. <swiper :indicator-dots="true" indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#ffffff"
  4. :autoplay="true" :interval="4000" :duration="1000" circular>
  5. <swiper-item v-for="item in stationPicList" :key="item.id">
  6. <image :src="item" mode="scaleToFill"></image>
  7. </swiper-item>
  8. </swiper>
  9. <view class="box">
  10. <view class="title">
  11. <view class="left">
  12. 选择枪号 |
  13. <text v-if="!selectedGas.oilGunNo">请选择枪</text>
  14. <text class="selected" v-else>已选择{{selectedGas.oilGunNo}}号枪</text>
  15. </view>
  16. <!-- <text class="right" @click="openMoreGun">更多 ></text> -->
  17. </view>
  18. <view class="notice-bar-container">
  19. <uni-notice-bar class="notice-bar" scrollable="true" single="true" showIcon="true" :speed="50" :text="notice">
  20. </uni-notice-bar>
  21. </view>
  22. <view class="gun">
  23. <view v-for="item in cutGasList" @click="selectGas(item)"
  24. :class="[item.oilGunId === selectedGas.oilGunId ? 'selected' : '', cutGasList.length === 2 || cutGasList.length ===4 ? 'lengthIs2Or4' : '',cutGasList.length ===1 ? 'lengthIs1' : '' ]"
  25. :key="item.oilGunId">
  26. <text>{{ item.oilGunNo + "号枪"}}</text>
  27. <text>{{item.oilName}}</text>
  28. </view>
  29. <view @click="openMoreGun" :class="[showMoreGasSelected? 'selected':'']" v-if="gasList.length > 6">
  30. <text class="more">更多>></text>
  31. </view>
  32. </view>
  33. <view class="title" @click="changeInputFocus">
  34. <view class="left">
  35. 输入金额 |
  36. <text>建议询问加油员后输入</text>
  37. </view>
  38. </view>
  39. <view class="amount">
  40. <view class="inp">
  41. <input placeholder="点击输入金额" confirm-type="done" type="digit" step="0.01" min="0" @blur="inputAccount"
  42. v-model="account" :focus="inputFocusFlag" />
  43. <text>(元)</text>
  44. </view>
  45. <view class="btn">
  46. <view :class="[item === account ? 'selected' : '']" v-for="item in accountList" :key="item"
  47. @click="selectAccount(item)">
  48. {{item}}
  49. </view>
  50. </view>
  51. </view>
  52. <view class="tip" @click="changeInputFocus">
  53. <image src="../../static/icon/a01-zhuyi.2x.png" mode="scaleToFill"></image>
  54. <text>请勿在油机旁使用手机</text>
  55. </view>
  56. <view class="submit">
  57. <button type="default" :class="[avalibleSettle ? 'avalible' : '']" @click="creatOrder" :loading="loading"
  58. :disabled="!avalibleSettle || loading">
  59. 结算
  60. </button>
  61. </view>
  62. </view>
  63. <uni-popup ref="popup" type="bottom" :maskClick="true">
  64. <view class="more-gun">
  65. <view class="title">
  66. <text>选择枪号</text>
  67. <view class="icon" @click="closeMoreGun"></view>
  68. </view>
  69. <view class="gun-list">
  70. <scroll-view scroll-y="true">
  71. <view v-for="item in gasList" @click="selectGasPopup(item)"
  72. :class="[item.oilGunId === selectedGas.oilGunId ? 'selected' : '']" :key="item.oilGunId">
  73. <text>{{ item.oilGunNo + "号枪"}}</text>
  74. <text>{{item.oilName}}</text>
  75. </view>
  76. </scroll-view>
  77. </view>
  78. </view>
  79. </uni-popup>
  80. </view>
  81. </template>
  82. <script>
  83. import {
  84. mapState,
  85. mapMutations
  86. } from "vuex";
  87. import getPermission from "../../util/permission.js"
  88. import Parse from "../../util/parse.js"
  89. export default {
  90. data() {
  91. return {
  92. stationPicList: [],
  93. notice: '',
  94. gasList: [],
  95. selectedGas: undefined,
  96. accountList: [100, 200, 300, 400],
  97. account: "",
  98. loading: false,
  99. inputFocusFlag: false,
  100. employeeList: [],
  101. }
  102. },
  103. created() {
  104. this.init()
  105. },
  106. async mounted() {
  107. },
  108. computed: {
  109. cutGasList() {
  110. if (this.gasList.length > 6) {
  111. return this.gasList.slice(0, 5)
  112. }
  113. return this.gasList.slice(0, 6)
  114. },
  115. showMoreGasSelected() {
  116. if (!this.selectedGas) {
  117. return false
  118. }
  119. const len = this.cutGasList.filter((ele) => {
  120. return ele.oilGunId == this.selectedGas.oilGunId
  121. })
  122. if (len.length === 0) {
  123. return true
  124. }
  125. return false
  126. },
  127. avalibleSettle() {
  128. return !!this.account && this.account > 0 && !!this.selectedGas
  129. }
  130. },
  131. methods: {
  132. ...mapMutations(["updateCouponEnabledFlag","updateSucceedIssueId","updateCouponList","updateOrderInfo", "updateSelectedGas", "resetApplet"]),
  133. async init() {
  134. // 准入条件
  135. if (!this.stationId) {
  136. const parse = Parse.getInstance()
  137. return parse.scanCode(true,{
  138. showCancel: false,
  139. content:'亲,请扫码进入~',
  140. }).then(()=>{
  141. this.init()
  142. }).catch((err)=>{});
  143. // this.scanCode("亲,请扫码进入~").then(()=>{
  144. // this.init()
  145. // });
  146. }
  147. try {
  148. uni.showLoading({
  149. title: '加载中~',
  150. mask: true
  151. });
  152. const initDataPro = await this.$Request({
  153. url: "/stationOilGunListNew",
  154. method: "GET",
  155. data: {
  156. stationId: this.stationId,
  157. personnelId: this.employeeId
  158. }
  159. })
  160. if (initDataPro.retCode != 0) {
  161. throw new Error("油站初始化失败")
  162. }
  163. this.stationPicList = initDataPro.data.listPic
  164. this.notice = initDataPro.data.notice
  165. this.gasList = initDataPro.data.stationOilGunList
  166. this.employeeList = initDataPro.data.personnalList
  167. if (!this.employeeId && this.employeeList.length > 1) {
  168. uni.hideLoading()
  169. const parse = Parse.getInstance()
  170. parse.scanCode(true,{
  171. showCancel: false,
  172. // showCancel: true,
  173. content:'此站点只能扫码进入~',
  174. }).then(()=>{
  175. this.init()
  176. }).catch((err)=>{
  177. });
  178. }
  179. if (this.gasList.length == 1) {
  180. this.selectedGas = this.gasList[0]
  181. this.updateSelectedGas(this.gasList[0])
  182. }
  183. uni.hideLoading();
  184. } catch (e) {
  185. //TODO handle the exception
  186. uni.hideLoading();
  187. uni.showModal({
  188. title: '≧▽≦*',
  189. content: '矮油,初始化失败',
  190. confirmText: "重新进入",
  191. showCancel: false,
  192. success: function(res) {
  193. if (res.confirm) {
  194. uni.redirectTo({
  195. url: "/pages/index/index"
  196. })
  197. }
  198. }
  199. });
  200. }
  201. },
  202. // async scanCode(msg) {
  203. // const showModalPro = await uni.showModal({
  204. // title: '~( ̄▽ ̄)~',
  205. // showCancel: !!this.stationId,
  206. // content: msg || '此站点只能扫码进入~',
  207. // cancelText: '返回',
  208. // confirmText: '立刻扫码',
  209. // })
  210. // if (showModalPro[1].cancel) {
  211. // uni.navigateBack({
  212. // delta: 1
  213. // })
  214. // } else if (showModalPro[1].confirm) {
  215. // const parse = Parse.getInstance()
  216. // return parse.scanCode().catch((err) => {
  217. // return this.scanCode(err)
  218. // });
  219. // }
  220. // },
  221. change(e) {
  222. this.current = e.detail.current;
  223. },
  224. changeInputFocus() {
  225. this.inputFocusFlag = true
  226. },
  227. openMoreGun() {
  228. this.$refs.popup.open()
  229. },
  230. closeMoreGun() {
  231. this.$refs.popup.close()
  232. },
  233. selectGas(ele) {
  234. this.selectedGas = ele
  235. this.updateSelectedGas(ele)
  236. },
  237. selectGasPopup(ele) {
  238. this.updateSelectedGas(ele)
  239. this.selectedGas = ele
  240. this.$refs.popup.close()
  241. },
  242. selectAccount(ele) {
  243. this.account = ele
  244. },
  245. async creatAliOrder(){
  246. },
  247. async creatOrder() {
  248. if (!getPermission()) {
  249. return
  250. }
  251. this.loading = true
  252. uni.showLoading({
  253. title: '订单创建中...',
  254. mask: true
  255. });
  256. try {
  257. //#ifdef MP-WEIXIN
  258. const addNewOrderPro = await this.$Request({
  259. url: "/AddPayOrderInfoNew",
  260. method: "POST",
  261. data: {
  262. "userType": "1",
  263. "openId": this.openId,
  264. "stationId": this.stationId,
  265. "receivableAmt": this.account,
  266. "oilName": this.selectedGas.oilName,
  267. "oilGun": this.selectedGas.oilGunNo,
  268. "labelId": this.labelId,
  269. "personnelId": this.employeeId,
  270. }
  271. })
  272. //#endif
  273. //#ifdef MP-ALIPAY
  274. const addNewOrderPro = await this.$Request({
  275. url: "/AddPayOrderFromAliPay",
  276. method: "POST",
  277. data: {
  278. "openId": this.openId,
  279. "stationId": this.stationId,
  280. "receivableAmt": this.account,
  281. "oilName": this.selectedGas.oilName,
  282. "oilGun": this.selectedGas.oilGunNo,
  283. "labelId": this.labelId,
  284. "personnelId": this.employeeId,
  285. "customerName":this.userInfo.nickName,
  286. }
  287. })
  288. console.log('aLiAddNewOrderPro',addNewOrderPro)
  289. //#endif
  290. if (addNewOrderPro.retCode != 0) {
  291. throw new Error("创建失败~")
  292. return
  293. }
  294. this.loading = false
  295. uni.hideLoading();
  296. this.updateOrderInfo(addNewOrderPro.data)
  297. console.log('订单信息',addNewOrderPro)
  298. //#ifdef MP-WEIXIN
  299. this.updateCouponEnabledFlag(addNewOrderPro.data.couponEnabledFlag)
  300. this.updateSucceedIssueId(addNewOrderPro.data.couponIssueId)
  301. this.updateCouponList(addNewOrderPro.data.userCouponsList)
  302. //#endif
  303. uni.navigateTo({
  304. url: "/pages/confirm/confirm"
  305. })
  306. } catch (e) {
  307. this.loading = false
  308. uni.hideLoading();
  309. uni.showToast({
  310. icon: "error",
  311. title: '请重试~'
  312. })
  313. this.resetApplet();
  314. }
  315. },
  316. inputAccount(e) {
  317. this.inputFocusFlag = false;
  318. if (isNaN(+e.detail.value)) {
  319. this.account = ''
  320. return
  321. }
  322. this.account = (+e.detail.value).toFixed(2).toString()
  323. // // const reg = /^[1-9]{1,}(\.)?([0-9]{0,2})?/ // 最小数额1
  324. // const reg = /^[0-9]{1,}(\.)?([0-9]{0,2})?/ // 不设置最小数额
  325. // let res = e.detail.value.match(reg, "");
  326. // console.log(this)
  327. // console.log(res)
  328. // if(res === null){
  329. // this.account = ""
  330. // return
  331. // }
  332. // res = res[0]
  333. // const reg1 = /\.$/
  334. // res = + res.replace(reg1, '')
  335. // if (res == 0) {
  336. // this.account = ''
  337. // return
  338. // }
  339. // this.account = res.toString()
  340. // setTimeout(() => {
  341. // this.account = res.toString()
  342. // }, 0)
  343. }
  344. }
  345. }
  346. </script>
  347. <style lang="scss">
  348. page {
  349. width: 750rpx;
  350. .content {
  351. swiper {
  352. height: 389rpx;
  353. swiper-item {
  354. image {
  355. width: 100%;
  356. height: 100%;
  357. border-radius: 30rpx;
  358. }
  359. }
  360. }
  361. .box {
  362. box-sizing: border-box;
  363. width: 750rpx;
  364. background: #FFFFFF;
  365. border-radius: 36rpx 36rpx 0px 0px;
  366. box-shadow: 0 -2rpx 2rpx rgba(0, 0, 0, 0.1);
  367. padding: 40rpx;
  368. display: flex;
  369. flex-direction: column;
  370. .title {
  371. display: flex;
  372. justify-content: space-between;
  373. .left {
  374. height: 42rpx;
  375. font-size: 32rpx;
  376. font-family: PingFangSC-Medium, PingFang SC;
  377. font-weight: 600;
  378. color: #111111;
  379. line-height: 45rpx;
  380. text {
  381. font-weight: 500;
  382. color: #b0b0b0;
  383. font-size: 28rpx;
  384. margin-left: 8rpx;
  385. }
  386. .selected {
  387. color: #ff0000;
  388. font-weight: 500;
  389. }
  390. }
  391. .right {
  392. height: 40rpx;
  393. font-size: 28rpx;
  394. color: #AAAAAA;
  395. line-height: 40rpx;
  396. margin-top: 4rpx;
  397. }
  398. }
  399. .notice-bar-container {
  400. margin-top: 20rpx;
  401. .notice-bar,
  402. .uni-noticebar {
  403. margin: 0;
  404. border-radius: 20rpx;
  405. overflow: hidden;
  406. }
  407. }
  408. .gun {
  409. display: flex;
  410. flex-wrap: wrap;
  411. justify-content: space-around;
  412. align-content: space-around;
  413. margin-top: 30rpx;
  414. view {
  415. width: 200rpx;
  416. height: 110rpx;
  417. background: rgba(255, 255, 255, 0.08);
  418. box-shadow: 0px 2rpx 9rpx 4rpx rgba(16, 178, 125, 0.1);
  419. border-radius: 12rpx;
  420. display: flex;
  421. flex-direction: column;
  422. justify-content: center;
  423. text-align: center;
  424. margin-bottom: 20rpx;
  425. text {
  426. font-size: 28rpx;
  427. font-weight: 500;
  428. color: #666666;
  429. line-height: 40rpx;
  430. }
  431. text:nth-child(1) {
  432. margin-top: 10rpx;
  433. color: #7c7c7c;
  434. font-size: 20rpx;
  435. line-height: 40rpx;
  436. }
  437. text:nth-child(2) {
  438. font-size: 25rpx;
  439. line-height: 60rpx;
  440. font-weight: 500;
  441. }
  442. text.more {
  443. font-size: 28rpx;
  444. font-weight: 500;
  445. color: #000;
  446. line-height: 100rpx;
  447. margin-top: 0;
  448. }
  449. }
  450. view.lengthIs2Or4 {
  451. width: 280rpx;
  452. }
  453. view.lengthIs1 {
  454. width: 480rpx;
  455. }
  456. view.selected {
  457. background-color: #0ea374;
  458. text {
  459. color: #FFFFFF;
  460. }
  461. }
  462. }
  463. .title:nth-of-type(4) {
  464. margin-top: 10rpx;
  465. }
  466. .amount {
  467. margin-top: 30rpx;
  468. .inp {
  469. width: 670rpx;
  470. height: 100rpx;
  471. background: rgba(255, 255, 255, 0.08);
  472. box-shadow: 0px 2rpx 9rpx 4rpx rgba(16, 178, 125, 0.1);
  473. border-radius: 13rpx;
  474. position: relative;
  475. input {
  476. position: absolute;
  477. top: 30rpx;
  478. left: 30rpx;
  479. color: #ff0000;
  480. font-weight: 600;
  481. }
  482. text {
  483. position: absolute;
  484. top: 40rpx;
  485. right: 30rpx;
  486. width: 56rpx;
  487. height: 33rpx;
  488. font-size: 24rpx;
  489. color: #AAAAAA;
  490. line-height: 33rpx;
  491. }
  492. }
  493. .btn {
  494. display: flex;
  495. justify-content: space-between;
  496. align-items: center;
  497. margin-top: 20rpx;
  498. view {
  499. width: 153rpx;
  500. height: 80rpx;
  501. background: rgba(255, 255, 255, 0.08);
  502. box-shadow: 0px 2rpx 9rpx 4rpx rgba(16, 178, 125, 0.1);
  503. border-radius: 13rpx;
  504. text-align: center;
  505. line-height: 80rpx;
  506. font-size: 32rpx;
  507. color: #AAAAAA;
  508. }
  509. .selected {
  510. background-color: #0ea374;
  511. color: #fff;
  512. }
  513. }
  514. }
  515. .tip {
  516. display: flex;
  517. justify-content: center;
  518. align-items: center;
  519. height: 60rpx;
  520. margin-top: 20rpx;
  521. image {
  522. display: inline-block;
  523. width: 25rpx;
  524. height: 25rpx;
  525. border-radius: 12.5rpx;
  526. }
  527. text {
  528. font-size: 27rpx;
  529. color: #DB9D28;
  530. line-height: 60rpx;
  531. padding: 0;
  532. margin: 0;
  533. }
  534. }
  535. .submit {
  536. height: 80rpx;
  537. margin-top: 20rpx;
  538. button {
  539. width: 670rpx;
  540. height: 80rpx;
  541. background: #CCCCCC;
  542. border-radius: 45rpx;
  543. font-size: 32rpx;
  544. color: #FFFFFF;
  545. line-height: 80rpx;
  546. text-align: center;
  547. }
  548. button.avalible {
  549. background: #0EA374;
  550. }
  551. }
  552. }
  553. }
  554. .more-gun {
  555. width: 750rpx;
  556. max-height: 985rpx;
  557. background: #F8F8F8;
  558. border-radius: 42rpx 42rpx 0px 0px;
  559. .title {
  560. height: 80rpx;
  561. text-align: center;
  562. position: relative;
  563. text {
  564. width: 160rpx;
  565. font-size: 32rpx;
  566. font-weight: 600;
  567. color: #111111;
  568. line-height: 70rpx;
  569. }
  570. .icon {
  571. width: 45rpx;
  572. height: 45rpx;
  573. background-color: red;
  574. background: url(../../static/icon/6_d05_close.2x.png) no-repeat 0px 0px;
  575. background-size: 100% 100%;
  576. position: absolute;
  577. top: 10rpx;
  578. right: 40rpx;
  579. }
  580. }
  581. .gun-list {
  582. margin-top: 20rpx;
  583. scroll-view {
  584. padding: 0 30rpx;
  585. max-height: 850rpx;
  586. view {
  587. width: 200rpx;
  588. height: 110rpx;
  589. background: rgba(255, 255, 255, 0.08);
  590. box-shadow: 0px 2rpx 9rpx 4rpx rgba(16, 178, 125, 0.1);
  591. border-radius: 12rpx;
  592. display: inline-flex;
  593. flex-direction: column;
  594. justify-content: center;
  595. text-align: center;
  596. margin: 5rpx 15rpx 40rpx 15rpx;
  597. text {
  598. font-size: 28rpx;
  599. font-weight: 500;
  600. color: #666666;
  601. line-height: 40rpx;
  602. }
  603. text:nth-child(1) {
  604. margin-top: 10rpx;
  605. color: #7c7c7c;
  606. font-size: 20rpx;
  607. line-height: 40rpx;
  608. }
  609. text:nth-child(2) {
  610. font-size: 25rpx;
  611. line-height: 60rpx;
  612. font-weight: 500;
  613. }
  614. text.more {
  615. font-size: 28rpx;
  616. font-weight: 500;
  617. color: #000;
  618. line-height: 100rpx;
  619. margin-top: 0;
  620. }
  621. }
  622. .selected {
  623. background-color: #0ea374;
  624. text {
  625. color: #fff;
  626. }
  627. color: #fff;
  628. }
  629. }
  630. }
  631. }
  632. }
  633. </style>