金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

616 lines
17 KiB

4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view>
  3. <lf-nav title="确认订单" :showIcon="true"></lf-nav>
  4. <block v-if="$isRight(order_detail)">
  5. <view class="card head">
  6. <view class="lf-font-32 lf-color-222">选择收货方式</view>
  7. <view class="capsule">
  8. <view class="item" :class="{'capsule-active': mode == 0}" @click="switchMode(0)">邮寄</view>
  9. <view class="item" :class="{'capsule-active': mode == 1}" @click="switchMode(1)">自提</view>
  10. </view>
  11. </view>
  12. <view class="card address" v-if="mode == 0">
  13. <view @click="$url('/pages/address/list/list?is_select=1')">
  14. <text class="lf-font-28 lf-color-primary lf-m-r-10">更换收获地址</text>
  15. <text class="lf-iconfont icon-xiangyou lf-font-24 lf-color-777"></text>
  16. </view>
  17. <view v-if="address">
  18. <view class="lf-m-t-20">
  19. <text class="lf-font-28 lf-color-222 lf-font-bold">{{ address.accept_name }}</text>
  20. <text class="lf-font-28 lf-color-777 lf-m-l-20">{{ address.mobile }}</text>
  21. </view>
  22. <view class="lf-font-28 lf-color-333 lf-m-t-10">
  23. <text>{{ address.address_name }}{{ address.address }}</text>
  24. </view>
  25. </view>
  26. <view v-else class="lf-font-28 lf-color-777">
  27. 暂无收货地址,请前往添加
  28. </view>
  29. </view>
  30. <view class="card address" v-else>
  31. <view>
  32. <text class="lf-font-28 lf-color-primary lf-m-r-10">店铺地址</text>
  33. </view>
  34. <view v-if="address">
  35. <view class="lf-m-t-20">
  36. <text class="lf-font-28 lf-color-222 lf-font-bold">{{ order_detail.order.brand.name }}</text>
  37. <text class="lf-font-28 lf-color-777 lf-m-l-20">{{ order_detail.order.brand.tel }}</text>
  38. </view>
  39. <view class="lf-font-28 lf-color-333 lf-m-t-10">
  40. <text>{{ order_detail.order.brand.floor }}</text>
  41. </view>
  42. </view>
  43. <view v-else class="lf-font-28 lf-color-777">
  44. 暂无收货地址,请前往添加
  45. </view>
  46. </view>
  47. <view class="card goods" v-if="$isRight(order_detail.order) && $isRight(order_detail.order.items)">
  48. <view @click="$url('/pages/shop/shopdetail?id='+ order_detail.order.brand.id)">
  49. <text class="lf-iconfont icon-Group- lf-font-30"></text>
  50. <text class="shop-name">{{ order_detail.order.brand.name }}</text>
  51. <text class="lf-iconfont icon-xiangyou lf-font-24"></text>
  52. </view>
  53. <view class="lf-flex lf-m-t-20" v-for="(item, index) in order_detail.order.items" :key="index">
  54. <image class="goods-img" :src="item.item_meta.image"></image>
  55. <view class="info">
  56. <view class="lf-font-26 lf-color-333 lf-line-1">{{ item.item_name }}</view>
  57. <view class="lf-font-24 lf-color-777">{{ item.item_meta.specs_text }}</view>
  58. <view class="lf-row-between" style="line-height: 1;">
  59. <text class="price"><text v-if="goods_type==1">¥</text>{{ unitConversion(item.unit_price) }}<text class="lf-font-24" v-if="goods_type==0">积分</text></text>
  60. <text class="lf-font-28 lf-color-777">x {{ item.quantity }}</text>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- <view class="tips">支付成功后15天内柜台提货</view> -->
  65. <view class="lf-flex lf-m-t-20">
  66. <view class="lf-font-28 lf-color-777">留言</view>
  67. <input v-model="value" class="input" placeholder="有什么要求,请备注留言" />
  68. </view>
  69. </view>
  70. <view class="card lf-m-t-20">
  71. <view class="lf-row-between" @click="openCheckCoupon">
  72. <view class="lf-font-28 lf-color-777">优惠券</view>
  73. <view>
  74. <text class="lf-font-26 lf-color-999 lf-m-r-10">{{ showCouponTitle }}</text>
  75. <text class="lf-iconfont icon-xiangyou lf-font-24"></text>
  76. </view>
  77. </view>
  78. <view class="lf-row-between lf-m-t-20">
  79. <view class="lf-font-28 lf-color-777">商品金额</view>
  80. <view class="lf-font-26 lf-color-222"><text v-if="goods_type==1">¥</text>{{ itemsPrice }}<text v-if="goods_type==0">积分</text></view>
  81. </view>
  82. <view class="lf-row-between lf-m-t-20" v-if="mode == 0">
  83. <view class="lf-font-28 lf-color-777">运费</view>
  84. <view class="lf-font-26" style="color: #F63434;">+¥{{ order_detail.order.payable_freight_yuan || 0 }}</view>
  85. </view>
  86. <view class="lf-row-between lf-m-t-20">
  87. <view class="lf-font-28 lf-color-777">优惠</view>
  88. <view class="lf-font-26" style="color: #F63434;">-¥{{ fullMinus(order_detail.discounts) }}</view>
  89. </view>
  90. </view>
  91. <view class="spread-out"></view>
  92. <view class="fixed-bottom">
  93. <view class="fixed-content">
  94. <view class="lf-font-24 lf-color-777">{{ order_detail.order.count }}</view>
  95. <view class="lf-flex">
  96. <!-- <view class="lf-font-32 lf-color-primary" style="max-width: 400rpx;">合计 ¥{{ order_detail.order.total_yuan }}</view> -->
  97. <view class="lf-font-32 lf-color-primary" style="max-width: 400rpx;">
  98. <text>合计</text>
  99. <text v-if="goods_type==1">¥</text>
  100. <text>{{ totalPrice }}</text>
  101. <text v-if="goods_type==0">积分</text>
  102. </view>
  103. <view class="confirm-btn" hover-class="lf-opacity" @click="confirm">提交订单</view>
  104. </view>
  105. </view>
  106. </view>
  107. <!-- 选择优惠券弹出层 -->
  108. <u-popup v-model="show_coupon" mode="bottom" :round="true" borderRadius="20">
  109. <view class="popup-content">
  110. <view class="lf-row-between" v-for="(item, index) in order_detail.coupons" :key="index">
  111. <radio-group @change="couponChange">
  112. <radio :value="index" :checked="coupon_index == index"></radio>
  113. </radio-group>
  114. <view class="coupon-card lf-m-b-30" :class="{'invalid-bg': item.ifpast == true}">
  115. <view class="coupon-circle-top">
  116. <view class="coupon-circle1"></view>
  117. </view>
  118. <view class="coupon-circle-bottom">
  119. <view class="coupon-circle1"></view>
  120. </view>
  121. <view class="coupon-radius">
  122. <view class="coupon-left">
  123. <view class="lf-font-36 lf-color-white" style="line-height: 1;" v-if="item.discount.action_type.type == 'cash'">
  124. <text v-if="goods_type==1"></text>
  125. <text class="lf-font-70 lf-font-bold">{{item.discount.action_type.value}}</text>
  126. <text v-if="goods_type==0">积分</text>
  127. </view>
  128. <view class="lf-font-36 lf-color-white" style="line-height: 1;" v-if="item.discount.action_type.type == 'discount'">
  129. <text class="lf-font-70 lf-font-bold">{{item.discount.action_type.value}}</text>
  130. <text>%</text>
  131. </view>
  132. <view class="coupon-tag" v-if="item.used_at != ''">
  133. 已使用
  134. </view>
  135. <view class="coupon-tag" v-if="item.ifpast">
  136. 已过期
  137. </view>
  138. <view class="coupon-tag" v-if="!item.ifpast && item.used_at == ''">
  139. 待使用
  140. </view>
  141. </view>
  142. <view class="coupon-right">
  143. <view class="lf-font-32 lf-font-bold lf-color-white">{{item.discount.title}}</view>
  144. <view class="lf-font-24 lf-color-white">有效期{{item.discount.starts_at}}~{{item.discount.ends_at}}</view>
  145. </view>
  146. </view>
  147. </view>
  148. </view>
  149. <!-- 不使用优惠券 -->
  150. <view class="lf-flex">
  151. <radio-group @change="couponChange">
  152. <radio value="null" :checked="coupon_index == null"></radio>
  153. </radio-group>
  154. <view>不使用优惠券</view>
  155. </view>
  156. </view>
  157. </u-popup>
  158. </block>
  159. </view>
  160. </template>
  161. <script>
  162. import Bigc from '@/common/js/bigc.js';
  163. export default {
  164. data(){
  165. return {
  166. mode: 0, // 0邮寄,1自提
  167. value: '', // 备注
  168. token: '',
  169. address: {},
  170. address_id: null,
  171. order_detail: {},
  172. show_coupon: false,
  173. coupon_index: null,
  174. goods_type: 1,
  175. itemsPrice: 0, // 商品金额(所有商品之和,但不包括额外费用及优惠)
  176. totalPrice: 0 ,// 合计价格
  177. clickContinue: true
  178. }
  179. },
  180. computed: {
  181. showCouponTitle(){
  182. let order_detail = this.order_detail;
  183. if(typeof order_detail.coupons == 'undefined'){
  184. order_detail.coupons = [];
  185. }
  186. if(this.coupon_index != null){
  187. return order_detail.coupons[this.coupon_index].discount.title;
  188. }else{
  189. if(order_detail.coupons.length){
  190. return '不使用优惠券';
  191. }else{
  192. return '暂无可用优惠券';
  193. }
  194. }
  195. },
  196. fullMinus(){
  197. return function(arr){
  198. if(this.$isRight(arr)){
  199. let price = arr[0].adjustmentTotal;
  200. let adjustmentTotal = new Bigc(price).div(100);
  201. return Math.abs(adjustmentTotal);
  202. }else{
  203. return 0
  204. }
  205. }
  206. }
  207. },
  208. onLoad(e){
  209. this.token = this.$cookieStorage.get('user_token');
  210. this.goods_type = e.goods_type;
  211. console.log('积分类型',e)
  212. let options = this.$cookieStorage.get('order_confirm');
  213. if(this.$isRight(options)){
  214. this.orderCheckout(options);
  215. }
  216. },
  217. onUnload(){
  218. this.$cookieStorage.clear('order_confirm');
  219. },
  220. onShow(){
  221. if(this.address_id){
  222. this.getSelectAddress();
  223. }
  224. },
  225. methods: {
  226. // 生成临时订单
  227. orderCheckout(options){
  228. uni.showLoading({
  229. title: '正在生成订单'
  230. })
  231. this.$http.post({
  232. api: 'api/shopping/order/checkout',
  233. data: options,
  234. header: {
  235. Authorization: this.token
  236. }
  237. }).then(res => {
  238. if(res.data.code == 200){
  239. let detail = res.data.data;
  240. this.order_detail = detail;
  241. this.address = res.data.data.address;
  242. if(this.$isRight(detail.coupons)){
  243. this.coupon_index = 0;
  244. }
  245. this.calcAmount();
  246. }else{
  247. this.$msg(res.data.message || '生成订单失败').then(() => {
  248. this.$toBack();
  249. })
  250. }
  251. uni.hideLoading()
  252. }).catch(err => uni.hideLoading())
  253. },
  254. // 单位转换金额
  255. unitConversion(price){
  256. let newPrice = new Bigc(price).div(100);
  257. return Math.abs(newPrice);
  258. },
  259. // 计算金额
  260. calcAmount(){
  261. let detail = this.order_detail;
  262. let items = detail.order.items || [];
  263. let itemsPrice = new Bigc(0);
  264. // 所有商品总计
  265. items.map(item => {
  266. let price = new Bigc(item.unit_price).div(100);
  267. let itemP = price.times(item.quantity);
  268. itemsPrice = itemsPrice.plus(itemP);
  269. })
  270. this.itemsPrice = itemsPrice;
  271. // 减去优惠券的价格
  272. if(this.coupon_index != null){
  273. let coupon = detail.coupons[this.coupon_index];
  274. let adjustmentTotal = new Bigc(coupon.adjustmentTotal).div(100); // 得到负数
  275. itemsPrice = itemsPrice.plus(adjustmentTotal); // 加一个负数等于减去的优惠
  276. }
  277. // 减去满减优惠
  278. if(this.$isRight(detail.discounts)){
  279. let discount = detail.discounts[0];
  280. let adjustmentTotal = new Bigc(discount.adjustmentTotal).div(100); // 得到负数
  281. itemsPrice = itemsPrice.plus(adjustmentTotal); // 加一个负数等于减去的优惠
  282. }
  283. // 如果为邮寄订单时,加上运费
  284. if(this.mode == 0){
  285. let payable_freight = new Bigc(detail.order.payable_freight).div(100);
  286. itemsPrice = itemsPrice.plus(payable_freight);
  287. }
  288. this.totalPrice = itemsPrice; // 合计价格
  289. },
  290. // 切换订单是邮寄还是自提
  291. switchMode(mode){
  292. this.mode = mode;
  293. this.calcAmount();
  294. },
  295. // 获取默认地址
  296. getDefaultAddress(){
  297. this.$http.get({
  298. api: 'api/address/default',
  299. header: {
  300. Authorization: this.token
  301. }
  302. }).then(res => {
  303. this.address = res.data.data || {};
  304. })
  305. },
  306. // 获取用户自己选择的地址
  307. getSelectAddress(){
  308. this.$http.get({
  309. api: 'api/address/'+ this.address_id,
  310. header: {
  311. Authorization: this.token
  312. }
  313. }).then(res => {
  314. this.address = res.data.data || {};
  315. })
  316. },
  317. // 打开选择优惠券
  318. openCheckCoupon(){
  319. if(this.order_detail.coupons.length){
  320. this.show_coupon = true;
  321. }else{
  322. this.$msg('您没有可用的优惠券哦');
  323. }
  324. },
  325. // 提交订单
  326. confirm(){
  327. console.log(this.address)
  328. if(this.clickContinue == true) {
  329. this.clickContinue = false;
  330. if(this.address == null) {
  331. this.$msg('请先添加收货地址!');
  332. return
  333. }
  334. let par = {
  335. order_no: this.order_detail.order.order_no,
  336. pick_self: this.mode, // 0 配送,1自提
  337. address_id: this.address.id,
  338. note: this.value,
  339. }
  340. // 是否选择了优惠券 TODO 优惠券id是否传对?
  341. if(this.coupon_index != null){
  342. par.coupon_id = this.order_detail.coupons[this.coupon_index].id;
  343. }
  344. this.$http.post({
  345. api: 'api/shopping/order/confirm',
  346. data: par,
  347. header: {
  348. Authorization: this.token
  349. }
  350. }).then(res => {
  351. if(res.data.code == 200 || res.data.code == true){
  352. let order = res.data.data.order;
  353. let url = '/pages/order/cashier/cashier';
  354. url += '?amount='+ this.totalPrice;
  355. url += '&order_no='+ order.order_no;
  356. this.$cookieStorage.set('last_pay_time', order.last_pay_time);
  357. this.$url(url, {type: 'redirect'});
  358. this.clickContinue = true;
  359. }else{
  360. this.$msg(res.data.message);
  361. this.clickContinue = true;
  362. }
  363. })
  364. }
  365. },
  366. // 选择优惠券
  367. couponChange(event){
  368. if(event.detail.value == 'null'){
  369. this.coupon_index = null;
  370. }else{
  371. this.coupon_index = Number(event.detail.value);
  372. }
  373. this.show_coupon = false;
  374. this.calcAmount();
  375. }
  376. }
  377. }
  378. </script>
  379. <style>
  380. page{
  381. background-color: #F8F8F8;
  382. }
  383. </style>
  384. <style lang="scss" scoped="scoped">
  385. .card{
  386. height: max-content;
  387. width: 750rpx;
  388. padding: 30rpx 32rpx;
  389. background-color: #FFFFFF;
  390. }
  391. .head{
  392. .capsule{
  393. width: 614rpx;
  394. height: 100rpx;
  395. margin: 30rpx auto 0;
  396. border-radius: 100px;
  397. border: 2rpx solid #15716E;
  398. display: flex;
  399. overflow: hidden;
  400. .item{
  401. width: 50%;
  402. display: flex;
  403. justify-content: center;
  404. align-items: center;
  405. font-size: 32rpx;
  406. font-weight: bold;
  407. color: #15716E;
  408. }
  409. .capsule-active{
  410. background-color: #15716E;
  411. color: #FFFFFF;
  412. }
  413. }
  414. }
  415. .address{
  416. margin-top: 20rpx;
  417. }
  418. .goods{
  419. margin-top: 20rpx;
  420. .shop-name{
  421. font-size: 28rpx;
  422. color: #222222;
  423. font-weight: bold;
  424. margin: 0 15rpx;
  425. }
  426. .goods-img{
  427. width: 130rpx;
  428. height: 130rpx;
  429. border-radius: 4rpx;
  430. margin-right: 15rpx;
  431. background-color: #EEEEEE;
  432. }
  433. .info{
  434. width: 540rpx;
  435. height: 130rpx;
  436. display: flex;
  437. flex-direction: column;
  438. justify-content: space-around;
  439. .price{
  440. font-size: 32rpx;
  441. color: #F63434;
  442. font-weight: bold;
  443. }
  444. }
  445. .tips{
  446. font-size: 22rpx;
  447. margin-top: 30rpx;
  448. color: #15716E;
  449. }
  450. .input{
  451. margin-left: 30rpx;
  452. font-size: 28rpx;
  453. width: 596rpx;
  454. }
  455. }
  456. .spread-out{
  457. height: 138rpx;
  458. padding-bottom: constant(safe-area-inset-bottom);
  459. padding-bottom: env(safe-area-inset-bottom);
  460. box-sizing: content-box;
  461. }
  462. .fixed-bottom{
  463. position: fixed;
  464. left: 0;
  465. bottom: 0;
  466. width: 750rpx;
  467. height: max-content;
  468. background-color: #FFFFFF;
  469. border-top: 1rpx solid #e5e5e5;
  470. padding-bottom: constant(safe-area-inset-bottom);
  471. padding-bottom: env(safe-area-inset-bottom);
  472. .fixed-content{
  473. width: 100%;
  474. height: 118rpx;
  475. padding: 0 32rpx;
  476. display: flex;
  477. align-items: center;
  478. justify-content: space-between;
  479. .confirm-btn{
  480. width: 167rpx;
  481. height: 80rpx;
  482. background: #15716E;
  483. border-radius: 40rpx;
  484. color: #FFFFFF;
  485. display: flex;
  486. justify-content: center;
  487. align-items: center;
  488. margin-left: 30rpx;
  489. font-size: 26rpx;
  490. }
  491. }
  492. }
  493. .popup-content{
  494. width: 750rpx;
  495. height: max-content;
  496. max-height: 70vh;
  497. overflow-y: scroll;
  498. padding: 40rpx 32rpx;
  499. background: #FFFFFF;
  500. }
  501. .coupon-circle1 {
  502. width: 40rpx;
  503. height: 40rpx;
  504. background-color: white;
  505. border-radius: 50%;
  506. }
  507. .coupon-circle-top {
  508. width: 50rpx;
  509. height: 50rpx;
  510. border-radius: 50%;
  511. // background-color: red;
  512. position: absolute;
  513. border: 1px dashed #ccc;
  514. left: 190rpx;
  515. top: -20rpx;
  516. display: flex;
  517. align-items: center;
  518. text-align: center;
  519. justify-content: center;
  520. }
  521. .coupon-circle-bottom {
  522. width: 50rpx;
  523. height: 50rpx;
  524. border-radius: 50%;
  525. // background-color: red;
  526. position: absolute;
  527. border: 1px dashed #ccc;
  528. left: 190rpx;
  529. bottom: -20rpx;
  530. display: flex;
  531. align-items: center;
  532. text-align: center;
  533. justify-content: center;
  534. }
  535. .coupon-right {
  536. text-align: left;
  537. justify-content: center;
  538. align-items: flex-start;
  539. display: flex;
  540. flex-direction: column;
  541. margin-left: 90rpx;
  542. }
  543. .coupon-left {
  544. margin-left: 30rpx;
  545. display: flex;
  546. flex-direction: column;
  547. justify-content: center;
  548. align-items: center;
  549. }
  550. .coupon-tag {
  551. width: max-content;
  552. margin-top: 10rpx;
  553. padding: 0 24rpx;
  554. height: 43rpx;
  555. border-radius: 22rpx;
  556. border: 2rpx solid #FFFFFF;
  557. font-size: 24rpx;
  558. color: white;
  559. }
  560. .coupon-wrap {
  561. display: flex;
  562. justify-content: center;
  563. margin-top: 30rpx;
  564. flex-direction: column;
  565. align-content: center;
  566. align-items: center;
  567. }
  568. .coupon-card {
  569. overflow: hidden;
  570. position: relative;
  571. display: flex;
  572. align-items: center;
  573. justify-content: center;
  574. // width: 674rpx;
  575. width: 626rpx;
  576. height: 171rpx;
  577. background: #15716E;
  578. border-radius: 20rpx;
  579. }
  580. .invalid-bg{
  581. background-color: #999999;
  582. }
  583. .coupon-radius {
  584. // width: 664rpx;
  585. width: 616rpx;
  586. display: flex;
  587. height: 161rpx;
  588. border: 1rpx dashed #ccc;
  589. // background: #15716E;
  590. border-radius: 20rpx;
  591. }
  592. /deep/.u-scroll-box {
  593. display: flex;
  594. justify-content: center;
  595. align-items: center;
  596. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  597. }
  598. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  599. background-color: #15716E!important;
  600. width: 80rpx!important;
  601. position: absolute;
  602. height: 10rpx;
  603. left: 0;
  604. border-radius: 8rpx 8rpx 0px 0px!important;
  605. bottom: -12rpx;
  606. }
  607. /deep/ .u-tab-item {
  608. font-size: 28rpx!important;
  609. }
  610. </style>