getOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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="checkedCoupon" class="right">
  52. <u-icon name="gift" color="rgb(255,0,0)" size="32"></u-icon>
  53. <text class="coopon">9.8元洗车券(¥-9.8)</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 uniSteps from '@/components/uni-steps/uni-steps.vue'
  93. import {
  94. getUserInfo
  95. } from '@/api/login.js'
  96. import {
  97. getStoreItems,
  98. saveOrder,
  99. signPay
  100. } from '@/api/order.js'
  101. import {
  102. getStoreStatus
  103. } from '@/api/store.js'
  104. export default {
  105. components: {
  106. uniSteps
  107. },
  108. data() {
  109. return {
  110. status: 'loadmore',
  111. userPhone: '',
  112. stepIndex: 0, // 当前步奏下标
  113. serverIndex: 0, // 选择服务下标
  114. itemList: [], // 服务类型
  115. isRead: '', // 是否同意协议
  116. couponList: [{
  117. id: 23432445,
  118. name: "满100减50",
  119. price: 100,
  120. yxTime: "2020-05-16",
  121. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  122. checked: false
  123. },
  124. {
  125. id: 3544355,
  126. name: "满100减50",
  127. price: 100,
  128. yxTime: "2020-05-16",
  129. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  130. checked: false
  131. },
  132. {
  133. id: 234234234,
  134. name: "满100减50",
  135. price: 100,
  136. yxTime: "2020-05-16",
  137. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  138. checked: false
  139. },
  140. {
  141. id: 66264646,
  142. name: "满100减50",
  143. price: 100,
  144. yxTime: "2020-05-16",
  145. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  146. checked: false
  147. },
  148. {
  149. id: 9794694698,
  150. name: "满100减50",
  151. price: 100,
  152. yxTime: "2020-05-16",
  153. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  154. checked: false
  155. }
  156. ], // 用户可用优惠券
  157. checkedCoupon: null, // 用户当前所选优惠券
  158. amount: 0, // 所选服务项目总金额
  159. couponAmount: 0, // 优惠券优惠金额
  160. finalAmount: 0, // 用户最终所需支付金额
  161. }
  162. },
  163. onLoad(options) {
  164. // 存储当前扫码的设备及网点id
  165. if (options.scene) {
  166. let scene = decodeURIComponent(options.scene);
  167. //&是我们定义的参数链接方式
  168. let storeId = scene.split(",")[0];
  169. let bizId = scene.split(',')[1];
  170. //其他逻辑处理。。。。。
  171. this.$store.state.vuex_orderInfo.bizId = bizId
  172. this.$store.state.vuex_orderInfo.storeId = storeId
  173. // 判断当前门店是否已运营
  174. // this.getStoreStatus(storeId,bizId)
  175. this.dataInit()
  176. } else {
  177. // 判断是否扫码过
  178. if (this.$store.state.vuex_orderInfo.bizId != '') {
  179. this.dataInit()
  180. } else {
  181. // 返回首页
  182. uni.reLaunch({
  183. url: "/pages/index/index"
  184. })
  185. }
  186. }
  187. },
  188. onUnload() {
  189. uni.removeStorageSync('stepIndex')
  190. },
  191. onShow() {
  192. const index = uni.getStorageSync('stepIndex')
  193. this.stepIndex = index ? index : 0
  194. console.log(this.stepIndex)
  195. },
  196. methods: {
  197. // 查询基础数据
  198. dataInit(){
  199. // 监听点击已阅读事件
  200. uni.$once('read', this.read)
  201. // 获取用户信息
  202. this.getUserPhone()
  203. // 获取服务项目
  204. this.getServerList()
  205. },
  206. // 获取网点营业状态
  207. getStoreStatus(storeId, bizId) {
  208. uni.showLoading({
  209. title: '加载中...',
  210. mask: true
  211. })
  212. getStoreStatus({
  213. storeId: storeId,
  214. deviceNo: bizId
  215. }).then(res => {
  216. uni.hideLoading()
  217. console.log(res)
  218. if(res.status != 200 && res.status != 401) {
  219. uni.showModal({
  220. title: '提示',
  221. content: res.message,
  222. showCancel: false,
  223. success: function (res) {
  224. if (res.confirm) {
  225. uni.reLaunch({
  226. url:'/pages/index/index'
  227. })
  228. }
  229. }
  230. });
  231. }else{
  232. this.dataInit()
  233. }
  234. })
  235. },
  236. // 获取用户信息
  237. getUserPhone() {
  238. getUserInfo().then(res => {
  239. console.log(res, 'rrrrrrr')
  240. if (res.status == 200) {
  241. this.userPhone = res.data.mobile
  242. } else {
  243. }
  244. })
  245. },
  246. // 查看更多注意事项
  247. lookMore() {
  248. uni.navigateTo({
  249. url: '/pages/careMore/careMore'
  250. })
  251. },
  252. // 获取服务列表
  253. getServerList() {
  254. this.status = 'loading'
  255. let storeId = this.$store.state.vuex_orderInfo.storeId
  256. getStoreItems({
  257. storeId: storeId
  258. }).then(res => {
  259. this.status = 'loadmore'
  260. if (res.status == 200) {
  261. this.itemList = res.data
  262. this.serverIndex = 0
  263. this.getFinalAmount()
  264. } else {
  265. this.itemList = []
  266. }
  267. })
  268. },
  269. // 选择服务项目
  270. chooseItem(index) {
  271. this.serverIndex = index
  272. this.getFinalAmount()
  273. },
  274. // 下一步
  275. nextStep() {
  276. this.stepIndex = this.stepIndex === 0 ? 1 : 2
  277. uni.setStorageSync('stepIndex', this.stepIndex)
  278. },
  279. // 已阅读
  280. read(e) {
  281. this.isRead = e.msg
  282. },
  283. // 获取用户可用优惠券
  284. getCouponList() {
  285. },
  286. // 格式化优惠券数据 获取优惠金额最大的优惠券 couponType 优惠券类型:FULLSUB满减/DISCOUNT折扣券/VOUCHER代金券
  287. formatCouponData() {
  288. let arr = []
  289. let _this = this
  290. this.couponList.map(item => {
  291. let data = {}
  292. data.id = item.couponReceivesId
  293. if (item.couponType == 'DISCOUNT') {
  294. console.log(_this.amount, '_this.amount')
  295. data.subAmount = Number((_this.amount * (1 - item.subAmount)).toFixed(2))
  296. } else {
  297. data.subAmount = item.couponType == 'FULLSUB' ? item.subAmount : item.price
  298. }
  299. arr.push(data)
  300. })
  301. console.log(arr, 'arr')
  302. // 比较数据中优惠金额最大的值 并返回该对象
  303. let obj = arr.reduce((p, v) => p.subAmount < v.subAmount ? v : p)
  304. console.log(obj)
  305. let p = this.couponList.find(item => item.couponReceivesId == obj.id)
  306. // 订单金额为0时,默认不使用优惠卷
  307. if (this.amount != 0) {
  308. this.checkedCoupon = p
  309. this.couponAmount = obj.subAmount > this.amount ? this.amount : obj.subAmount
  310. } else {
  311. this.checkedCoupon = null
  312. this.couponAmount = 0
  313. }
  314. // 计算合计
  315. this.getFinalAmount()
  316. },
  317. // 计算合计
  318. getFinalAmount() {
  319. this.amount = this.itemList[this.serverIndex].currentPrice
  320. let ret = this.amount - this.couponAmount
  321. this.finalAmount = ret.toFixed(2)
  322. },
  323. // 选择优惠券
  324. intoChooseCoupon() {
  325. uni.navigateTo({
  326. url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}`
  327. })
  328. },
  329. // 打开服务协议
  330. intoAgreement() {
  331. uni.navigateTo({
  332. url: '/pages/agreement/agreement'
  333. })
  334. },
  335. // 去付款 保存订单
  336. handleSubmit() {
  337. if (this.itemList.length == 0) {
  338. this.toashMsg('请先选择服务')
  339. return
  340. }
  341. if (this.isRead != 'read') {
  342. this.toashMsg('请先阅读并同意无人洗车《注意事项及服务协议》!')
  343. return
  344. } else if (this.itemList.length == 0) {
  345. this.toashMsg('暂无服务项目')
  346. return
  347. }
  348. uni.showLoading({
  349. title: '请求中...',
  350. mask: true
  351. })
  352. let item = this.itemList[this.serverIndex]
  353. let storeId = this.$store.state.vuex_orderInfo.storeId
  354. let deviceNo = this.$store.state.vuex_orderInfo.bizId
  355. let params = {
  356. "itemId": item.itemId, // 服务id
  357. "itemCode": item.itemCode,
  358. "storeId": storeId, // 门店id
  359. "deviceNo": deviceNo, // 设备编号
  360. "orderTime": this.$u.timeFormat(Date.now(), 'yyyy-mm-dd hh:MM:ss'),
  361. "payableAmount": this.amount, // 应付金额 即优惠前金额
  362. "paymentAmount": this.finalAmount // 实收金额 即优惠后金额
  363. }
  364. saveOrder(params).then(res => {
  365. if (res.status == 200) {
  366. let data = res.data
  367. // 保存成功后 请求预支付返回吊起微信支付所需参数
  368. this.getPayData(data)
  369. this.$store.state.vuex_orderInfo.itemCode = data.itemCode
  370. this.$store.state.vuex_orderInfo.orderNo = data.orderNo
  371. this.$store.state.vuex_orderInfo.duration = item.duration
  372. } else {
  373. uni.hideLoading()
  374. // 刷新服务项
  375. this.getServerList()
  376. this.toashMsg(res.message)
  377. }
  378. })
  379. },
  380. // 预支付 返回微信支付所需参数
  381. getPayData(orderData) {
  382. signPay({
  383. orderId: orderData.id
  384. }).then(res => {
  385. console.log(res, '预支付')
  386. uni.hideLoading()
  387. if (res.status == 200) {
  388. let data = res.data
  389. // 0元订单直接支付成功,不用吊微信支付
  390. if (data.tradeStatus && data.tradeStatus == "PAID") {
  391. this.paySuccess()
  392. } else {
  393. uni.requestPayment({
  394. provider: 'wxpay',
  395. timeStamp: data.timeStamp,
  396. nonceStr: data.nonceStr,
  397. package: data.package,
  398. signType: data.signType,
  399. paySign: data.paySign,
  400. success: function(res) {
  401. console.log('success:' + JSON.stringify(res));
  402. this.paySuccess()
  403. },
  404. fail: function(err) {
  405. console.log('fail:' + JSON.stringify(err));
  406. this.payFail(err)
  407. }
  408. });
  409. }
  410. } else {
  411. this.toashMsg(res.message)
  412. }
  413. })
  414. },
  415. // 付款成功后
  416. paySuccess(){
  417. this.$store.state.vuex_orderInfo.orderStatus = 'PAID'
  418. // 付款成功后开始洗车
  419. uni.redirectTo({
  420. url: `/pages/work/index/index`
  421. })
  422. },
  423. // 付款失败或取消
  424. payFail(err){
  425. this.$store.state.vuex_orderInfo.orderStatus = 'FAIL'
  426. let content = '支付失败,请重新下单'
  427. if(err.errMsg.indexOf("cancel")>=0){
  428. content = '支付取消,请重新下单'
  429. }
  430. uni.showModal({
  431. title: '提示',
  432. content: content,
  433. showCancel: false,
  434. success: function (res) {
  435. if (res.confirm) {
  436. uni.navigateBack()
  437. }
  438. }
  439. });
  440. }
  441. }
  442. }
  443. </script>
  444. <style lang="scss">
  445. page {
  446. height: 100%;
  447. }
  448. .order-content {
  449. width: 100%;
  450. height: 100%;
  451. display: flex;
  452. flex-direction: column;
  453. .step {
  454. padding: 40rpx 0;
  455. }
  456. .step-content {
  457. flex: 1;
  458. width: 100%;
  459. display: flex;
  460. flex-direction: column;
  461. .step-item {
  462. width: 100%;
  463. display: flex;
  464. flex-direction: column;
  465. align-items: center;
  466. flex: 1;
  467. }
  468. // 第一步
  469. .step-one {
  470. text {
  471. color: #999;
  472. margin: 40rpx 0;
  473. }
  474. }
  475. // 第二步
  476. .step-two {
  477. background-color: #F8F8F8;
  478. justify-content: space-around;
  479. .item {
  480. background-color: #fff;
  481. width: 92%;
  482. height: 45%;
  483. display: flex;
  484. flex-direction: column;
  485. align-items: center;
  486. image {
  487. width: 80%;
  488. flex: 1;
  489. }
  490. }
  491. .top {
  492. text {
  493. color: #df928e;
  494. font-size: 24rpx;
  495. }
  496. .item-text {
  497. padding-top: 20rpx;
  498. }
  499. .care {
  500. padding: 10rpx 20rpx;
  501. background-color: #ff805b;
  502. border-radius: 30rpx;
  503. color: #fff;
  504. font-size: 24rpx;
  505. margin-bottom: 20rpx;
  506. }
  507. }
  508. .bottom {
  509. text {
  510. font-size: 24rpx;
  511. color: #333;
  512. }
  513. .item-text {
  514. width: 100%;
  515. padding: 0 40rpx;
  516. display: flex;
  517. justify-content: space-between;
  518. padding-top: 20rpx;
  519. }
  520. image {
  521. margin-top: 20rpx;
  522. }
  523. }
  524. }
  525. // 第三步 下单
  526. .step-three {
  527. .choose {
  528. width: 100%;
  529. height: auto;
  530. padding-bottom: 60rpx;
  531. display: flex;
  532. flex-direction: column;
  533. align-items: center;
  534. border-bottom: 1px solid #eee;
  535. .title {
  536. color: #666;
  537. }
  538. .list {
  539. width: 100%;
  540. display: flex;
  541. justify-content: space-around;
  542. padding: 0 20rpx;
  543. .item {
  544. width: 30%;
  545. height: 140rpx;
  546. display: flex;
  547. flex-direction: column;
  548. align-items: center;
  549. justify-content: center;
  550. border: 1px solid #eee;
  551. border-radius: 15rpx;
  552. margin-top: 30rpx;
  553. color: #999;
  554. .price {
  555. font-size: 34rpx;
  556. margin-top: 10rpx;
  557. }
  558. }
  559. .avtive {
  560. color: #333;
  561. border-color: rgb(255, 0, 0);
  562. .price {
  563. color: rgb(255, 0, 0);
  564. }
  565. }
  566. }
  567. }
  568. .choose-content {
  569. flex: 1;
  570. width: 100%;
  571. .choose-item {
  572. width: 100%;
  573. .item {
  574. padding: 0 30rpx;
  575. }
  576. }
  577. .item {
  578. width: 100%;
  579. height: 100rpx;
  580. display: flex;
  581. align-items: center;
  582. justify-content: space-between;
  583. border-bottom: 1px solid #eee;
  584. .coopon {
  585. color: rgb(255, 0, 0);
  586. }
  587. }
  588. .phone {
  589. border-bottom: none;
  590. }
  591. .read {
  592. width: 100%;
  593. border-top: 1px solid #eee;
  594. padding-top: 40rpx;
  595. display: flex;
  596. justify-content: center;
  597. text {
  598. color: #999;
  599. }
  600. text:last-child {
  601. color: #ff9ba5;
  602. }
  603. }
  604. }
  605. }
  606. }
  607. .step-footer {
  608. width: 100%;
  609. background-color: #fff;
  610. .next-button {
  611. margin: 0;
  612. border-radius: 0;
  613. padding: 10rpx 0;
  614. }
  615. .pay {
  616. width: 100%;
  617. height: 100%;
  618. padding: 10rpx;
  619. border-top: 1px solid #eee;
  620. display: flex;
  621. align-items: center;
  622. justify-content: flex-end;
  623. .amount {
  624. color: rgb(255, 0, 0);
  625. font-size: 36rpx;
  626. margin-right: 40rpx;
  627. }
  628. button {
  629. width: 200rpx;
  630. }
  631. }
  632. }
  633. }
  634. </style>