getOrder.vue 16 KB

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