getOrder.vue 16 KB

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