getOrder.vue 13 KB

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