getOrder.vue 16 KB

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