getOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. this.$store.state.vuex_orderDjs = 0
  435. this.$store.state.vuex_workStep = 0
  436. // 付款成功后开始洗车
  437. uni.redirectTo({
  438. url: `/pages/work/index/index`
  439. })
  440. },
  441. // 付款失败或取消
  442. payFail(err){
  443. this.$store.state.vuex_orderInfo.orderStatus = 'FAIL'
  444. let content = '支付失败,请重新下单'
  445. if(err.errMsg.indexOf("cancel")>=0){
  446. content = '支付取消,请重新下单'
  447. }
  448. uni.showModal({
  449. title: '提示',
  450. content: content,
  451. showCancel: false,
  452. success: function (res) {
  453. if (res.confirm) {
  454. uni.navigateBack()
  455. }
  456. }
  457. });
  458. }
  459. }
  460. }
  461. </script>
  462. <style lang="scss">
  463. page {
  464. height: 100%;
  465. }
  466. .order-content {
  467. width: 100%;
  468. height: 100%;
  469. display: flex;
  470. flex-direction: column;
  471. .step {
  472. padding: 40rpx 0;
  473. }
  474. .step-content {
  475. flex: 1;
  476. width: 100%;
  477. display: flex;
  478. flex-direction: column;
  479. .step-item {
  480. width: 100%;
  481. display: flex;
  482. flex-direction: column;
  483. align-items: center;
  484. flex: 1;
  485. }
  486. // 第一步
  487. .step-one {
  488. text {
  489. color: #999;
  490. margin: 40rpx 0;
  491. }
  492. }
  493. // 第二步
  494. .step-two {
  495. background-color: #F8F8F8;
  496. justify-content: space-around;
  497. .item {
  498. background-color: #fff;
  499. width: 92%;
  500. height: 45%;
  501. display: flex;
  502. flex-direction: column;
  503. align-items: center;
  504. image {
  505. width: 80%;
  506. flex: 1;
  507. }
  508. }
  509. .top {
  510. text {
  511. color: #df928e;
  512. font-size: 24rpx;
  513. }
  514. .item-text {
  515. padding-top: 20rpx;
  516. }
  517. .care {
  518. padding: 10rpx 20rpx;
  519. background-color: #ff805b;
  520. border-radius: 30rpx;
  521. color: #fff;
  522. font-size: 24rpx;
  523. margin-bottom: 20rpx;
  524. }
  525. }
  526. .bottom {
  527. text {
  528. font-size: 24rpx;
  529. color: #333;
  530. }
  531. .item-text {
  532. width: 100%;
  533. padding: 0 40rpx;
  534. display: flex;
  535. justify-content: space-between;
  536. padding-top: 20rpx;
  537. }
  538. image {
  539. margin-top: 20rpx;
  540. }
  541. }
  542. }
  543. // 第三步 下单
  544. .step-three {
  545. .choose {
  546. width: 100%;
  547. height: auto;
  548. padding-bottom: 60rpx;
  549. display: flex;
  550. flex-direction: column;
  551. align-items: center;
  552. border-bottom: 1px solid #eee;
  553. .title {
  554. color: #666;
  555. }
  556. .list {
  557. width: 100%;
  558. display: flex;
  559. justify-content: space-around;
  560. padding: 0 20rpx;
  561. .item {
  562. width: 30%;
  563. height: 140rpx;
  564. display: flex;
  565. flex-direction: column;
  566. align-items: center;
  567. justify-content: center;
  568. border: 1px solid #eee;
  569. border-radius: 15rpx;
  570. margin-top: 30rpx;
  571. color: #999;
  572. .price {
  573. font-size: 34rpx;
  574. margin-top: 10rpx;
  575. }
  576. }
  577. .avtive {
  578. color: #333;
  579. border-color: rgb(255, 0, 0);
  580. .price {
  581. color: rgb(255, 0, 0);
  582. }
  583. }
  584. }
  585. }
  586. .choose-content {
  587. flex: 1;
  588. width: 100%;
  589. .choose-item {
  590. width: 100%;
  591. .item {
  592. padding: 0 30rpx;
  593. }
  594. }
  595. .item {
  596. width: 100%;
  597. height: 100rpx;
  598. display: flex;
  599. align-items: center;
  600. justify-content: space-between;
  601. border-bottom: 1px solid #eee;
  602. .coopon {
  603. color: rgb(255, 0, 0);
  604. }
  605. }
  606. .phone {
  607. border-bottom: none;
  608. }
  609. .read {
  610. width: 100%;
  611. border-top: 1px solid #eee;
  612. padding-top: 40rpx;
  613. display: flex;
  614. justify-content: center;
  615. text {
  616. color: #999;
  617. }
  618. text:last-child {
  619. color: #ff9ba5;
  620. }
  621. }
  622. }
  623. }
  624. }
  625. .step-footer {
  626. width: 100%;
  627. background-color: #fff;
  628. .next-button {
  629. margin: 0;
  630. border-radius: 0;
  631. padding: 10rpx 0;
  632. }
  633. .pay {
  634. width: 100%;
  635. height: 100%;
  636. padding: 10rpx;
  637. border-top: 1px solid #eee;
  638. display: flex;
  639. align-items: center;
  640. justify-content: flex-end;
  641. .amount {
  642. color: rgb(255, 0, 0);
  643. font-size: 36rpx;
  644. margin-right: 40rpx;
  645. }
  646. button {
  647. width: 200rpx;
  648. }
  649. }
  650. }
  651. }
  652. </style>