getOrder.vue 15 KB

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