金诚优选前端代码
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.

614 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.$url(url, {type: 'redirect'});
  357. this.clickContinue = true;
  358. }else{
  359. this.$msg(res.data.message);
  360. this.clickContinue = true;
  361. }
  362. })
  363. }
  364. },
  365. // 选择优惠券
  366. couponChange(event){
  367. if(event.detail.value == 'null'){
  368. this.coupon_index = null;
  369. }else{
  370. this.coupon_index = Number(event.detail.value);
  371. }
  372. this.show_coupon = false;
  373. this.calcAmount();
  374. }
  375. }
  376. }
  377. </script>
  378. <style>
  379. page{
  380. background-color: #F8F8F8;
  381. }
  382. </style>
  383. <style lang="scss" scoped="scoped">
  384. .card{
  385. height: max-content;
  386. width: 750rpx;
  387. padding: 30rpx 32rpx;
  388. background-color: #FFFFFF;
  389. }
  390. .head{
  391. .capsule{
  392. width: 614rpx;
  393. height: 100rpx;
  394. margin: 30rpx auto 0;
  395. border-radius: 100px;
  396. border: 2rpx solid #15716E;
  397. display: flex;
  398. overflow: hidden;
  399. .item{
  400. width: 50%;
  401. display: flex;
  402. justify-content: center;
  403. align-items: center;
  404. font-size: 32rpx;
  405. font-weight: bold;
  406. color: #15716E;
  407. }
  408. .capsule-active{
  409. background-color: #15716E;
  410. color: #FFFFFF;
  411. }
  412. }
  413. }
  414. .address{
  415. margin-top: 20rpx;
  416. }
  417. .goods{
  418. margin-top: 20rpx;
  419. .shop-name{
  420. font-size: 28rpx;
  421. color: #222222;
  422. font-weight: bold;
  423. margin: 0 15rpx;
  424. }
  425. .goods-img{
  426. width: 130rpx;
  427. height: 130rpx;
  428. border-radius: 4rpx;
  429. margin-right: 15rpx;
  430. background-color: #EEEEEE;
  431. }
  432. .info{
  433. width: 540rpx;
  434. height: 130rpx;
  435. display: flex;
  436. flex-direction: column;
  437. justify-content: space-around;
  438. .price{
  439. font-size: 32rpx;
  440. color: #F63434;
  441. font-weight: bold;
  442. }
  443. }
  444. .tips{
  445. font-size: 22rpx;
  446. margin-top: 30rpx;
  447. color: #15716E;
  448. }
  449. .input{
  450. margin-left: 30rpx;
  451. font-size: 28rpx;
  452. width: 596rpx;
  453. }
  454. }
  455. .spread-out{
  456. height: 138rpx;
  457. padding-bottom: constant(safe-area-inset-bottom);
  458. padding-bottom: env(safe-area-inset-bottom);
  459. box-sizing: content-box;
  460. }
  461. .fixed-bottom{
  462. position: fixed;
  463. left: 0;
  464. bottom: 0;
  465. width: 750rpx;
  466. height: max-content;
  467. background-color: #FFFFFF;
  468. border-top: 1rpx solid #e5e5e5;
  469. padding-bottom: constant(safe-area-inset-bottom);
  470. padding-bottom: env(safe-area-inset-bottom);
  471. .fixed-content{
  472. width: 100%;
  473. height: 118rpx;
  474. padding: 0 32rpx;
  475. display: flex;
  476. align-items: center;
  477. justify-content: space-between;
  478. .confirm-btn{
  479. width: 167rpx;
  480. height: 80rpx;
  481. background: #15716E;
  482. border-radius: 40rpx;
  483. color: #FFFFFF;
  484. display: flex;
  485. justify-content: center;
  486. align-items: center;
  487. margin-left: 30rpx;
  488. font-size: 26rpx;
  489. }
  490. }
  491. }
  492. .popup-content{
  493. width: 750rpx;
  494. height: max-content;
  495. max-height: 70vh;
  496. overflow-y: scroll;
  497. padding: 40rpx 32rpx;
  498. background: #FFFFFF;
  499. }
  500. .coupon-circle1 {
  501. width: 40rpx;
  502. height: 40rpx;
  503. background-color: white;
  504. border-radius: 50%;
  505. }
  506. .coupon-circle-top {
  507. width: 50rpx;
  508. height: 50rpx;
  509. border-radius: 50%;
  510. // background-color: red;
  511. position: absolute;
  512. border: 1px dashed #ccc;
  513. left: 190rpx;
  514. top: -20rpx;
  515. display: flex;
  516. align-items: center;
  517. text-align: center;
  518. justify-content: center;
  519. }
  520. .coupon-circle-bottom {
  521. width: 50rpx;
  522. height: 50rpx;
  523. border-radius: 50%;
  524. // background-color: red;
  525. position: absolute;
  526. border: 1px dashed #ccc;
  527. left: 190rpx;
  528. bottom: -20rpx;
  529. display: flex;
  530. align-items: center;
  531. text-align: center;
  532. justify-content: center;
  533. }
  534. .coupon-right {
  535. text-align: left;
  536. justify-content: center;
  537. align-items: flex-start;
  538. display: flex;
  539. flex-direction: column;
  540. margin-left: 90rpx;
  541. }
  542. .coupon-left {
  543. margin-left: 30rpx;
  544. display: flex;
  545. flex-direction: column;
  546. justify-content: center;
  547. align-items: center;
  548. }
  549. .coupon-tag {
  550. width: max-content;
  551. margin-top: 10rpx;
  552. padding: 0 24rpx;
  553. height: 43rpx;
  554. border-radius: 22rpx;
  555. border: 2rpx solid #FFFFFF;
  556. font-size: 24rpx;
  557. color: white;
  558. }
  559. .coupon-wrap {
  560. display: flex;
  561. justify-content: center;
  562. margin-top: 30rpx;
  563. flex-direction: column;
  564. align-content: center;
  565. align-items: center;
  566. }
  567. .coupon-card {
  568. overflow: hidden;
  569. position: relative;
  570. display: flex;
  571. align-items: center;
  572. justify-content: center;
  573. // width: 674rpx;
  574. width: 626rpx;
  575. height: 171rpx;
  576. background: #15716E;
  577. border-radius: 20rpx;
  578. }
  579. .invalid-bg{
  580. background-color: #999999;
  581. }
  582. .coupon-radius {
  583. // width: 664rpx;
  584. width: 616rpx;
  585. display: flex;
  586. height: 161rpx;
  587. border: 1rpx dashed #ccc;
  588. // background: #15716E;
  589. border-radius: 20rpx;
  590. }
  591. /deep/.u-scroll-box {
  592. display: flex;
  593. justify-content: center;
  594. align-items: center;
  595. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  596. }
  597. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  598. background-color: #15716E!important;
  599. width: 80rpx!important;
  600. position: absolute;
  601. height: 10rpx;
  602. left: 0;
  603. border-radius: 8rpx 8rpx 0px 0px!important;
  604. bottom: -12rpx;
  605. }
  606. /deep/ .u-tab-item {
  607. font-size: 28rpx!important;
  608. }
  609. </style>