getOrder.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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.name}}</text>
  35. <text class="price">¥{{item.price}}</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 @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. } else {
  195. this.toashMsg(res.message)
  196. }
  197. })
  198. },
  199. // 选择服务项目
  200. chooseItem(index) {
  201. this.serverIndex = index
  202. this.amount = this.itemList[index].price
  203. this.getFinalAmount()
  204. },
  205. // 下一步
  206. nextStep() {
  207. this.stepIndex = this.stepIndex===0 ? 1 : 2
  208. uni.setStorageSync('stepIndex', this.stepIndex)
  209. },
  210. // 已阅读
  211. read (e) {
  212. this.isRead = e.msg
  213. },
  214. // 获取用户可用优惠券
  215. getCouponList () {
  216. },
  217. // 格式化优惠券数据 获取优惠金额最大的优惠券 couponType 优惠券类型:FULLSUB满减/DISCOUNT折扣券/VOUCHER代金券
  218. formatCouponData (){
  219. let arr = []
  220. let _this = this
  221. this.couponList.map(item => {
  222. let data = {}
  223. data.id = item.couponReceivesId
  224. if (item.couponType == 'DISCOUNT') {
  225. console.log(_this.amount, '_this.amount')
  226. data.subAmount = Number((_this.amount * (1 - item.subAmount)).toFixed(2))
  227. } else {
  228. data.subAmount = item.couponType == 'FULLSUB' ? item.subAmount : item.price
  229. }
  230. arr.push(data)
  231. })
  232. console.log(arr, 'arr')
  233. // 比较数据中优惠金额最大的值 并返回该对象
  234. let obj = arr.reduce((p, v) => p.subAmount < v.subAmount ? v : p)
  235. console.log(obj)
  236. let p = this.couponList.find(item => item.couponReceivesId == obj.id)
  237. // 订单金额为0时,默认不使用优惠卷
  238. if (this.amount != 0){
  239. this.checkedCoupon = p
  240. this.couponAmount = obj.subAmount > this.amount ? this.amount : obj.subAmount
  241. } else {
  242. this.checkedCoupon = null
  243. this.couponAmount = 0
  244. }
  245. // 计算合计
  246. this.getFinalAmount()
  247. },
  248. // 计算合计
  249. getFinalAmount () {
  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. toPay (){
  267. uni.showLoading({
  268. title: '请求中...',
  269. mask: true
  270. })
  271. let params = {
  272. "itemId": 100000, // 服务id
  273. "storeId": 100000, // 门店id
  274. "deviceId": 100000, // 设备id
  275. "orderTime": this.$u.timeFormat(Date.now(), 'yyyy-mm-dd hh:MM:ss'),
  276. "payableAmount": 4, // 应付金额 即优惠前金额
  277. "paymentAmount": 4 // 实收金额 即优惠后金额
  278. }
  279. saveOrder(params).then(res =>{
  280. uni.hideLoading()
  281. if (res.status==200) {
  282. // 付款成功后开始洗车
  283. uni.redirectTo({
  284. url:"/pages/work/index/index"
  285. })
  286. } else {
  287. this.toashMsg(res.message)
  288. }
  289. })
  290. }
  291. }
  292. }
  293. </script>
  294. <style lang="scss">
  295. page{
  296. height: 100%;
  297. }
  298. .order-content{
  299. width: 100%;
  300. height: 100%;
  301. display: flex;
  302. flex-direction: column;
  303. .step{
  304. padding: 40rpx 0;
  305. }
  306. .step-content{
  307. flex: 1;
  308. width: 100%;
  309. display: flex;
  310. flex-direction: column;
  311. .step-item{
  312. width: 100%;
  313. display: flex;
  314. flex-direction: column;
  315. align-items: center;
  316. flex: 1;
  317. }
  318. .step-one{
  319. text{
  320. color: #999;
  321. margin: 40rpx 0;
  322. }
  323. }
  324. .step-two{
  325. background-color: #F8F8F8;
  326. .item{
  327. background-color: #fff;
  328. width: 80%;
  329. height: 40%;
  330. display: flex;
  331. flex-direction: column;
  332. align-items: center;
  333. margin-top: 20rpx;
  334. padding-top: 20rpx;
  335. image{
  336. width: 80%;
  337. flex: 1;
  338. }
  339. }
  340. .top{
  341. text{
  342. color: #df928e;
  343. font-size: 24rpx;
  344. margin-bottom: 20rpx;
  345. }
  346. .care{
  347. padding: 10rpx 20rpx;
  348. background-color: #ff805b;
  349. border-radius: 30rpx;
  350. color: #fff;
  351. font-size: 24rpx;
  352. margin-bottom: 10rpx;
  353. }
  354. }
  355. .bottom{
  356. text{
  357. font-size: 24rpx;
  358. color: #333;
  359. }
  360. }
  361. }
  362. .step-three{
  363. .choose{
  364. width: 100%;
  365. height: auto;
  366. padding-bottom: 60rpx;
  367. display: flex;
  368. flex-direction: column;
  369. align-items: center;
  370. border-bottom: 1px solid #eee;
  371. .title{
  372. color: #666;
  373. }
  374. .list{
  375. width: 100%;
  376. display: flex;
  377. justify-content: space-around;
  378. padding: 0 20rpx;
  379. .item{
  380. width: 30%;
  381. height: 140rpx;
  382. display: flex;
  383. flex-direction: column;
  384. align-items: center;
  385. justify-content: center;
  386. border: 1px solid #eee;
  387. border-radius: 15rpx;
  388. margin-top: 30rpx;
  389. color: #999;
  390. .price{
  391. font-size: 34rpx;
  392. margin-top: 10rpx;
  393. }
  394. }
  395. .avtive{
  396. color: #333;
  397. border-color: rgb(255,0,0);
  398. .price{
  399. color: rgb(255,0,0);
  400. }
  401. }
  402. }
  403. }
  404. .choose-content{
  405. flex: 1;
  406. width: 100%;
  407. .choose-item{
  408. width: 100%;
  409. .item{
  410. padding: 0 30rpx;
  411. }
  412. }
  413. .item{
  414. width: 100%;
  415. height: 100rpx;
  416. display: flex;
  417. align-items: center;
  418. justify-content: space-between;
  419. border-bottom: 1px solid #eee;
  420. .coopon{
  421. color: rgb(255,0,0);
  422. }
  423. }
  424. .phone{
  425. border-bottom: none;
  426. }
  427. .read{
  428. width: 100%;
  429. border-top: 1px solid #eee;
  430. padding-top: 40rpx;
  431. display: flex;
  432. justify-content: center;
  433. text{
  434. color: #999;
  435. }
  436. text:last-child{
  437. color: #ff9ba5;
  438. }
  439. }
  440. }
  441. }
  442. .step-footer{
  443. width: 100%;
  444. background-color: #fff;
  445. .next-button{
  446. margin: 0;
  447. border-radius: 0;
  448. padding: 10rpx 0;
  449. }
  450. .pay{
  451. width: 100%;
  452. height: 100%;
  453. padding: 10rpx;
  454. border-top: 1px solid #eee;
  455. display: flex;
  456. align-items: center;
  457. justify-content: flex-end;
  458. .amount{
  459. color: rgb(255,0,0);
  460. font-size: 36rpx;
  461. margin-right: 40rpx;
  462. }
  463. button{
  464. width: 200rpx;
  465. }
  466. }
  467. }
  468. }
  469. }
  470. </style>