getOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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.$u.vuex('vuex_bizId',bizId)
  173. this.$u.vuex('vuex_storeId',storeId)
  174. // 判断当前门店是否已运营
  175. this.getStoreStatus(storeId,bizId)
  176. } else {
  177. // 判断是否扫码过
  178. if (this.$store.state.vuex_bizId != '') {
  179. this.dataInit()
  180. } else {
  181. // 返回首页
  182. uni.reLaunch({
  183. url: "/pages/index/index"
  184. })
  185. }
  186. }
  187. },
  188. onUnload() {
  189. uni.removeStorageSync('stepIndex')
  190. uni.$off('couponChoose', this.couponChoose)
  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_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_storeId
  359. let deviceNo = this.$store.state.vuex_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. "couponAmount": this.couponAmount, // 优惠金额
  369. }
  370. if (this.checkedCoupon) {
  371. params.couponReceivesList = [{couponId:this.checkedCoupon.id}]
  372. }
  373. saveOrder(params).then(res => {
  374. if (res.status == 200) {
  375. let data = res.data
  376. // 保存成功后 请求预支付返回吊起微信支付所需参数
  377. this.getPayData(data)
  378. this.$u.vuex('vuex_itemCode',data.itemCode)
  379. this.$u.vuex('vuex_orderNo',data.orderNo)
  380. } else {
  381. uni.hideLoading()
  382. // 刷新服务项
  383. this.getServerList()
  384. this.toashMsg(res.message)
  385. }
  386. })
  387. },
  388. // 预支付 返回微信支付所需参数
  389. getPayData(orderData) {
  390. signPay({
  391. orderId: orderData.id
  392. }).then(res => {
  393. console.log(res, '预支付')
  394. uni.hideLoading()
  395. if (res.status == 200) {
  396. let data = res.data
  397. // 0元订单直接支付成功,不用吊微信支付
  398. if (data.tradeStatus && data.tradeStatus == "PAID") {
  399. this.paySuccess()
  400. } else {
  401. uni.requestPayment({
  402. provider: 'wxpay',
  403. timeStamp: data.timeStamp,
  404. nonceStr: data.nonceStr,
  405. package: data.package,
  406. signType: data.signType,
  407. paySign: data.paySign,
  408. success: function(res) {
  409. console.log('success:' + JSON.stringify(res));
  410. this.paySuccess()
  411. },
  412. fail: function(err) {
  413. console.log('fail:' + JSON.stringify(err));
  414. this.payFail(err)
  415. }
  416. });
  417. }
  418. } else {
  419. this.toashMsg(res.message)
  420. }
  421. })
  422. },
  423. // 付款成功后
  424. paySuccess(){
  425. this.$u.vuex('vuex_orderStatus','PAID')
  426. this.$u.vuex('vuex_orderDjs',0)
  427. this.$u.vuex('vuex_workStep',0)
  428. this.$u.vuex('vuex_workStatus','linking')
  429. // 付款成功后开始洗车
  430. uni.redirectTo({
  431. url: `/pages/work/index/index`
  432. })
  433. },
  434. // 付款失败或取消
  435. payFail(err){
  436. this.$u.vuex('vuex_orderStatus','FAIL')
  437. let content = '支付失败,请重新下单'
  438. if(err.errMsg.indexOf("cancel")>=0){
  439. content = '支付取消,请重新下单'
  440. }
  441. uni.showModal({
  442. title: '提示',
  443. content: content,
  444. showCancel: false,
  445. success: function (res) {
  446. if (res.confirm) {
  447. uni.navigateBack()
  448. }
  449. }
  450. });
  451. }
  452. }
  453. }
  454. </script>
  455. <style lang="scss">
  456. page {
  457. height: 100%;
  458. }
  459. .order-content {
  460. width: 100%;
  461. height: 100%;
  462. display: flex;
  463. flex-direction: column;
  464. .step {
  465. padding: 40rpx 0;
  466. }
  467. .step-content {
  468. flex: 1;
  469. width: 100%;
  470. display: flex;
  471. flex-direction: column;
  472. .step-item {
  473. width: 100%;
  474. display: flex;
  475. flex-direction: column;
  476. align-items: center;
  477. flex: 1;
  478. }
  479. // 第一步
  480. .step-one {
  481. text {
  482. color: #999;
  483. margin: 40rpx 0;
  484. }
  485. }
  486. // 第二步
  487. .step-two {
  488. background-color: #F8F8F8;
  489. justify-content: space-around;
  490. .item {
  491. background-color: #fff;
  492. width: 92%;
  493. height: 45%;
  494. display: flex;
  495. flex-direction: column;
  496. align-items: center;
  497. image {
  498. width: 80%;
  499. flex: 1;
  500. }
  501. }
  502. .top {
  503. text {
  504. color: #df928e;
  505. font-size: 24rpx;
  506. }
  507. .item-text {
  508. padding-top: 20rpx;
  509. }
  510. .care {
  511. padding: 10rpx 20rpx;
  512. background-color: #ff805b;
  513. border-radius: 30rpx;
  514. color: #fff;
  515. font-size: 24rpx;
  516. margin-bottom: 20rpx;
  517. }
  518. }
  519. .bottom {
  520. text {
  521. font-size: 24rpx;
  522. color: #333;
  523. }
  524. .item-text {
  525. width: 100%;
  526. padding: 0 40rpx;
  527. display: flex;
  528. justify-content: space-between;
  529. padding-top: 20rpx;
  530. }
  531. image {
  532. margin-top: 20rpx;
  533. }
  534. }
  535. }
  536. // 第三步 下单
  537. .step-three {
  538. .choose {
  539. width: 100%;
  540. height: auto;
  541. padding-bottom: 60rpx;
  542. display: flex;
  543. flex-direction: column;
  544. align-items: center;
  545. border-bottom: 1px solid #eee;
  546. .title {
  547. color: #666;
  548. }
  549. .list {
  550. width: 100%;
  551. display: flex;
  552. justify-content: space-around;
  553. padding: 0 20rpx;
  554. .item {
  555. width: 30%;
  556. height: 140rpx;
  557. display: flex;
  558. flex-direction: column;
  559. align-items: center;
  560. justify-content: center;
  561. border: 1px solid #eee;
  562. border-radius: 15rpx;
  563. margin-top: 30rpx;
  564. color: #999;
  565. .price {
  566. font-size: 34rpx;
  567. margin-top: 10rpx;
  568. }
  569. }
  570. .avtive {
  571. color: #333;
  572. border-color: rgb(255, 0, 0);
  573. .price {
  574. color: rgb(255, 0, 0);
  575. }
  576. }
  577. }
  578. }
  579. .choose-content {
  580. flex: 1;
  581. width: 100%;
  582. .choose-item {
  583. width: 100%;
  584. .item {
  585. padding: 0 30rpx;
  586. }
  587. }
  588. .item {
  589. width: 100%;
  590. height: 100rpx;
  591. display: flex;
  592. align-items: center;
  593. justify-content: space-between;
  594. border-bottom: 1px solid #eee;
  595. .coopon {
  596. color: rgb(255, 0, 0);
  597. }
  598. }
  599. .phone {
  600. border-bottom: none;
  601. }
  602. .read {
  603. width: 100%;
  604. border-top: 1px solid #eee;
  605. padding-top: 40rpx;
  606. display: flex;
  607. justify-content: center;
  608. text {
  609. color: #999;
  610. }
  611. text:last-child {
  612. color: #ff9ba5;
  613. }
  614. }
  615. }
  616. }
  617. }
  618. .step-footer {
  619. width: 100%;
  620. background-color: #fff;
  621. .next-button {
  622. margin: 0;
  623. border-radius: 0;
  624. padding: 10rpx 0;
  625. }
  626. .pay {
  627. width: 100%;
  628. height: 100%;
  629. padding: 10rpx;
  630. border-top: 1px solid #eee;
  631. display: flex;
  632. align-items: center;
  633. justify-content: flex-end;
  634. .amount {
  635. color: rgb(255, 0, 0);
  636. font-size: 36rpx;
  637. margin-right: 40rpx;
  638. }
  639. button {
  640. width: 200rpx;
  641. }
  642. }
  643. }
  644. }
  645. </style>