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

536 lines
14 KiB

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="mode = 0">邮寄</view>
  9. <view class="item" :class="{'capsule-active': mode == 1}" @click="mode = 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 @click="$url('/pages/address/list/list?is_select=1')">
  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">
  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">¥{{ item.total_yuan }}</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">¥{{ order_detail.order.items_total_yuan }}</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 }}</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;">-¥{{ order_detail.order.adjustments_total_yuan }}</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;">合计 ¥{{ totalPrice }}</view>
  98. <view class="confirm-btn" hover-class="lf-opacity" @click="confirm">提交订单</view>
  99. </view>
  100. </view>
  101. </view>
  102. <!-- 选择优惠券弹出层 -->
  103. <u-popup v-model="show_coupon" mode="bottom" :round="true" borderRadius="20">
  104. <view class="popup-content">
  105. <view class="lf-row-between" v-for="(item, index) in order_detail.coupons" :key="index">
  106. <radio-group @change="couponChange">
  107. <radio :value="index" :checked="coupon_index == index"></radio>
  108. </radio-group>
  109. <view class="coupon-card lf-m-b-30" :class="{'invalid-bg': item.ifpast == true}">
  110. <view class="coupon-circle-top">
  111. <view class="coupon-circle1"></view>
  112. </view>
  113. <view class="coupon-circle-bottom">
  114. <view class="coupon-circle1"></view>
  115. </view>
  116. <view class="coupon-radius">
  117. <view class="coupon-left">
  118. <view class="lf-font-36 lf-color-white" style="line-height: 1;" v-if="item.discount.action_type.type == 'cash'">
  119. <text></text>
  120. <text class="lf-font-70 lf-font-bold">{{item.discount.action_type.value}}</text>
  121. </view>
  122. <view class="lf-font-36 lf-color-white" style="line-height: 1;" v-if="item.discount.action_type.type == 'discount'">
  123. <text class="lf-font-70 lf-font-bold">{{item.discount.action_type.value}}</text>
  124. <text>%</text>
  125. </view>
  126. <view class="coupon-tag" v-if="item.used_at != ''">
  127. 已使用
  128. </view>
  129. <view class="coupon-tag" v-if="item.ifpast">
  130. 已过期
  131. </view>
  132. <view class="coupon-tag" v-if="!item.ifpast && item.used_at == ''">
  133. 待使用
  134. </view>
  135. </view>
  136. <view class="coupon-right">
  137. <view class="lf-font-32 lf-font-bold lf-color-white">{{item.discount.title}}</view>
  138. <view class="lf-font-24 lf-color-white">有效期{{item.discount.starts_at}}~{{item.discount.ends_at}}</view>
  139. </view>
  140. </view>
  141. </view>
  142. </view>
  143. <!-- 不使用优惠券 -->
  144. <view class="lf-flex">
  145. <radio-group @change="couponChange">
  146. <radio value="null" :checked="coupon_index == null"></radio>
  147. </radio-group>
  148. <view>不使用优惠券</view>
  149. </view>
  150. </view>
  151. </u-popup>
  152. </block>
  153. </view>
  154. </template>
  155. <script>
  156. import Bigc from '@/common/js/bigc.js';
  157. export default {
  158. data(){
  159. return {
  160. mode: 0, // 0邮寄,1自提
  161. value: '', // 备注
  162. token: '',
  163. address: {},
  164. address_id: null,
  165. order_detail: {coupons: []},
  166. show_coupon: false,
  167. coupon_index: null
  168. }
  169. },
  170. computed: {
  171. showCouponTitle(){
  172. if(this.coupon_index != null){
  173. return this.order_detail.coupons[this.coupon_index].discount.title;
  174. }else{
  175. if(this.order_detail.coupons.length){
  176. return '不使用优惠券';
  177. }else{
  178. return '暂无可用优惠券';
  179. }
  180. }
  181. },
  182. totalPrice(){
  183. let order = this.order_detail.order;
  184. if(!this.$isRight(order)){
  185. return 0;
  186. }
  187. if(this.mode){
  188. return order.total_yuan;
  189. }else{
  190. return new Bigc(order.total_yuan).plus(order.payable_freight);
  191. }
  192. }
  193. },
  194. onLoad(){
  195. this.token = this.$cookieStorage.get('user_token');
  196. let options = this.$cookieStorage.get('order_confirm');
  197. if(this.$isRight(options)){
  198. this.orderCheckout(options);
  199. }
  200. },
  201. onUnload(){
  202. this.$cookieStorage.clear('order_confirm');
  203. },
  204. onShow(){
  205. if(this.address_id){
  206. this.getSelectAddress();
  207. }
  208. },
  209. methods: {
  210. // 生成临时订单
  211. orderCheckout(options){
  212. uni.showLoading({
  213. title: '正在生成订单'
  214. })
  215. this.$http.post({
  216. api: 'api/shopping/order/checkout',
  217. data: options,
  218. header: {
  219. Authorization: this.token
  220. }
  221. }).then(res => {
  222. let detail = res.data.data;
  223. this.order_detail = detail;
  224. this.address = res.data.data.address;
  225. uni.hideLoading()
  226. }).catch(err => uni.hideLoading())
  227. },
  228. // 获取默认地址
  229. getDefaultAddress(){
  230. this.$http.get({
  231. api: 'api/address/default',
  232. header: {
  233. Authorization: this.token
  234. }
  235. }).then(res => {
  236. this.address = res.data.data || {};
  237. })
  238. },
  239. // 获取用户自己选择的地址
  240. getSelectAddress(){
  241. this.$http.get({
  242. api: 'api/address/'+ this.address_id,
  243. header: {
  244. Authorization: this.token
  245. }
  246. }).then(res => {
  247. this.address = res.data.data || {};
  248. })
  249. },
  250. // 打开选择优惠券
  251. openCheckCoupon(){
  252. if(this.order_detail.coupons.length){
  253. this.show_coupon = true;
  254. }else{
  255. this.$msg('您没有可用的优惠券哦');
  256. }
  257. },
  258. // 提交订单
  259. confirm(){
  260. console.log(this.address)
  261. if(this.address == null) {
  262. this.$msg('请先添加收货地址!');
  263. return
  264. }
  265. this.$http.post({
  266. api: 'api/shopping/order/confirm',
  267. data: {
  268. order_no: this.order_detail.order.order_no,
  269. // discount_id: 0, // 优惠券id? TODO
  270. pick_self: this.mode, // 0 配送,1自提
  271. address_id: this.address.id,
  272. note: this.value
  273. },
  274. header: {
  275. Authorization: this.token
  276. }
  277. }).then(res => {
  278. console.log("`````````", res);
  279. if(res.data.code == 200 || res.data.code == true){
  280. let order = res.data.data.order;
  281. let url = '/pages/order/cashier/cashier';
  282. url += '?amount='+ order.total_yuan;
  283. url += '&order_no='+ order.order_no;
  284. this.$url(url, {type: 'redirect'});
  285. }else{
  286. this.$msg(res.data.message);
  287. }
  288. })
  289. },
  290. // 选择优惠券
  291. couponChange(event){
  292. if(event.detail.value == 'null'){
  293. this.coupon_index = null;
  294. }else{
  295. this.coupon_index = Number(event.detail.value);
  296. }
  297. }
  298. }
  299. }
  300. </script>
  301. <style>
  302. page{
  303. background-color: #F8F8F8;
  304. }
  305. </style>
  306. <style lang="scss" scoped="scoped">
  307. .card{
  308. height: max-content;
  309. width: 750rpx;
  310. padding: 30rpx 32rpx;
  311. background-color: #FFFFFF;
  312. }
  313. .head{
  314. .capsule{
  315. width: 614rpx;
  316. height: 100rpx;
  317. margin: 30rpx auto 0;
  318. border-radius: 100px;
  319. border: 2rpx solid #15716E;
  320. display: flex;
  321. overflow: hidden;
  322. .item{
  323. width: 50%;
  324. display: flex;
  325. justify-content: center;
  326. align-items: center;
  327. font-size: 32rpx;
  328. font-weight: bold;
  329. color: #15716E;
  330. }
  331. .capsule-active{
  332. background-color: #15716E;
  333. color: #FFFFFF;
  334. }
  335. }
  336. }
  337. .address{
  338. margin-top: 20rpx;
  339. }
  340. .goods{
  341. margin-top: 20rpx;
  342. .shop-name{
  343. font-size: 28rpx;
  344. color: #222222;
  345. font-weight: bold;
  346. margin: 0 15rpx;
  347. }
  348. .goods-img{
  349. width: 130rpx;
  350. height: 130rpx;
  351. border-radius: 4rpx;
  352. margin-right: 15rpx;
  353. background-color: #EEEEEE;
  354. }
  355. .info{
  356. width: 540rpx;
  357. height: 130rpx;
  358. display: flex;
  359. flex-direction: column;
  360. justify-content: space-around;
  361. .price{
  362. font-size: 32rpx;
  363. color: #F63434;
  364. font-weight: bold;
  365. }
  366. }
  367. .tips{
  368. font-size: 22rpx;
  369. margin-top: 30rpx;
  370. color: #15716E;
  371. }
  372. .input{
  373. margin-left: 30rpx;
  374. font-size: 28rpx;
  375. width: 596rpx;
  376. }
  377. }
  378. .spread-out{
  379. height: 138rpx;
  380. padding-bottom: constant(safe-area-inset-bottom);
  381. padding-bottom: env(safe-area-inset-bottom);
  382. box-sizing: content-box;
  383. }
  384. .fixed-bottom{
  385. position: fixed;
  386. left: 0;
  387. bottom: 0;
  388. width: 750rpx;
  389. height: max-content;
  390. background-color: #FFFFFF;
  391. border-top: 1rpx solid #e5e5e5;
  392. padding-bottom: constant(safe-area-inset-bottom);
  393. padding-bottom: env(safe-area-inset-bottom);
  394. .fixed-content{
  395. width: 100%;
  396. height: 118rpx;
  397. padding: 0 32rpx;
  398. display: flex;
  399. align-items: center;
  400. justify-content: space-between;
  401. .confirm-btn{
  402. width: 167rpx;
  403. height: 80rpx;
  404. background: #15716E;
  405. border-radius: 40rpx;
  406. color: #FFFFFF;
  407. display: flex;
  408. justify-content: center;
  409. align-items: center;
  410. margin-left: 30rpx;
  411. font-size: 26rpx;
  412. }
  413. }
  414. }
  415. .popup-content{
  416. width: 750rpx;
  417. height: max-content;
  418. max-height: 70vh;
  419. overflow-y: scroll;
  420. padding: 40rpx 32rpx;
  421. background: #FFFFFF;
  422. }
  423. .coupon-circle1 {
  424. width: 40rpx;
  425. height: 40rpx;
  426. background-color: white;
  427. border-radius: 50%;
  428. }
  429. .coupon-circle-top {
  430. width: 50rpx;
  431. height: 50rpx;
  432. border-radius: 50%;
  433. // background-color: red;
  434. position: absolute;
  435. border: 1px dashed #ccc;
  436. left: 190rpx;
  437. top: -20rpx;
  438. display: flex;
  439. align-items: center;
  440. text-align: center;
  441. justify-content: center;
  442. }
  443. .coupon-circle-bottom {
  444. width: 50rpx;
  445. height: 50rpx;
  446. border-radius: 50%;
  447. // background-color: red;
  448. position: absolute;
  449. border: 1px dashed #ccc;
  450. left: 190rpx;
  451. bottom: -20rpx;
  452. display: flex;
  453. align-items: center;
  454. text-align: center;
  455. justify-content: center;
  456. }
  457. .coupon-right {
  458. text-align: left;
  459. justify-content: center;
  460. align-items: flex-start;
  461. display: flex;
  462. flex-direction: column;
  463. margin-left: 90rpx;
  464. }
  465. .coupon-left {
  466. margin-left: 30rpx;
  467. display: flex;
  468. flex-direction: column;
  469. justify-content: center;
  470. align-items: center;
  471. }
  472. .coupon-tag {
  473. width: max-content;
  474. margin-top: 10rpx;
  475. padding: 0 24rpx;
  476. height: 43rpx;
  477. border-radius: 22rpx;
  478. border: 2rpx solid #FFFFFF;
  479. font-size: 24rpx;
  480. color: white;
  481. }
  482. .coupon-wrap {
  483. display: flex;
  484. justify-content: center;
  485. margin-top: 30rpx;
  486. flex-direction: column;
  487. align-content: center;
  488. align-items: center;
  489. }
  490. .coupon-card {
  491. overflow: hidden;
  492. position: relative;
  493. display: flex;
  494. align-items: center;
  495. justify-content: center;
  496. // width: 674rpx;
  497. width: 626rpx;
  498. height: 171rpx;
  499. background: #15716E;
  500. border-radius: 20rpx;
  501. }
  502. .invalid-bg{
  503. background-color: #999999;
  504. }
  505. .coupon-radius {
  506. // width: 664rpx;
  507. width: 616rpx;
  508. display: flex;
  509. height: 161rpx;
  510. border: 1rpx dashed #ccc;
  511. // background: #15716E;
  512. border-radius: 20rpx;
  513. }
  514. /deep/.u-scroll-box {
  515. display: flex;
  516. justify-content: center;
  517. align-items: center;
  518. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  519. }
  520. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  521. background-color: #15716E!important;
  522. width: 80rpx!important;
  523. position: absolute;
  524. height: 10rpx;
  525. left: 0;
  526. border-radius: 8rpx 8rpx 0px 0px!important;
  527. bottom: -12rpx;
  528. }
  529. /deep/ .u-tab-item {
  530. font-size: 28rpx!important;
  531. }
  532. </style>