settleCenter.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <template>
  2. <view class="common-page">
  3. <!-- 地址选择区域,点击可触发地址选择 -->
  4. <view class="common-card-box">
  5. <view class="address-box" @click="selectAddress">
  6. <!-- 未选择地址时显示的提示 -->
  7. <view v-if="!mAddress || !mAddress.code" class="address-view">
  8. <view style="display: flex; align-items: center;">
  9. <van-image
  10. height="36rpx"
  11. src="/static/hd-if-b.png"
  12. width="36rpx"
  13. />
  14. <text class="t1" style="margin-top: 0; margin-left: 20rpx ;font-family: PingFang SC-Medium;">请选择收货地址</text>
  15. </view>
  16. </view>
  17. <!-- 已选择地址时显示具体地址信息 -->
  18. <view v-if="mAddress && mAddress.code" class="address-view">
  19. <view style="display: flex; align-items: center;">
  20. <van-image
  21. height="36rpx"
  22. src="/static/hd-if-b.png"
  23. width="36rpx"
  24. />
  25. <view style="margin-top: 0; margin-left: 34rpx ;font-family: PingFang SC-Medium;">
  26. <view class="t1" space="ensp">
  27. {{ mAddress.name }} {{ mAddress.phone }}
  28. </view>
  29. <br />
  30. <view class="t2" space="emsp">
  31. {{ mAddress.province }} {{ mAddress.city }}{{ mAddress.area }}{{ mAddress.address }}
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 右侧箭头图标,表示可以点击展开地址选择 -->
  37. <u-icon name="arrow-right" color="#AEAEAE" size="34rpx"></u-icon>
  38. </view>
  39. </view>
  40. <!-- 显示已选商品列表 -->
  41. <view class="common-card-box">
  42. <view class="goods-list display-flex-center" v-for="(item, index) in goodsList" :key="index">
  43. <!-- 商品图片 -->
  44. <image class="mr20" style="width: 176rpx; height: 176rpx; border-radius: 12rpx;flex-shrink: 0;"
  45. :src="item.goods_cover" mode="aspectFill">
  46. </image>
  47. <!-- 商品名称、规格和数量 -->
  48. <view class="list-info">
  49. <view class="fs14 fw400 color-333">{{item.goods_name}}</view>
  50. <view class="fw400 color-888 fs12 mt8 mb8">{{item.sku.goods_spec}}</view>
  51. <view class="display-flex-between">
  52. <text class="fw400 color-888 fs12 mb8">¥<text class="fw700 color-333 fs16 mb8">{{item.price_selling}}</text></text>
  53. <text>×{{ item.stock_sales }}</text>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 商品总价区域 -->
  58. <view class="goods-total display-flex-center">
  59. <view class="fs12 color-333 fw400">
  60. 共{{ orderData.number_goods }}件商品&nbsp;&nbsp; 总计:<text class=" fs12 fw400">¥</text><text class="fw700 fs20">{{orderData.amount_goods }}</text>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 运费显示区域 -->
  65. <view class="common-card good-card display-flex-between">
  66. <view>运费</view>
  67. <view>¥{{ orderData.amount_express || 0 }}</view>
  68. </view>
  69. <!-- 优惠券和积分使用区域 -->
  70. <template v-if="pageOptions.isGift != '1' && pageOptions.type != 'msGoods'">
  71. <view class="common-card good-card ">
  72. <!-- 优惠券选择 -->
  73. <view class="display-flex-between" @click="choseCoupon">
  74. <view>优惠券</view>
  75. <view class="display-flex">
  76. <view v-if="checkedCoupon.coupon_id" > 已选:{{ checkedCoupon.coupon_price }}元优惠券</view>
  77. <view class=" ml10">
  78. <u-icon name="arrow-right" color="#AEAEAE" size="34rpx"></u-icon>
  79. </view>
  80. </view>
  81. </view>
  82. <!-- 使用积分抵扣 -->
  83. <view class="display-flex-between mt15" v-if="usePointsFlag" >
  84. <view class="display-flex">使用 {{ pointsShowData.points }} 积分抵扣 <view class="color-556 ml5 mr5"> {{ pointsShowData.price }}</view>元</view>
  85. <u-checkbox-group v-model="usePoints" size="20" >
  86. <u-checkbox :disabled="pointsDisabled" activeColor="#C29556" name="points" shape="circle" label=" "></u-checkbox>
  87. </u-checkbox-group>
  88. </view>
  89. </view>
  90. </template>
  91. <!-- 留言区域 -->
  92. <view class="common-card good-card">
  93. <view class="fs14 mb10">留言</view>
  94. <u--textarea height="110" v-model="order_remark" placeholder="100字以内" maxlength="100" count></u--textarea>
  95. </view>
  96. <!-- 底部支付区域 -->
  97. <view class="bottom-box display-flex-end">
  98. <view>应付:<text class="color-556 fs12 fw400">¥</text><text class="fw700 fs20 color-556">{{payTotal}}</text></view>
  99. <view class="settle-center-btn" @click="toPay">去支付</view>
  100. </view>
  101. <!-- 优惠券选择弹窗 -->
  102. <u-popup :show="showCoupon" :round="10" mode="bottom" @close="showCoupon = false">
  103. <view class="coupon-list">
  104. <view class="popop-title text-center mb30">
  105. <text class="color-3 fw700 fs18">选择优惠券</text>
  106. <view class="float-right" @click="showCoupon = false">
  107. <u-icon name="close" bold="true" color="#8E8E8E" size="18"></u-icon>
  108. </view>
  109. </view>
  110. <!-- 优惠券列表 -->
  111. <couponItem v-for="item in couponList" :key="item.id" :data="item" :config="getItemConfig(item)"
  112. @on-click="handleItem(item)"/>
  113. </view>
  114. </u-popup>
  115. </view>
  116. </template>
  117. <script>
  118. import couponItem from '@/subPages/coupon/couponItem.vue'
  119. export default {
  120. components: {couponItem},
  121. data() {
  122. return {
  123. // 订单编号
  124. orderNo: '',
  125. // 页面选项
  126. pageOptions: {},
  127. // 优惠券弹窗显示标志
  128. showCoupon: false,
  129. // 优惠券列表
  130. couponList: [],
  131. // 收货地址
  132. mAddress: {},
  133. // 使用积分标志
  134. usePoints: [],
  135. // 订单备注
  136. order_remark: '',
  137. // 已选择的优惠券
  138. checkedCoupon: {},
  139. // 商品列表
  140. goodsList: [],
  141. // 订单数据,包括商品总价和运费等
  142. orderData: {amount_goods: 0, amount_express: 0},
  143. // 购物车商品ID列表
  144. cartIds: [],
  145. // 积分相关数据
  146. pointsData: {},
  147. // 积分显示数据
  148. pointsShowData: {price: 0, points: 0},
  149. // 使用积分标志
  150. usePointsFlag: true,
  151. }
  152. },
  153. computed: {
  154. // 计算支付总价
  155. payTotal() {
  156. const {amount_goods = 0, amount_express = 0} = this.orderData
  157. let result = Number(amount_goods) + Number(amount_express)
  158. if (this.checkedCoupon.coupon_id) {
  159. result = result - Number(this.checkedCoupon.coupon_price)
  160. }
  161. if (this.integral == 1) {
  162. result = result - Number(this.pointsShowData.price)
  163. }
  164. return result.toFixed(2)
  165. },
  166. // 计算使用的积分数量
  167. integral() {
  168. return this.usePoints.length
  169. },
  170. // 计算用户可用积分
  171. userPoints() {
  172. const {integral_total = 0, integral_used = 0} = JSON.parse(uni.getStorageSync('userInfo'))
  173. return integral_total - integral_used
  174. },
  175. // 积分使用限制判断
  176. pointsDisabled() {
  177. const {min_money, ratio, to_money} = this.pointsData
  178. return min_money > this.orderData.amount_goods
  179. },
  180. },
  181. watch: {
  182. // 监听积分使用变化
  183. integral(nv) {
  184. if (this.pageOptions.type != 'cart') {
  185. this.$api.orderUserPoints({order_no: this.orderNo, integral: nv})
  186. }
  187. },
  188. // 监听商品总价变化
  189. 'orderData.amount_goods'(nv) {
  190. if (nv) {
  191. if (this.pageOptions.type != 'cart') {
  192. this.$nextTick(() => {
  193. this.getPoints()
  194. })
  195. }
  196. }
  197. }
  198. },
  199. onLoad(options) {
  200. // 页面加载时获取订单编号和页面选项
  201. this.orderNo = options.orderNo
  202. this.pageOptions = options
  203. },
  204. onShow() {
  205. // 页面显示时根据类型获取数据
  206. const {type} = this.pageOptions
  207. if (type == 'cart') {
  208. this.getCartData()
  209. const selectAddress = uni.getStorageSync('selectAddress') || undefined
  210. if (selectAddress) {
  211. const tempAddress = JSON.parse(selectAddress)
  212. if (!this.mAddress.code || (this.mAddress && this.mAddress.code != tempAddress.code)) {
  213. this.mAddress = tempAddress
  214. this.getExpressFee()
  215. }
  216. uni.removeStorageSync('selectAddress')
  217. }else{
  218. this.getSelectAddress("cart")
  219. }
  220. } else {
  221. this.getCouponList()
  222. this.getOrderDetail()
  223. }
  224. },
  225. methods: {
  226. /**
  227. * 获取优惠券配置
  228. * @param {Object} item - 优惠券对象
  229. * @returns {Object} - 优惠券配置对象
  230. */
  231. getSelectAddress(type=""){
  232. this.$api.getAddressList().then(res => {
  233. // uni.hideLoading()
  234. let addressList = res.data || []
  235. for (let item of addressList) {
  236. if (item.type === 1) {
  237. uni.setStorageSync('selectAddress', JSON.stringify(item))
  238. const selectAddress = uni.getStorageSync('selectAddress') || undefined
  239. if (selectAddress) {
  240. const tempAddress = JSON.parse(selectAddress)
  241. if (!this.mAddress.code || (this.mAddress && this.mAddress.code != tempAddress.code)) {
  242. this.mAddress = tempAddress
  243. if (type==="cart"){
  244. this.getExpressFee()
  245. }else{
  246. this.addressConfirm()
  247. }
  248. }
  249. uni.removeStorageSync('selectAddress')
  250. }
  251. break
  252. }
  253. }
  254. })
  255. },
  256. getItemConfig(item) {
  257. let itemConfig = {
  258. btnText: '去使用',
  259. disabled: false,
  260. btnPlain: true
  261. }
  262. if (item.coupon_id == this.checkedCoupon.coupon_id) {
  263. itemConfig = {
  264. btnText: '取消使用',
  265. disabled: false,
  266. btnPlain: true
  267. }
  268. }
  269. return itemConfig
  270. },
  271. /**
  272. * 获取积分使用数据
  273. */
  274. getPoints() {
  275. this.$api.getPointsUseData().then(res => {
  276. if (!res.data.ratio) {
  277. this.usePointsFlag = false
  278. return
  279. } else {
  280. this.usePointsFlag = true
  281. }
  282. this.pointsData = res.data
  283. const {min_money, ratio, to_money} = this.pointsData
  284. const amount = this.orderData.amount_goods
  285. if (this.orderData.integral) {
  286. this.usePoints = ['points']
  287. let price = this.orderData.integral_price
  288. this.pointsShowData = {
  289. price: price.toFixed(2),
  290. points: Math.floor(price / to_money)
  291. }
  292. } else {
  293. let userPoints = 1000
  294. let price = Math.floor(amount * ratio / 100)
  295. let points = price * to_money
  296. points = this.userPoints > points ? points : this.userPoints
  297. price = points / to_money
  298. this.pointsShowData = {
  299. points: Math.floor(points),
  300. price: price.toFixed(2)
  301. }
  302. }
  303. })
  304. },
  305. /**
  306. * 获取购物车数据
  307. */
  308. getCartData() {
  309. this.cartIds = this.pageOptions.ids.split('_')
  310. this.$api.createPrevOrderByCart({id: this.cartIds}).then(res => {
  311. const {items, coupons, count_total, amount_total, integral = {}} = res.data
  312. this.goodsList = items.map(item => {
  313. const {goods_spec, price_selling} = item.sku
  314. item.stock_sales = item.num
  315. item = {
  316. goods_spec,
  317. price_selling,
  318. ...item
  319. }
  320. return item
  321. })
  322. this.couponList = coupons
  323. this.orderData.number_goods = count_total
  324. this.orderData.amount_goods = amount_total
  325. if (res.data.integral_use && res.data.integral_price) {
  326. this.usePointsFlag = true
  327. this.pointsShowData = {
  328. points: res.data.integral_use,
  329. price: (res.data.integral_price).toFixed(2)
  330. }
  331. } else {
  332. this.usePointsFlag = false
  333. }
  334. })
  335. },
  336. /**
  337. * 获取运费
  338. */
  339. getExpressFee() {
  340. this.$api.getPrevCartExpress({id: this.cartIds, addr_code: this.mAddress.code}).then(res => {
  341. this.orderData.amount_express = res.data
  342. })
  343. },
  344. /**
  345. * 前往支付
  346. */
  347. toPay() {
  348. if (!this.mAddress.code) {
  349. uni.showToast({
  350. title: '请选择收货地址'
  351. })
  352. return
  353. }
  354. if (this.pageOptions.type == 'cart') {
  355. const sendData = {
  356. id: this.cartIds,
  357. addr_code: this.mAddress.code,
  358. coupon_id: this.checkedCoupon.id,
  359. order_remark: this.order_remark,
  360. integral: this.integral
  361. }
  362. this.$api.createOrderByCart(sendData).then(res => {
  363. const {appId, nonceStr, paySign, signType, timeStamp} = res.data.param
  364. uni.requestPayment({
  365. provider: 'wxpay',
  366. nonceStr,
  367. package: res.data.param.package,
  368. paySign,
  369. signType,
  370. timeStamp,
  371. success: function (success) {
  372. uni.navigateTo({url: `/subPages/paySuccess/paySuccess?orderNo=${res.data.order.order_no}`})
  373. },
  374. fail: function (err) {
  375. uni.navigateTo({url: `/subPages/orderDetail/orderDetail?orderNo=${res.data.order.order_no}`})
  376. }
  377. })
  378. })
  379. } else {
  380. // uni.navigateTo({url: `/subPages/paySuccess/paySuccess?orderNo=${this.orderNo}`})
  381. this.$toWechatPay(this.orderNo, this.order_remark)
  382. }
  383. },
  384. /**
  385. * 地址确认
  386. */
  387. addressConfirm() {
  388. this.$api.submitOrderByAdress({order_no: this.orderNo, code: this.mAddress.code}).then(res => {
  389. this.orderData.amount_express = res.data.amount
  390. })
  391. },
  392. /**
  393. * 选择优惠券
  394. */
  395. choseCoupon() {
  396. if (this.couponList.length) {
  397. this.showCoupon = true
  398. } else {
  399. uni.showToast({
  400. title: '暂无可使用优惠券',
  401. icon: 'none'
  402. })
  403. }
  404. },
  405. /**
  406. * 获取优惠券列表
  407. */
  408. getCouponList() {
  409. this.$api.getCouponByOrder({order_no: this.orderNo}).then(res => {
  410. this.couponList = res.data
  411. })
  412. },
  413. /**
  414. * 处理优惠券选择
  415. * @param {Object} item - 优惠券对象
  416. */
  417. handleItem(item) {
  418. this.showCoupon = false
  419. if (Number(item.coupon_price) > Number(this.orderData.amount_goods)) {
  420. uni.showToast({
  421. title: '无法使用该优惠券!',
  422. icon: 'none'
  423. })
  424. return;
  425. }
  426. if (item.coupon_id == this.checkedCoupon.coupon_id) {
  427. this.checkedCoupon = {id: 0, coupon_id: 0}
  428. } else {
  429. this.checkedCoupon = item
  430. }
  431. if (this.pageOptions.type != 'cart') {
  432. this.$api.submitOrderByCoupon({order_no: this.orderNo, id: this.checkedCoupon.id})
  433. }
  434. },
  435. /**
  436. * 获取订单详情
  437. */
  438. getOrderDetail() {
  439. this.$api.orderDetail({order_no: this.orderNo}).then(res => {
  440. this.goodsList = res.data.items || []
  441. this.orderData = res.data
  442. this.checkedCoupon = res.data.coupon || {}
  443. if (res.data.addr_code) {
  444. const {
  445. address_area,
  446. address_city,
  447. address_province,
  448. address_content,
  449. address_name,
  450. address_phone
  451. } = res.data.truck || {}
  452. this.mAddress = {
  453. code: res.data.addr_code,
  454. area: address_area,
  455. city: address_city,
  456. province: address_province,
  457. address: address_content,
  458. name: address_name,
  459. phone: address_phone
  460. }
  461. }
  462. const selectAddress = uni.getStorageSync('selectAddress') || undefined
  463. if (selectAddress) {
  464. const tempAddress = JSON.parse(selectAddress)
  465. if (!this.mAddress.code || (this.mAddress && this.mAddress.code != tempAddress.code)) {
  466. this.mAddress = tempAddress
  467. this.addressConfirm()
  468. }
  469. uni.removeStorageSync('selectAddress')
  470. }else{
  471. this.getSelectAddress()
  472. }
  473. })
  474. },
  475. /**
  476. * 选择地址
  477. */
  478. selectAddress() {
  479. uni.navigateTo({
  480. url: '/subPages/addressMg/addressMg?isBack=true'
  481. })
  482. }
  483. }
  484. }
  485. </script>
  486. <style lang="scss" scoped>
  487. .coupon-list {
  488. padding: 40rpx 20rpx;
  489. }
  490. .common-page {
  491. height: 100vh;
  492. overflow-y: auto;
  493. padding: 20rpx;
  494. color: #2C2C2C;
  495. padding-bottom: 188rpx;
  496. box-sizing: border-box;
  497. }
  498. .bottom-box {
  499. position: fixed;
  500. bottom: 0;
  501. width: 100%;
  502. height: 170rpx;
  503. left: 0;
  504. right: 0;
  505. box-sizing: border-box;
  506. padding: 27rpx 30rpx;
  507. background-color: #fff;
  508. z-index: 1000;
  509. border-radius: 24rpx 24rpx 0rpx 0rpx;
  510. }
  511. .settle-center-btn {
  512. height: 76rpx;
  513. line-height: 78rpx;
  514. width: 170rpx;
  515. padding: 0 29rpx;
  516. color: #fff;
  517. background: linear-gradient( 315deg, #CA9359 0%, #E2B98E 100%);
  518. border-radius: 292rpx 292rpx 292rpx 292rpx;
  519. font-size: 32rpx;
  520. text-align: center;
  521. margin-left: 30rpx;
  522. }
  523. .good-card {
  524. padding: 38rpx 22rpx;
  525. color: #7A7A7A;
  526. ::v-deep {
  527. .u-textarea {
  528. background: #F6F6F6;
  529. border-radius: 12rpx 12rpx 12rpx 12rpx;
  530. border: none;
  531. padding: 18rpx;
  532. .u-textarea__count {
  533. background-color: transparent !important;
  534. }
  535. }
  536. .u-checkbox__icon-wrap{
  537. margin-right: 0!important;
  538. }
  539. }
  540. }
  541. .goods-list {
  542. margin: 0 30rpx;
  543. padding: 30rpx 0;
  544. border-bottom: 1rpx solid #F5F5F5;
  545. .list-info {
  546. width: 100%;
  547. }
  548. }
  549. .goods-total {
  550. justify-content: flex-end;
  551. margin: 27rpx 20rpx;
  552. }
  553. .address-box {
  554. // width: 100%;
  555. display: flex;
  556. flex-direction: row;
  557. align-items: center;
  558. padding: 30rpx 22rpx;
  559. .address-view {
  560. flex: 1;
  561. display: flex;
  562. flex-direction: column;
  563. .t1 {
  564. font-size: 28rpx;
  565. margin-top: 10rpx;
  566. font-family: PingFang SC-Medium, PingFang SC;
  567. font-weight: 400;
  568. color: #333333;
  569. }
  570. .t2 {
  571. font-size: 28rpx;
  572. font-family: PingFang SC-Heavy, PingFang SC;
  573. font-weight: 600;
  574. color: #333333;
  575. margin-top: 20rpx;
  576. }
  577. }
  578. }
  579. </style>