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

609 lines
17 KiB

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