getOrder.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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>-请完成以下操作-</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>超高加装件不能清洗</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. let orderId = res.data.id
  295. // 保存成功后 请求预支付返回吊起微信支付所需参数
  296. // this.getPayData(orderId)
  297. // 付款成功后开始洗车
  298. uni.redirectTo({
  299. url:`/pages/work/index/index?washCarType=${data.itemCode}&orderNo=${data.orderNo}`
  300. })
  301. } else {
  302. uni.hideLoading()
  303. // 刷新服务项
  304. this.getServerList()
  305. this.toashMsg(res.message)
  306. }
  307. })
  308. },
  309. // 预支付 返回微信支付所需参数
  310. getPayData (id) {
  311. signPay({orderId:id}).then(res =>{
  312. console.log(res,'11111111')
  313. uni.hideLoading()
  314. if (res.status == 200) {
  315. let data = res.data
  316. uni.requestPayment({
  317. provider: 'wxpay',
  318. timeStamp: data.timeStamp,
  319. nonceStr: data.nonceStr,
  320. package: data.package,
  321. signType: data.signType,
  322. paySign: data.paySign,
  323. success: function (res) {
  324. console.log('success:' + JSON.stringify(res));
  325. },
  326. fail: function (err) {
  327. console.log('fail:' + JSON.stringify(err));
  328. }
  329. });
  330. } else {
  331. this.toashMsg(res.message)
  332. }
  333. })
  334. }
  335. }
  336. }
  337. </script>
  338. <style lang="scss">
  339. page{
  340. height: 100%;
  341. }
  342. .order-content{
  343. width: 100%;
  344. height: 100%;
  345. display: flex;
  346. flex-direction: column;
  347. .step{
  348. padding: 40rpx 0;
  349. }
  350. .step-content{
  351. flex: 1;
  352. width: 100%;
  353. display: flex;
  354. flex-direction: column;
  355. .step-item{
  356. width: 100%;
  357. display: flex;
  358. flex-direction: column;
  359. align-items: center;
  360. flex: 1;
  361. }
  362. // 第一步
  363. .step-one{
  364. text{
  365. color: #999;
  366. margin: 40rpx 0;
  367. }
  368. }
  369. // 第二步
  370. .step-two{
  371. background-color: #F8F8F8;
  372. justify-content: space-around;
  373. .item{
  374. background-color: #fff;
  375. width: 80%;
  376. height: 45%;
  377. display: flex;
  378. flex-direction: column;
  379. align-items: center;
  380. // margin-top: 20rpx;
  381. // padding-top: 20rpx;
  382. image{
  383. width: 80%;
  384. flex: 1;
  385. }
  386. }
  387. .top{
  388. text{
  389. color: #df928e;
  390. font-size: 24rpx;
  391. // margin-top: 20rpx;
  392. }
  393. .care{
  394. padding: 10rpx 20rpx;
  395. background-color: #ff805b;
  396. border-radius: 30rpx;
  397. color: #fff;
  398. font-size: 24rpx;
  399. margin-bottom: 20rpx;
  400. }
  401. }
  402. .bottom{
  403. text{
  404. font-size: 24rpx;
  405. color: #333;
  406. padding-top: 20rpx;
  407. // margin-top: 20rpx;
  408. }
  409. }
  410. }
  411. // 第三步 下单
  412. .step-three{
  413. .choose{
  414. width: 100%;
  415. height: auto;
  416. padding-bottom: 60rpx;
  417. display: flex;
  418. flex-direction: column;
  419. align-items: center;
  420. border-bottom: 1px solid #eee;
  421. .title{
  422. color: #666;
  423. }
  424. .list{
  425. width: 100%;
  426. display: flex;
  427. justify-content: space-around;
  428. padding: 0 20rpx;
  429. .item{
  430. width: 30%;
  431. height: 140rpx;
  432. display: flex;
  433. flex-direction: column;
  434. align-items: center;
  435. justify-content: center;
  436. border: 1px solid #eee;
  437. border-radius: 15rpx;
  438. margin-top: 30rpx;
  439. color: #999;
  440. .price{
  441. font-size: 34rpx;
  442. margin-top: 10rpx;
  443. }
  444. }
  445. .avtive{
  446. color: #333;
  447. border-color: rgb(255,0,0);
  448. .price{
  449. color: rgb(255,0,0);
  450. }
  451. }
  452. }
  453. }
  454. .choose-content{
  455. flex: 1;
  456. width: 100%;
  457. .choose-item{
  458. width: 100%;
  459. .item{
  460. padding: 0 30rpx;
  461. }
  462. }
  463. .item{
  464. width: 100%;
  465. height: 100rpx;
  466. display: flex;
  467. align-items: center;
  468. justify-content: space-between;
  469. border-bottom: 1px solid #eee;
  470. .coopon{
  471. color: rgb(255,0,0);
  472. }
  473. }
  474. .phone{
  475. border-bottom: none;
  476. }
  477. .read{
  478. width: 100%;
  479. border-top: 1px solid #eee;
  480. padding-top: 40rpx;
  481. display: flex;
  482. justify-content: center;
  483. text{
  484. color: #999;
  485. }
  486. text:last-child{
  487. color: #ff9ba5;
  488. }
  489. }
  490. }
  491. }
  492. }
  493. .step-footer{
  494. width: 100%;
  495. background-color: #fff;
  496. .next-button{
  497. margin: 0;
  498. border-radius: 0;
  499. padding: 10rpx 0;
  500. }
  501. .pay{
  502. width: 100%;
  503. height: 100%;
  504. padding: 10rpx;
  505. border-top: 1px solid #eee;
  506. display: flex;
  507. align-items: center;
  508. justify-content: flex-end;
  509. .amount{
  510. color: rgb(255,0,0);
  511. font-size: 36rpx;
  512. margin-right: 40rpx;
  513. }
  514. button{
  515. width: 200rpx;
  516. }
  517. }
  518. }
  519. }
  520. </style>