getOrder.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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">
  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 @click="intoAgreement">《注意事项及服务协议》</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. uni.removeStorageSync('stepIndex')
  156. // 注册全局监听事件
  157. uni.$once('read', this.read)
  158. this.getUserPhone()
  159. this.getServerList()
  160. // 存储当前扫码的设备及网点id
  161. // if(options.scene){
  162. // let scene=decodeURIComponent(options.scene);
  163. // //&是我们定义的参数链接方式
  164. // let userId=scene.split("&")[0];
  165. // let recommendId=scene.split('&')[1];
  166. // //其他逻辑处理。。。。。
  167. // }
  168. this.$store.state.vuex_orderInfo.bizId = option.bizId || '9898'
  169. this.$store.state.vuex_orderInfo.storeId = option.storeId || ''
  170. },
  171. onUnload() {
  172. uni.removeStorageSync('stepIndex')
  173. },
  174. onShow() {
  175. const index = uni.getStorageSync('stepIndex')
  176. this.stepIndex = index ? index : 0
  177. console.log(this.stepIndex)
  178. },
  179. methods: {
  180. // 获取用户信息
  181. getUserPhone () {
  182. getUserInfo().then(res =>{
  183. console.log(res,'rrrrrrr')
  184. if(res.status == 200) {
  185. this.userPhone = res.data.mobile
  186. } else {
  187. uni.showToast({
  188. title: res.message,
  189. icon: 'none'
  190. })
  191. }
  192. })
  193. },
  194. // 查看更多注意事项
  195. lookMore () {
  196. uni.navigateTo({
  197. url: '/pages/careMore/careMore'
  198. })
  199. },
  200. // 获取服务列表
  201. getServerList () {
  202. this.status = 'loading'
  203. getStoreItems({storeId:100000}).then(res =>{
  204. this.status = 'loadmore'
  205. if (res.status == 200) {
  206. this.itemList = res.data
  207. this.serverIndex = 0
  208. this.getFinalAmount()
  209. } else {
  210. this.itemList = []
  211. this.toashMsg(res.message)
  212. }
  213. })
  214. },
  215. // 选择服务项目
  216. chooseItem(index) {
  217. this.serverIndex = index
  218. this.getFinalAmount()
  219. },
  220. // 下一步
  221. nextStep() {
  222. this.stepIndex = this.stepIndex===0 ? 1 : 2
  223. uni.setStorageSync('stepIndex', this.stepIndex)
  224. },
  225. // 已阅读
  226. read (e) {
  227. this.isRead = e.msg
  228. },
  229. // 获取用户可用优惠券
  230. getCouponList () {
  231. },
  232. // 格式化优惠券数据 获取优惠金额最大的优惠券 couponType 优惠券类型:FULLSUB满减/DISCOUNT折扣券/VOUCHER代金券
  233. formatCouponData (){
  234. let arr = []
  235. let _this = this
  236. this.couponList.map(item => {
  237. let data = {}
  238. data.id = item.couponReceivesId
  239. if (item.couponType == 'DISCOUNT') {
  240. console.log(_this.amount, '_this.amount')
  241. data.subAmount = Number((_this.amount * (1 - item.subAmount)).toFixed(2))
  242. } else {
  243. data.subAmount = item.couponType == 'FULLSUB' ? item.subAmount : item.price
  244. }
  245. arr.push(data)
  246. })
  247. console.log(arr, 'arr')
  248. // 比较数据中优惠金额最大的值 并返回该对象
  249. let obj = arr.reduce((p, v) => p.subAmount < v.subAmount ? v : p)
  250. console.log(obj)
  251. let p = this.couponList.find(item => item.couponReceivesId == obj.id)
  252. // 订单金额为0时,默认不使用优惠卷
  253. if (this.amount != 0){
  254. this.checkedCoupon = p
  255. this.couponAmount = obj.subAmount > this.amount ? this.amount : obj.subAmount
  256. } else {
  257. this.checkedCoupon = null
  258. this.couponAmount = 0
  259. }
  260. // 计算合计
  261. this.getFinalAmount()
  262. },
  263. // 计算合计
  264. getFinalAmount () {
  265. this.amount = this.itemList[this.serverIndex].currentPrice
  266. let ret = this.amount - this.couponAmount
  267. this.finalAmount = ret.toFixed(2)
  268. },
  269. // 选择优惠券
  270. intoChooseCoupon () {
  271. uni.navigateTo({
  272. url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}`
  273. })
  274. },
  275. // 打开服务协议
  276. intoAgreement () {
  277. uni.navigateTo({
  278. url: '/pages/agreement/agreement'
  279. })
  280. },
  281. // 去付款 保存订单
  282. handleSubmit (){
  283. if (this.isRead !='read') {
  284. this.toashMsg('请先阅读并同意无人洗车《注意事项及服务协议》!')
  285. return
  286. } else if (this.itemList.length==0) {
  287. this.toashMsg('暂无服务项目')
  288. return
  289. }
  290. uni.showLoading({
  291. title: '请求中...',
  292. mask: true
  293. })
  294. let item = this.itemList[this.serverIndex]
  295. let params = {
  296. "itemId": item.itemId, // 服务id
  297. "itemCode": item.itemCode,
  298. "storeId": 100000, // 门店id
  299. "deviceId": 100000, // 设备id
  300. "orderTime": this.$u.timeFormat(Date.now(), 'yyyy-mm-dd hh:MM:ss'),
  301. "payableAmount": this.amount, // 应付金额 即优惠前金额
  302. "paymentAmount": this.finalAmount // 实收金额 即优惠后金额
  303. }
  304. saveOrder(params).then(res =>{
  305. if (res.status==200) {
  306. let data = res.data
  307. // 保存成功后 请求预支付返回吊起微信支付所需参数
  308. this.getPayData(data)
  309. this.$store.state.vuex_orderInfo.itemCode = data.itemCode
  310. this.$store.state.vuex_orderInfo.orderNo = data.orderNo
  311. this.$store.state.vuex_orderInfo.duration = item.duration
  312. } else {
  313. uni.hideLoading()
  314. // 刷新服务项
  315. this.getServerList()
  316. this.toashMsg(res.message)
  317. }
  318. })
  319. },
  320. // 预支付 返回微信支付所需参数
  321. getPayData (orderData) {
  322. signPay({orderId:orderData.id}).then(res =>{
  323. console.log(res,'预支付')
  324. uni.hideLoading()
  325. if (res.status == 200) {
  326. let data = res.data
  327. // 0元订单直接支付成功,不用吊微信支付
  328. if (data.tradeStatus && data.tradeStatus=="PAID") {
  329. // 付款成功后开始洗车
  330. uni.redirectTo({
  331. url:`/pages/work/index/index`
  332. })
  333. } else {
  334. uni.requestPayment({
  335. provider: 'wxpay',
  336. timeStamp: data.timeStamp,
  337. nonceStr: data.nonceStr,
  338. package: data.package,
  339. signType: data.signType,
  340. paySign: data.paySign,
  341. success: function (res) {
  342. console.log('success:' + JSON.stringify(res));
  343. // 付款成功后开始洗车
  344. uni.redirectTo({
  345. url:`/pages/work/index/index`
  346. })
  347. },
  348. fail: function (err) {
  349. console.log('fail:' + JSON.stringify(err));
  350. }
  351. });
  352. }
  353. } else {
  354. this.toashMsg(res.message)
  355. }
  356. })
  357. }
  358. }
  359. }
  360. </script>
  361. <style lang="scss">
  362. page{
  363. height: 100%;
  364. }
  365. .order-content{
  366. width: 100%;
  367. height: 100%;
  368. display: flex;
  369. flex-direction: column;
  370. .step{
  371. padding: 40rpx 0;
  372. }
  373. .step-content{
  374. flex: 1;
  375. width: 100%;
  376. display: flex;
  377. flex-direction: column;
  378. .step-item{
  379. width: 100%;
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. flex: 1;
  384. }
  385. // 第一步
  386. .step-one{
  387. text{
  388. color: #999;
  389. margin: 40rpx 0;
  390. }
  391. }
  392. // 第二步
  393. .step-two{
  394. background-color: #F8F8F8;
  395. justify-content: space-around;
  396. .item{
  397. background-color: #fff;
  398. width: 80%;
  399. height: 45%;
  400. display: flex;
  401. flex-direction: column;
  402. align-items: center;
  403. image{
  404. width: 80%;
  405. flex: 1;
  406. }
  407. }
  408. .top{
  409. text{
  410. color: #df928e;
  411. font-size: 24rpx;
  412. }
  413. .item-text{
  414. padding-top: 20rpx;
  415. }
  416. .care{
  417. padding: 10rpx 20rpx;
  418. background-color: #ff805b;
  419. border-radius: 30rpx;
  420. color: #fff;
  421. font-size: 24rpx;
  422. margin-bottom: 20rpx;
  423. }
  424. }
  425. .bottom{
  426. text{
  427. font-size: 24rpx;
  428. color: #333;
  429. }
  430. .item-text{
  431. width: 100%;
  432. padding:0 20rpx;
  433. display: flex;
  434. justify-content: space-between;
  435. padding-top: 20rpx;
  436. }
  437. }
  438. }
  439. // 第三步 下单
  440. .step-three{
  441. .choose{
  442. width: 100%;
  443. height: auto;
  444. padding-bottom: 60rpx;
  445. display: flex;
  446. flex-direction: column;
  447. align-items: center;
  448. border-bottom: 1px solid #eee;
  449. .title{
  450. color: #666;
  451. }
  452. .list{
  453. width: 100%;
  454. display: flex;
  455. justify-content: space-around;
  456. padding: 0 20rpx;
  457. .item{
  458. width: 30%;
  459. height: 140rpx;
  460. display: flex;
  461. flex-direction: column;
  462. align-items: center;
  463. justify-content: center;
  464. border: 1px solid #eee;
  465. border-radius: 15rpx;
  466. margin-top: 30rpx;
  467. color: #999;
  468. .price{
  469. font-size: 34rpx;
  470. margin-top: 10rpx;
  471. }
  472. }
  473. .avtive{
  474. color: #333;
  475. border-color: rgb(255,0,0);
  476. .price{
  477. color: rgb(255,0,0);
  478. }
  479. }
  480. }
  481. }
  482. .choose-content{
  483. flex: 1;
  484. width: 100%;
  485. .choose-item{
  486. width: 100%;
  487. .item{
  488. padding: 0 30rpx;
  489. }
  490. }
  491. .item{
  492. width: 100%;
  493. height: 100rpx;
  494. display: flex;
  495. align-items: center;
  496. justify-content: space-between;
  497. border-bottom: 1px solid #eee;
  498. .coopon{
  499. color: rgb(255,0,0);
  500. }
  501. }
  502. .phone{
  503. border-bottom: none;
  504. }
  505. .read{
  506. width: 100%;
  507. border-top: 1px solid #eee;
  508. padding-top: 40rpx;
  509. display: flex;
  510. justify-content: center;
  511. text{
  512. color: #999;
  513. }
  514. text:last-child{
  515. color: #ff9ba5;
  516. }
  517. }
  518. }
  519. }
  520. }
  521. .step-footer{
  522. width: 100%;
  523. background-color: #fff;
  524. .next-button{
  525. margin: 0;
  526. border-radius: 0;
  527. padding: 10rpx 0;
  528. }
  529. .pay{
  530. width: 100%;
  531. height: 100%;
  532. padding: 10rpx;
  533. border-top: 1px solid #eee;
  534. display: flex;
  535. align-items: center;
  536. justify-content: flex-end;
  537. .amount{
  538. color: rgb(255,0,0);
  539. font-size: 36rpx;
  540. margin-right: 40rpx;
  541. }
  542. button{
  543. width: 200rpx;
  544. }
  545. }
  546. }
  547. }
  548. </style>