getOrder.vue 16 KB

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