index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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(["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: true,
  172. content:'此站点只能扫码进入~',
  173. }).then(()=>{
  174. this.init()
  175. }).catch((err)=>{
  176. });
  177. }
  178. if (this.gasList.length == 1) {
  179. this.selectedGas = this.gasList[0]
  180. this.updateSelectedGas(this.gasList[0])
  181. }
  182. uni.hideLoading();
  183. } catch (e) {
  184. //TODO handle the exception
  185. uni.hideLoading();
  186. uni.showModal({
  187. title: '≧▽≦*',
  188. content: '矮油,初始化失败',
  189. confirmText: "重新进入",
  190. showCancel: false,
  191. success: function(res) {
  192. if (res.confirm) {
  193. uni.redirectTo({
  194. url: "/pages/index/index"
  195. })
  196. }
  197. }
  198. });
  199. }
  200. },
  201. // async scanCode(msg) {
  202. // const showModalPro = await uni.showModal({
  203. // title: '~( ̄▽ ̄)~',
  204. // showCancel: !!this.stationId,
  205. // content: msg || '此站点只能扫码进入~',
  206. // cancelText: '返回',
  207. // confirmText: '立刻扫码',
  208. // })
  209. // if (showModalPro[1].cancel) {
  210. // uni.navigateBack({
  211. // delta: 1
  212. // })
  213. // } else if (showModalPro[1].confirm) {
  214. // const parse = Parse.getInstance()
  215. // return parse.scanCode().catch((err) => {
  216. // return this.scanCode(err)
  217. // });
  218. // }
  219. // },
  220. change(e) {
  221. this.current = e.detail.current;
  222. },
  223. changeInputFocus() {
  224. this.inputFocusFlag = true
  225. },
  226. openMoreGun() {
  227. this.$refs.popup.open()
  228. },
  229. closeMoreGun() {
  230. this.$refs.popup.close()
  231. },
  232. selectGas(ele) {
  233. this.selectedGas = ele
  234. this.updateSelectedGas(ele)
  235. },
  236. selectGasPopup(ele) {
  237. this.updateSelectedGas(ele)
  238. this.selectedGas = ele
  239. this.$refs.popup.close()
  240. },
  241. selectAccount(ele) {
  242. this.account = ele
  243. },
  244. async creatOrder() {
  245. if (!getPermission()) {
  246. return
  247. }
  248. this.loading = true
  249. uni.showLoading({
  250. title: '订单创建中...',
  251. mask: true
  252. });
  253. try {
  254. const addNewOrderPro = await this.$Request({
  255. url: "/AddPayOrderInfoNew",
  256. method: "POST",
  257. data: {
  258. "userType": "1",
  259. "openId": this.openId,
  260. "stationId": this.stationId,
  261. "receivableAmt": this.account,
  262. "oilName": this.selectedGas.oilName,
  263. "oilGun": this.selectedGas.oilGunNo,
  264. "labelId": this.labelId,
  265. "personnelId": this.employeeId,
  266. }
  267. })
  268. if (addNewOrderPro.retCode != 0) {
  269. throw new Error("创建失败~")
  270. return
  271. }
  272. this.loading = false
  273. uni.hideLoading();
  274. this.updateOrderInfo(addNewOrderPro.data)
  275. uni.navigateTo({
  276. url: "/pages/confirm/confirm"
  277. })
  278. } catch (e) {
  279. this.loading = false
  280. uni.hideLoading();
  281. uni.showToast({
  282. icon: "error",
  283. title: '请重试~'
  284. })
  285. this.resetApplet();
  286. }
  287. },
  288. inputAccount(e) {
  289. this.inputFocusFlag = false;
  290. if (isNaN(+e.detail.value)) {
  291. this.account = ''
  292. return
  293. }
  294. this.account = (+e.detail.value).toFixed(2).toString()
  295. // // const reg = /^[1-9]{1,}(\.)?([0-9]{0,2})?/ // 最小数额1
  296. // const reg = /^[0-9]{1,}(\.)?([0-9]{0,2})?/ // 不设置最小数额
  297. // let res = e.detail.value.match(reg, "");
  298. // console.log(this)
  299. // console.log(res)
  300. // if(res === null){
  301. // this.account = ""
  302. // return
  303. // }
  304. // res = res[0]
  305. // const reg1 = /\.$/
  306. // res = + res.replace(reg1, '')
  307. // if (res == 0) {
  308. // this.account = ''
  309. // return
  310. // }
  311. // this.account = res.toString()
  312. // setTimeout(() => {
  313. // this.account = res.toString()
  314. // }, 0)
  315. }
  316. }
  317. }
  318. </script>
  319. <style lang="scss">
  320. page {
  321. width: 750rpx;
  322. .content {
  323. swiper {
  324. height: 389rpx;
  325. swiper-item {
  326. image {
  327. width: 100%;
  328. height: 100%;
  329. border-radius: 30rpx;
  330. }
  331. }
  332. }
  333. .box {
  334. box-sizing: border-box;
  335. width: 750rpx;
  336. background: #FFFFFF;
  337. border-radius: 36rpx 36rpx 0px 0px;
  338. box-shadow: 0 -2rpx 2rpx rgba(0, 0, 0, 0.1);
  339. padding: 40rpx;
  340. display: flex;
  341. flex-direction: column;
  342. .title {
  343. display: flex;
  344. justify-content: space-between;
  345. .left {
  346. height: 42rpx;
  347. font-size: 32rpx;
  348. font-family: PingFangSC-Medium, PingFang SC;
  349. font-weight: 600;
  350. color: #111111;
  351. line-height: 45rpx;
  352. text {
  353. font-weight: 500;
  354. color: #b0b0b0;
  355. font-size: 28rpx;
  356. margin-left: 8rpx;
  357. }
  358. .selected {
  359. color: #ff0000;
  360. font-weight: 500;
  361. }
  362. }
  363. .right {
  364. height: 40rpx;
  365. font-size: 28rpx;
  366. color: #AAAAAA;
  367. line-height: 40rpx;
  368. margin-top: 4rpx;
  369. }
  370. }
  371. .notice-bar-container {
  372. margin-top: 20rpx;
  373. .notice-bar,
  374. .uni-noticebar {
  375. margin: 0;
  376. border-radius: 20rpx;
  377. overflow: hidden;
  378. }
  379. }
  380. .gun {
  381. display: flex;
  382. flex-wrap: wrap;
  383. justify-content: space-around;
  384. align-content: space-around;
  385. margin-top: 30rpx;
  386. view {
  387. width: 200rpx;
  388. height: 110rpx;
  389. background: rgba(255, 255, 255, 0.08);
  390. box-shadow: 0px 2rpx 9rpx 4rpx rgba(16, 178, 125, 0.1);
  391. border-radius: 12rpx;
  392. display: flex;
  393. flex-direction: column;
  394. justify-content: center;
  395. text-align: center;
  396. margin-bottom: 20rpx;
  397. text {
  398. font-size: 28rpx;
  399. font-weight: 500;
  400. color: #666666;
  401. line-height: 40rpx;
  402. }
  403. text:nth-child(1) {
  404. margin-top: 10rpx;
  405. color: #7c7c7c;
  406. font-size: 20rpx;
  407. line-height: 40rpx;
  408. }
  409. text:nth-child(2) {
  410. font-size: 25rpx;
  411. line-height: 60rpx;
  412. font-weight: 500;
  413. }
  414. text.more {
  415. font-size: 28rpx;
  416. font-weight: 500;
  417. color: #000;
  418. line-height: 100rpx;
  419. margin-top: 0;
  420. }
  421. }
  422. view.lengthIs2Or4 {
  423. width: 280rpx;
  424. }
  425. view.lengthIs1 {
  426. width: 480rpx;
  427. }
  428. view.selected {
  429. background-color: #0ea374;
  430. text {
  431. color: #FFFFFF;
  432. }
  433. }
  434. }
  435. .title:nth-of-type(4) {
  436. margin-top: 10rpx;
  437. }
  438. .amount {
  439. margin-top: 30rpx;
  440. .inp {
  441. width: 670rpx;
  442. height: 100rpx;
  443. background: rgba(255, 255, 255, 0.08);
  444. box-shadow: 0px 2rpx 9rpx 4rpx rgba(16, 178, 125, 0.1);
  445. border-radius: 13rpx;
  446. position: relative;
  447. input {
  448. position: absolute;
  449. top: 30rpx;
  450. left: 30rpx;
  451. color: #ff0000;
  452. font-weight: 600;
  453. }
  454. text {
  455. position: absolute;
  456. top: 40rpx;
  457. right: 30rpx;
  458. width: 56rpx;
  459. height: 33rpx;
  460. font-size: 24rpx;
  461. color: #AAAAAA;
  462. line-height: 33rpx;
  463. }
  464. }
  465. .btn {
  466. display: flex;
  467. justify-content: space-between;
  468. align-items: center;
  469. margin-top: 20rpx;
  470. view {
  471. width: 153rpx;
  472. height: 80rpx;
  473. background: rgba(255, 255, 255, 0.08);
  474. box-shadow: 0px 2rpx 9rpx 4rpx rgba(16, 178, 125, 0.1);
  475. border-radius: 13rpx;
  476. text-align: center;
  477. line-height: 80rpx;
  478. font-size: 32rpx;
  479. color: #AAAAAA;
  480. }
  481. .selected {
  482. background-color: #0ea374;
  483. color: #fff;
  484. }
  485. }
  486. }
  487. .tip {
  488. display: flex;
  489. justify-content: center;
  490. align-items: center;
  491. height: 60rpx;
  492. margin-top: 20rpx;
  493. image {
  494. display: inline-block;
  495. width: 25rpx;
  496. height: 25rpx;
  497. border-radius: 12.5rpx;
  498. }
  499. text {
  500. font-size: 27rpx;
  501. color: #DB9D28;
  502. line-height: 60rpx;
  503. padding: 0;
  504. margin: 0;
  505. }
  506. }
  507. .submit {
  508. height: 80rpx;
  509. margin-top: 20rpx;
  510. button {
  511. width: 670rpx;
  512. height: 80rpx;
  513. background: #CCCCCC;
  514. border-radius: 45rpx;
  515. font-size: 32rpx;
  516. color: #FFFFFF;
  517. line-height: 80rpx;
  518. text-align: center;
  519. }
  520. button.avalible {
  521. background: #0EA374;
  522. }
  523. }
  524. }
  525. }
  526. .more-gun {
  527. width: 750rpx;
  528. max-height: 985rpx;
  529. background: #F8F8F8;
  530. border-radius: 42rpx 42rpx 0px 0px;
  531. .title {
  532. height: 80rpx;
  533. text-align: center;
  534. position: relative;
  535. text {
  536. width: 160rpx;
  537. font-size: 32rpx;
  538. font-weight: 600;
  539. color: #111111;
  540. line-height: 70rpx;
  541. }
  542. .icon {
  543. width: 45rpx;
  544. height: 45rpx;
  545. background-color: red;
  546. background: url(../../static/icon/6_d05_close.2x.png) no-repeat 0px 0px;
  547. background-size: 100% 100%;
  548. position: absolute;
  549. top: 10rpx;
  550. right: 40rpx;
  551. }
  552. }
  553. .gun-list {
  554. margin-top: 20rpx;
  555. scroll-view {
  556. padding: 0 30rpx;
  557. max-height: 850rpx;
  558. view {
  559. width: 200rpx;
  560. height: 110rpx;
  561. background: rgba(255, 255, 255, 0.08);
  562. box-shadow: 0px 2rpx 9rpx 4rpx rgba(16, 178, 125, 0.1);
  563. border-radius: 12rpx;
  564. display: inline-flex;
  565. flex-direction: column;
  566. justify-content: center;
  567. text-align: center;
  568. margin: 5rpx 15rpx 40rpx 15rpx;
  569. text {
  570. font-size: 28rpx;
  571. font-weight: 500;
  572. color: #666666;
  573. line-height: 40rpx;
  574. }
  575. text:nth-child(1) {
  576. margin-top: 10rpx;
  577. color: #7c7c7c;
  578. font-size: 20rpx;
  579. line-height: 40rpx;
  580. }
  581. text:nth-child(2) {
  582. font-size: 25rpx;
  583. line-height: 60rpx;
  584. font-weight: 500;
  585. }
  586. text.more {
  587. font-size: 28rpx;
  588. font-weight: 500;
  589. color: #000;
  590. line-height: 100rpx;
  591. margin-top: 0;
  592. }
  593. }
  594. .selected {
  595. background-color: #0ea374;
  596. text {
  597. color: #fff;
  598. }
  599. color: #fff;
  600. }
  601. }
  602. }
  603. }
  604. }
  605. </style>