getOrder.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <template>
  2. <view class="order-content">
  3. <view class="step">
  4. <uni-steps :options="[{title: '停车'}, {title: '检查'}, {title: '下单'}]" :active="stepIndex" active-color="rgb(255,0,0)"></uni-steps>
  5. </view>
  6. <view class="step-content">
  7. <!-- 停车 -->
  8. <view v-if="stepIndex===0" class="step-item step-one">
  9. <text>请确认车辆是否停到指定位置</text>
  10. <image src="/static/img/step-one.png" mode="aspectFit"></image>
  11. </view>
  12. <!-- 检查 -->
  13. <view v-if="stepIndex===1" class="step-item step-two">
  14. <view class="item top">
  15. <text class="item-text">-请完成以下操作-</text>
  16. <image src="/static/img/cztis.png" mode="aspectFit"></image>
  17. <view class="care">
  18. 注意:洗车过程中禁止移动车辆和上下车
  19. </view>
  20. </view>
  21. <view class="item bottom" @click="lookMore">
  22. <view class="item-text">
  23. <text>超高加装件不能清洗</text>
  24. <view class="right">
  25. <text>查看更多</text>
  26. <u-icon name="arrow-right" size="28"></u-icon>
  27. </view>
  28. </view>
  29. <image src="/static/img/zyts.png" ></image>
  30. </view>
  31. </view>
  32. <!-- 下单 -->
  33. <view v-if="stepIndex===2" class="step-item step-three">
  34. <view class="choose">
  35. <view class="title">
  36. 请选择服务模式
  37. </view>
  38. <view class="list">
  39. <view :class="['item', serverIndex==index ?'avtive':'']" @click="chooseItem(index)" v-for="(item,index) in itemList"
  40. :key="index">
  41. <text>{{item.itemName}}</text>
  42. <text class="price">¥{{item.currentPrice}}</text>
  43. </view>
  44. <u-empty text="暂无服务项目" img-width="120" v-if="itemList.length==0 && status!='loading'" mode="list"></u-empty>
  45. </view>
  46. </view>
  47. <view class="choose-content">
  48. <view class="choose-item">
  49. <view class="item" @click="intoChooseCoupon">
  50. <text>优惠卷</text>
  51. <view v-if="couponList.length" class="right">
  52. <u-icon name="gift" color="rgb(255,0,0)" size="32"></u-icon>
  53. <text class="coopon">{{checkedCoupon?(checkedCoupon.couponTitle+'(¥-'+checkedCoupon.couponAmount+')'):''}}</text>
  54. <u-icon name="arrow-right" color="rgb(255,0,0)" size="32"></u-icon>
  55. </view>
  56. <view v-else class="right">
  57. <text>暂无可用优惠券</text>
  58. </view>
  59. </view>
  60. <view class="item phone">
  61. <text>手机号码</text>
  62. <view class="right">
  63. <text>{{userPhone}}</text>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="read" @click="intoAgreement">
  68. <u-radio-group v-model="isRead">
  69. <u-radio shape="square" :disabled="isRead!='read'" name="read" active-color="red" icon-size="28" label-size="28">
  70. 点击阅读并同意
  71. <text>无人洗车</text>
  72. <text>《注意事项及服务协议》</text>
  73. </u-radio>
  74. </u-radio-group>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="step-footer">
  80. <button class="next-button" @click="nextStep" v-if="stepIndex!=2" type="warn">下一步</button>
  81. <view v-else class="pay">
  82. <text>合计:</text>
  83. <text class="amount">¥{{finalAmount}}</text>
  84. <view class="">
  85. <button @click="handleSubmit" type="warn">去付款</button>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import {couponEnable} from '@/api/coupon.js'
  93. import uniSteps from '@/components/uni-steps/uni-steps.vue'
  94. import {
  95. getUserInfo
  96. } from '@/api/login.js'
  97. import {
  98. getStoreItems,
  99. saveOrder,
  100. signPay
  101. } from '@/api/order.js'
  102. import {
  103. getStoreStatus
  104. } from '@/api/store.js'
  105. export default {
  106. components: {
  107. uniSteps
  108. },
  109. data() {
  110. return {
  111. status: 'loadmore',
  112. userPhone: '',
  113. stepIndex: 0, // 当前步奏下标
  114. serverIndex: 0, // 选择服务下标
  115. itemList: [], // 服务类型
  116. isRead: '', // 是否同意协议
  117. couponList: [], // 用户可用优惠券
  118. checkedCoupon: null, // 用户当前所选优惠券
  119. amount: 0, // 所选服务项目总金额
  120. couponAmount: 0, // 优惠券优惠金额
  121. finalAmount: 0, // 用户最终所需支付金额
  122. }
  123. },
  124. onLoad(options) {
  125. // 存储当前扫码的设备及网点id
  126. if (options.scene) {
  127. let scene = decodeURIComponent(options.scene);
  128. //&是我们定义的参数链接方式
  129. let storeId = scene.split(",")[0];
  130. let bizId = scene.split(',')[1];
  131. //其他逻辑处理。。。。。
  132. this.$u.vuex('vuex_bizId',bizId)
  133. this.$u.vuex('vuex_storeId',storeId)
  134. // 判断当前门店是否已运营
  135. this.getStoreStatus(storeId,bizId)
  136. } else {
  137. // 判断是否扫码过
  138. if (this.$store.state.vuex_bizId != '') {
  139. this.dataInit()
  140. } else {
  141. // 返回首页
  142. uni.reLaunch({
  143. url: "/pages/index/index"
  144. })
  145. }
  146. }
  147. },
  148. onUnload() {
  149. uni.removeStorageSync('stepIndex')
  150. uni.$off('couponChoose', this.couponChoose)
  151. },
  152. onShow() {
  153. const index = uni.getStorageSync('stepIndex')
  154. this.stepIndex = index ? index : 0
  155. console.log(this.stepIndex)
  156. },
  157. methods: {
  158. // 查询基础数据
  159. dataInit(){
  160. // 监听点击已阅读事件
  161. uni.$once('read', this.read)
  162. // 监听用户选择的优惠券
  163. uni.$on('couponChoose', this.couponChoose)
  164. // 获取用户信息
  165. this.getUserPhone()
  166. // 获取服务项目
  167. this.getServerList()
  168. },
  169. // 获取网点营业状态
  170. getStoreStatus(storeId, bizId) {
  171. uni.showLoading({
  172. title: '加载中...',
  173. mask: true
  174. })
  175. getStoreStatus({
  176. storeId: storeId,
  177. deviceNo: bizId
  178. }).then(res => {
  179. uni.hideLoading()
  180. console.log(res)
  181. if(res.status != 200 && res.status != 401) {
  182. uni.showModal({
  183. title: '提示',
  184. content: res.message,
  185. showCancel: false,
  186. success: function (res) {
  187. if (res.confirm) {
  188. uni.reLaunch({
  189. url:'/pages/index/index'
  190. })
  191. }
  192. }
  193. });
  194. }else{
  195. this.dataInit()
  196. }
  197. })
  198. },
  199. // 获取用户信息
  200. getUserPhone() {
  201. getUserInfo().then(res => {
  202. console.log(res, 'rrrrrrr')
  203. if (res.status == 200) {
  204. this.userPhone = res.data.mobile
  205. } else {
  206. }
  207. })
  208. },
  209. // 查看更多注意事项
  210. lookMore() {
  211. uni.navigateTo({
  212. url: '/pages/careMore/careMore'
  213. })
  214. },
  215. // 获取服务列表
  216. getServerList() {
  217. this.status = 'loading'
  218. let storeId = this.$store.state.vuex_storeId
  219. getStoreItems({
  220. storeId: storeId
  221. }).then(res => {
  222. this.status = 'loadmore'
  223. if (res.status == 200) {
  224. this.itemList = res.data
  225. this.serverIndex = 0
  226. // 获取用户可用优惠券
  227. this.getCouponList()
  228. } else {
  229. this.itemList = []
  230. }
  231. })
  232. },
  233. // 选择服务项目
  234. chooseItem(index) {
  235. this.serverIndex = index
  236. // 获取用户可用优惠券
  237. this.getCouponList()
  238. },
  239. // 下一步
  240. nextStep() {
  241. this.stepIndex = this.stepIndex === 0 ? 1 : 2
  242. uni.setStorageSync('stepIndex', this.stepIndex)
  243. },
  244. // 已阅读
  245. read(e) {
  246. this.isRead = e.msg
  247. },
  248. // 获取用户选择的优惠券
  249. couponChoose (e) {
  250. this.checkedCoupon = e.curCoupon
  251. // 计算合计
  252. this.getFinalAmount()
  253. },
  254. // 获取用户可用优惠券
  255. getCouponList() {
  256. let item = this.itemList[this.serverIndex]
  257. let params = {
  258. consumAmount: item.currentPrice, //服务金额
  259. itemId: item.itemId // 服务id
  260. }
  261. uni.showLoading({
  262. title: '正在查询可用优惠券...',
  263. mask: true
  264. })
  265. couponEnable(params).then(res=> {
  266. uni.hideLoading()
  267. if (res.status == 200) {
  268. this.couponList = res.data
  269. this.checkedCoupon = this.couponList[0]
  270. // 计算合计
  271. this.getFinalAmount()
  272. } else {
  273. this.couponList = []
  274. this.checkedCoupon = null
  275. }
  276. })
  277. },
  278. // 计算合计
  279. getFinalAmount() {
  280. this.amount = this.itemList[this.serverIndex].currentPrice
  281. this.couponAmount = (this.checkedCoupon && this.checkedCoupon.couponAmount > this.amount) ? this.amount : (this.checkedCoupon ?this.checkedCoupon.couponAmount : 0)
  282. let ret = this.amount - this.couponAmount
  283. this.finalAmount = ret.toFixed(2)
  284. },
  285. // 选择优惠券
  286. intoChooseCoupon() {
  287. this.couponList.map((item)=> {
  288. item.checked = (this.checkedCoupon && item.id == this.checkedCoupon.id) ? true : false
  289. })
  290. uni.navigateTo({
  291. url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}&curCoupon=${encodeURIComponent(JSON.stringify(this.checkedCoupon))}`
  292. })
  293. },
  294. // 打开服务协议
  295. intoAgreement() {
  296. uni.navigateTo({
  297. url: '/pages/agreement/agreement'
  298. })
  299. },
  300. // 去付款 保存订单
  301. handleSubmit() {
  302. if (this.itemList.length == 0) {
  303. this.toashMsg('请先选择服务')
  304. return
  305. }
  306. if (this.isRead != 'read') {
  307. this.toashMsg('请先阅读并同意无人洗车《注意事项及服务协议》!')
  308. return
  309. }
  310. uni.showLoading({
  311. title: '请求中...',
  312. mask: true
  313. })
  314. let item = this.itemList[this.serverIndex]
  315. let storeId = this.$store.state.vuex_storeId
  316. let deviceNo = this.$store.state.vuex_bizId
  317. let params = {
  318. "itemId": item.itemId, // 服务id
  319. "itemCode": item.itemCode,
  320. "storeId": storeId, // 门店id
  321. "deviceNo": deviceNo, // 设备编号
  322. "orderTime": this.$u.timeFormat(Date.now(), 'yyyy-mm-dd hh:MM:ss'),
  323. "payableAmount": this.amount, // 应付金额 即优惠前金额
  324. "paymentAmount": this.finalAmount, // 实收金额 即优惠后金额
  325. "couponAmount": this.couponAmount, // 优惠金额
  326. }
  327. if (this.checkedCoupon) {
  328. params.couponReceivesList = [{couponId:this.checkedCoupon.id}]
  329. }
  330. saveOrder(params).then(res => {
  331. uni.hideLoading()
  332. if (res.status == 200) {
  333. let data = res.data
  334. // 保存成功后 请求预支付返回吊起微信支付所需参数
  335. this.getPayData(data)
  336. this.$u.vuex('vuex_itemCode',data.itemCode)
  337. this.$u.vuex('vuex_orderNo',data.orderNo)
  338. } else {
  339. this.toashMsg(res.message)
  340. setTimeout(()=>{
  341. // 刷新服务项
  342. this.getServerList()
  343. },2000)
  344. }
  345. })
  346. },
  347. // 预支付 返回微信支付所需参数
  348. getPayData(orderData) {
  349. let _this = this
  350. signPay({
  351. orderId: orderData.id
  352. }).then(res => {
  353. console.log(res, '预支付')
  354. uni.hideLoading()
  355. if (res.status == 200) {
  356. let data = res.data
  357. // 0元订单直接支付成功,不用吊微信支付
  358. if (data.tradeStatus && data.tradeStatus == "PAID") {
  359. this.paySuccess()
  360. } else {
  361. uni.requestPayment({
  362. provider: 'wxpay',
  363. timeStamp: data.timeStamp,
  364. nonceStr: data.nonceStr,
  365. package: data.package,
  366. signType: data.signType,
  367. paySign: data.paySign,
  368. success: function(res) {
  369. console.log('success:' + JSON.stringify(res));
  370. _this.paySuccess()
  371. },
  372. fail: function(err) {
  373. console.log('fail:' + JSON.stringify(err));
  374. _this.payFail(err)
  375. }
  376. });
  377. }
  378. } else {
  379. this.toashMsg(res.message)
  380. }
  381. })
  382. },
  383. // 付款成功后
  384. paySuccess(){
  385. this.$u.vuex('vuex_orderStatus','PAID')
  386. this.$u.vuex('vuex_orderDjs',0)
  387. this.$u.vuex('vuex_workStep',0)
  388. this.$u.vuex('vuex_workStatus','linking')
  389. // 付款成功后开始洗车
  390. uni.redirectTo({
  391. url: `/pages/work/index/index`
  392. })
  393. },
  394. // 付款失败或取消
  395. payFail(err){
  396. this.$u.vuex('vuex_orderStatus','FAIL')
  397. let content = '支付失败,请重试'
  398. if(err.errMsg.indexOf("cancel")>=0){
  399. content = '支付取消'
  400. }
  401. this.toashMsg(content)
  402. }
  403. }
  404. }
  405. </script>
  406. <style lang="scss">
  407. page {
  408. height: 100%;
  409. }
  410. .order-content {
  411. width: 100%;
  412. height: 100%;
  413. display: flex;
  414. flex-direction: column;
  415. .step {
  416. padding: 40rpx 0;
  417. }
  418. .step-content {
  419. flex: 1;
  420. width: 100%;
  421. display: flex;
  422. flex-direction: column;
  423. .step-item {
  424. width: 100%;
  425. display: flex;
  426. flex-direction: column;
  427. align-items: center;
  428. flex: 1;
  429. }
  430. // 第一步
  431. .step-one {
  432. text {
  433. color: #999;
  434. margin: 40rpx 0;
  435. }
  436. }
  437. // 第二步
  438. .step-two {
  439. background-color: #F8F8F8;
  440. justify-content: space-around;
  441. .item {
  442. background-color: #fff;
  443. width: 92%;
  444. height: 45%;
  445. display: flex;
  446. flex-direction: column;
  447. align-items: center;
  448. image {
  449. width: 80%;
  450. flex: 1;
  451. }
  452. }
  453. .top {
  454. text {
  455. color: #df928e;
  456. font-size: 24rpx;
  457. }
  458. .item-text {
  459. padding-top: 20rpx;
  460. }
  461. .care {
  462. padding: 10rpx 20rpx;
  463. background-color: #ff805b;
  464. border-radius: 30rpx;
  465. color: #fff;
  466. font-size: 24rpx;
  467. margin-bottom: 20rpx;
  468. }
  469. }
  470. .bottom {
  471. text {
  472. font-size: 24rpx;
  473. color: #333;
  474. }
  475. .item-text {
  476. width: 100%;
  477. padding: 0 40rpx;
  478. display: flex;
  479. justify-content: space-between;
  480. padding-top: 20rpx;
  481. }
  482. image {
  483. margin-top: 20rpx;
  484. }
  485. }
  486. }
  487. // 第三步 下单
  488. .step-three {
  489. .choose {
  490. width: 100%;
  491. height: auto;
  492. padding-bottom: 60rpx;
  493. display: flex;
  494. flex-direction: column;
  495. align-items: center;
  496. border-bottom: 1px solid #eee;
  497. .title {
  498. color: #666;
  499. }
  500. .list {
  501. width: 100%;
  502. display: flex;
  503. justify-content: space-around;
  504. padding: 0 20rpx;
  505. .item {
  506. width: 30%;
  507. height: 140rpx;
  508. display: flex;
  509. flex-direction: column;
  510. align-items: center;
  511. justify-content: center;
  512. border: 1px solid #eee;
  513. border-radius: 15rpx;
  514. margin-top: 30rpx;
  515. color: #999;
  516. .price {
  517. font-size: 34rpx;
  518. margin-top: 10rpx;
  519. }
  520. }
  521. .avtive {
  522. color: #333;
  523. border-color: rgb(255, 0, 0);
  524. .price {
  525. color: rgb(255, 0, 0);
  526. }
  527. }
  528. }
  529. }
  530. .choose-content {
  531. flex: 1;
  532. width: 100%;
  533. .choose-item {
  534. width: 100%;
  535. .item {
  536. padding: 0 30rpx;
  537. }
  538. }
  539. .item {
  540. width: 100%;
  541. height: 100rpx;
  542. display: flex;
  543. align-items: center;
  544. justify-content: space-between;
  545. border-bottom: 1px solid #eee;
  546. .coopon {
  547. color: rgb(255, 0, 0);
  548. }
  549. }
  550. .phone {
  551. border-bottom: none;
  552. }
  553. .read {
  554. width: 100%;
  555. border-top: 1px solid #eee;
  556. padding-top: 40rpx;
  557. display: flex;
  558. justify-content: center;
  559. text {
  560. color: #999;
  561. }
  562. text:last-child {
  563. color: #ff9ba5;
  564. }
  565. }
  566. }
  567. }
  568. }
  569. .step-footer {
  570. width: 100%;
  571. background-color: #fff;
  572. .next-button {
  573. margin: 0;
  574. border-radius: 0;
  575. padding: 10rpx 0;
  576. }
  577. .pay {
  578. width: 100%;
  579. height: 100%;
  580. padding: 10rpx;
  581. border-top: 1px solid #eee;
  582. display: flex;
  583. align-items: center;
  584. justify-content: flex-end;
  585. .amount {
  586. color: rgb(255, 0, 0);
  587. font-size: 36rpx;
  588. margin-right: 40rpx;
  589. }
  590. button {
  591. width: 200rpx;
  592. }
  593. }
  594. }
  595. }
  596. </style>