getOrder.vue 14 KB

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