getOrder.vue 15 KB

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