getOrder.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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" mode="aspectFit"></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" :key="index">
  40. <text>{{item.itemName}}</text>
  41. <text class="price">¥{{item.currentPrice}}</text>
  42. </view>
  43. <u-empty text="暂无服务项目" img-width="120" v-if="itemList.length==0 && status!='loading'" mode="list"></u-empty>
  44. </view>
  45. </view>
  46. <view class="choose-content">
  47. <view class="choose-item">
  48. <view class="item" @click="intoChooseCoupon">
  49. <text>优惠卷</text>
  50. <view v-if="checkedCoupon" class="right">
  51. <u-icon name="gift" color="rgb(255,0,0)" size="32"></u-icon>
  52. <text class="coopon">9.8元洗车券(¥-9.8)</text>
  53. <u-icon name="arrow-right" color="rgb(255,0,0)" size="32"></u-icon>
  54. </view>
  55. <view v-else class="right">
  56. <text >暂无可用优惠券</text>
  57. </view>
  58. </view>
  59. <view class="item phone">
  60. <text>手机号码</text>
  61. <view class="right">
  62. <text >{{userPhone}}</text>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="read" @click="intoAgreement">
  67. <u-radio-group v-model="isRead">
  68. <u-radio shape="square" :disabled="isRead!='read'" name="read" active-color="red" icon-size="28" label-size="28">
  69. 点击阅读并同意
  70. <text>无人洗车</text>
  71. <text>《注意事项及服务协议》</text>
  72. </u-radio>
  73. </u-radio-group>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="step-footer">
  79. <button class="next-button" @click="nextStep" v-if="stepIndex!=2" type="warn">下一步</button>
  80. <view v-else class="pay">
  81. <text>合计:</text>
  82. <text class="amount">¥{{finalAmount}}</text>
  83. <view class="">
  84. <button @click="handleSubmit" type="warn">去付款</button>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import uniSteps from '@/components/uni-steps/uni-steps.vue'
  92. import {getUserInfo} from '@/api/login.js'
  93. import {getStoreItems, saveOrder, signPay} from '@/api/order.js'
  94. export default {
  95. components: {
  96. uniSteps
  97. },
  98. data() {
  99. return {
  100. status: 'loadmore',
  101. userPhone: '',
  102. stepIndex: 0, // 当前步奏下标
  103. serverIndex: 0, // 选择服务下标
  104. itemList: [], // 服务类型
  105. isRead: '', // 是否同意协议
  106. couponList: [
  107. {
  108. id: 23432445,
  109. name: "满100减50",
  110. price: 100,
  111. yxTime: "2020-05-16",
  112. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  113. checked: false
  114. },
  115. {
  116. id: 3544355,
  117. name: "满100减50",
  118. price: 100,
  119. yxTime: "2020-05-16",
  120. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  121. checked: false
  122. },
  123. {
  124. id: 234234234,
  125. name: "满100减50",
  126. price: 100,
  127. yxTime: "2020-05-16",
  128. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  129. checked: false
  130. },
  131. {
  132. id: 66264646,
  133. name: "满100减50",
  134. price: 100,
  135. yxTime: "2020-05-16",
  136. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  137. checked: false
  138. },
  139. {
  140. id: 9794694698,
  141. name: "满100减50",
  142. price: 100,
  143. yxTime: "2020-05-16",
  144. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  145. checked: false
  146. }
  147. ], // 用户可用优惠券
  148. checkedCoupon: null, // 用户当前所选优惠券
  149. amount: 0, // 所选服务项目总金额
  150. couponAmount: 0, // 优惠券优惠金额
  151. finalAmount: 0, // 用户最终所需支付金额
  152. }
  153. },
  154. onLoad(option) {
  155. // 存储当前扫码的设备及网点id
  156. if(options.scene){
  157. let scene=decodeURIComponent(options.scene);
  158. //&是我们定义的参数链接方式
  159. let storeId=scene.split(",")[0];
  160. let bizId=scene.split(',')[1];
  161. //其他逻辑处理。。。。。
  162. this.$store.state.vuex_orderInfo.bizId = bizId || '9999'
  163. this.$store.state.vuex_orderInfo.storeId = storeId || '100000'
  164. // 判断当前门店是否已运营
  165. }else{
  166. // 判断是否扫码过
  167. if(this.$store.state.vuex_orderInfo.bizId!=''){
  168. }else{
  169. // 返回首页
  170. }
  171. }
  172. },
  173. onUnload() {
  174. uni.removeStorageSync('stepIndex')
  175. },
  176. onShow() {
  177. const index = uni.getStorageSync('stepIndex')
  178. this.stepIndex = index ? index : 0
  179. console.log(this.stepIndex)
  180. },
  181. methods: {
  182. // 获取用户信息
  183. getUserPhone () {
  184. getUserInfo().then(res =>{
  185. console.log(res,'rrrrrrr')
  186. if(res.status == 200) {
  187. this.userPhone = res.data.mobile
  188. } else {
  189. uni.showToast({
  190. title: res.message,
  191. icon: 'none'
  192. })
  193. }
  194. })
  195. },
  196. // 查看更多注意事项
  197. lookMore () {
  198. uni.navigateTo({
  199. url: '/pages/careMore/careMore'
  200. })
  201. },
  202. // 获取服务列表
  203. getServerList () {
  204. this.status = 'loading'
  205. let storeId = this.$store.state.vuex_orderInfo.storeId
  206. getStoreItems({storeId:storeId}).then(res =>{
  207. this.status = 'loadmore'
  208. if (res.status == 200) {
  209. this.itemList = res.data
  210. this.serverIndex = 0
  211. this.getFinalAmount()
  212. } else {
  213. this.itemList = []
  214. this.toashMsg(res.message)
  215. }
  216. })
  217. },
  218. // 选择服务项目
  219. chooseItem(index) {
  220. this.serverIndex = index
  221. this.getFinalAmount()
  222. },
  223. // 下一步
  224. nextStep() {
  225. this.stepIndex = this.stepIndex===0 ? 1 : 2
  226. uni.setStorageSync('stepIndex', this.stepIndex)
  227. },
  228. // 已阅读
  229. read (e) {
  230. this.isRead = e.msg
  231. },
  232. // 获取用户可用优惠券
  233. getCouponList () {
  234. },
  235. // 格式化优惠券数据 获取优惠金额最大的优惠券 couponType 优惠券类型:FULLSUB满减/DISCOUNT折扣券/VOUCHER代金券
  236. formatCouponData (){
  237. let arr = []
  238. let _this = this
  239. this.couponList.map(item => {
  240. let data = {}
  241. data.id = item.couponReceivesId
  242. if (item.couponType == 'DISCOUNT') {
  243. console.log(_this.amount, '_this.amount')
  244. data.subAmount = Number((_this.amount * (1 - item.subAmount)).toFixed(2))
  245. } else {
  246. data.subAmount = item.couponType == 'FULLSUB' ? item.subAmount : item.price
  247. }
  248. arr.push(data)
  249. })
  250. console.log(arr, 'arr')
  251. // 比较数据中优惠金额最大的值 并返回该对象
  252. let obj = arr.reduce((p, v) => p.subAmount < v.subAmount ? v : p)
  253. console.log(obj)
  254. let p = this.couponList.find(item => item.couponReceivesId == obj.id)
  255. // 订单金额为0时,默认不使用优惠卷
  256. if (this.amount != 0){
  257. this.checkedCoupon = p
  258. this.couponAmount = obj.subAmount > this.amount ? this.amount : obj.subAmount
  259. } else {
  260. this.checkedCoupon = null
  261. this.couponAmount = 0
  262. }
  263. // 计算合计
  264. this.getFinalAmount()
  265. },
  266. // 计算合计
  267. getFinalAmount () {
  268. this.amount = this.itemList[this.serverIndex].currentPrice
  269. let ret = this.amount - this.couponAmount
  270. this.finalAmount = ret.toFixed(2)
  271. },
  272. // 选择优惠券
  273. intoChooseCoupon () {
  274. uni.navigateTo({
  275. url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}`
  276. })
  277. },
  278. // 打开服务协议
  279. intoAgreement () {
  280. uni.navigateTo({
  281. url: '/pages/agreement/agreement'
  282. })
  283. },
  284. // 去付款 保存订单
  285. handleSubmit (){
  286. if(this.itemList.length==0){
  287. this.toashMsg('请先选择服务')
  288. return
  289. }
  290. if (this.isRead !='read') {
  291. this.toashMsg('请先阅读并同意无人洗车《注意事项及服务协议》!')
  292. return
  293. } else if (this.itemList.length==0) {
  294. this.toashMsg('暂无服务项目')
  295. return
  296. }
  297. uni.showLoading({
  298. title: '请求中...',
  299. mask: true
  300. })
  301. let item = this.itemList[this.serverIndex]
  302. let params = {
  303. "itemId": item.itemId, // 服务id
  304. "itemCode": item.itemCode,
  305. "storeId": 100000, // 门店id
  306. "deviceId": 100000, // 设备id
  307. "orderTime": this.$u.timeFormat(Date.now(), 'yyyy-mm-dd hh:MM:ss'),
  308. "payableAmount": this.amount, // 应付金额 即优惠前金额
  309. "paymentAmount": this.finalAmount // 实收金额 即优惠后金额
  310. }
  311. saveOrder(params).then(res =>{
  312. if (res.status==200) {
  313. let data = res.data
  314. // 保存成功后 请求预支付返回吊起微信支付所需参数
  315. this.getPayData(data)
  316. this.$store.state.vuex_orderInfo.itemCode = data.itemCode
  317. this.$store.state.vuex_orderInfo.orderNo = data.orderNo
  318. this.$store.state.vuex_orderInfo.duration = item.duration
  319. } else {
  320. uni.hideLoading()
  321. // 刷新服务项
  322. this.getServerList()
  323. this.toashMsg(res.message)
  324. }
  325. })
  326. },
  327. // 预支付 返回微信支付所需参数
  328. getPayData (orderData) {
  329. signPay({orderId:orderData.id}).then(res =>{
  330. console.log(res,'预支付')
  331. uni.hideLoading()
  332. if (res.status == 200) {
  333. let data = res.data
  334. // 0元订单直接支付成功,不用吊微信支付
  335. if (data.tradeStatus && data.tradeStatus=="PAID") {
  336. // 付款成功后开始洗车
  337. uni.redirectTo({
  338. url:`/pages/work/index/index`
  339. })
  340. } else {
  341. uni.requestPayment({
  342. provider: 'wxpay',
  343. timeStamp: data.timeStamp,
  344. nonceStr: data.nonceStr,
  345. package: data.package,
  346. signType: data.signType,
  347. paySign: data.paySign,
  348. success: function (res) {
  349. console.log('success:' + JSON.stringify(res));
  350. // 付款成功后开始洗车
  351. uni.redirectTo({
  352. url:`/pages/work/index/index`
  353. })
  354. },
  355. fail: function (err) {
  356. console.log('fail:' + JSON.stringify(err));
  357. }
  358. });
  359. }
  360. } else {
  361. this.toashMsg(res.message)
  362. }
  363. })
  364. }
  365. }
  366. }
  367. </script>
  368. <style lang="scss">
  369. page{
  370. height: 100%;
  371. }
  372. .order-content{
  373. width: 100%;
  374. height: 100%;
  375. display: flex;
  376. flex-direction: column;
  377. .step{
  378. padding: 40rpx 0;
  379. }
  380. .step-content{
  381. flex: 1;
  382. width: 100%;
  383. display: flex;
  384. flex-direction: column;
  385. .step-item{
  386. width: 100%;
  387. display: flex;
  388. flex-direction: column;
  389. align-items: center;
  390. flex: 1;
  391. }
  392. // 第一步
  393. .step-one{
  394. text{
  395. color: #999;
  396. margin: 40rpx 0;
  397. }
  398. }
  399. // 第二步
  400. .step-two{
  401. background-color: #F8F8F8;
  402. justify-content: space-around;
  403. .item{
  404. background-color: #fff;
  405. width: 80%;
  406. height: 45%;
  407. display: flex;
  408. flex-direction: column;
  409. align-items: center;
  410. image{
  411. width: 80%;
  412. flex: 1;
  413. }
  414. }
  415. .top{
  416. text{
  417. color: #df928e;
  418. font-size: 24rpx;
  419. }
  420. .item-text{
  421. padding-top: 20rpx;
  422. }
  423. .care{
  424. padding: 10rpx 20rpx;
  425. background-color: #ff805b;
  426. border-radius: 30rpx;
  427. color: #fff;
  428. font-size: 24rpx;
  429. margin-bottom: 20rpx;
  430. }
  431. }
  432. .bottom{
  433. text{
  434. font-size: 24rpx;
  435. color: #333;
  436. }
  437. .item-text{
  438. width: 100%;
  439. padding:0 20rpx;
  440. display: flex;
  441. justify-content: space-between;
  442. padding-top: 20rpx;
  443. }
  444. }
  445. }
  446. // 第三步 下单
  447. .step-three{
  448. .choose{
  449. width: 100%;
  450. height: auto;
  451. padding-bottom: 60rpx;
  452. display: flex;
  453. flex-direction: column;
  454. align-items: center;
  455. border-bottom: 1px solid #eee;
  456. .title{
  457. color: #666;
  458. }
  459. .list{
  460. width: 100%;
  461. display: flex;
  462. justify-content: space-around;
  463. padding: 0 20rpx;
  464. .item{
  465. width: 30%;
  466. height: 140rpx;
  467. display: flex;
  468. flex-direction: column;
  469. align-items: center;
  470. justify-content: center;
  471. border: 1px solid #eee;
  472. border-radius: 15rpx;
  473. margin-top: 30rpx;
  474. color: #999;
  475. .price{
  476. font-size: 34rpx;
  477. margin-top: 10rpx;
  478. }
  479. }
  480. .avtive{
  481. color: #333;
  482. border-color: rgb(255,0,0);
  483. .price{
  484. color: rgb(255,0,0);
  485. }
  486. }
  487. }
  488. }
  489. .choose-content{
  490. flex: 1;
  491. width: 100%;
  492. .choose-item{
  493. width: 100%;
  494. .item{
  495. padding: 0 30rpx;
  496. }
  497. }
  498. .item{
  499. width: 100%;
  500. height: 100rpx;
  501. display: flex;
  502. align-items: center;
  503. justify-content: space-between;
  504. border-bottom: 1px solid #eee;
  505. .coopon{
  506. color: rgb(255,0,0);
  507. }
  508. }
  509. .phone{
  510. border-bottom: none;
  511. }
  512. .read{
  513. width: 100%;
  514. border-top: 1px solid #eee;
  515. padding-top: 40rpx;
  516. display: flex;
  517. justify-content: center;
  518. text{
  519. color: #999;
  520. }
  521. text:last-child{
  522. color: #ff9ba5;
  523. }
  524. }
  525. }
  526. }
  527. }
  528. .step-footer{
  529. width: 100%;
  530. background-color: #fff;
  531. .next-button{
  532. margin: 0;
  533. border-radius: 0;
  534. padding: 10rpx 0;
  535. }
  536. .pay{
  537. width: 100%;
  538. height: 100%;
  539. padding: 10rpx;
  540. border-top: 1px solid #eee;
  541. display: flex;
  542. align-items: center;
  543. justify-content: flex-end;
  544. .amount{
  545. color: rgb(255,0,0);
  546. font-size: 36rpx;
  547. margin-right: 40rpx;
  548. }
  549. button{
  550. width: 200rpx;
  551. }
  552. }
  553. }
  554. }
  555. </style>