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

607 lines
17 KiB

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