getOrder.vue 14 KB

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