getOrder.vue 13 KB

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