getOrder.vue 12 KB

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