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

603 lines
17 KiB

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