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

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