getOrder.vue 16 KB

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