settleCenter.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. }
  218. } else {
  219. this.getCouponList()
  220. this.getOrderDetail()
  221. }
  222. },
  223. methods: {
  224. /**
  225. * 获取优惠券配置
  226. * @param {Object} item - 优惠券对象
  227. * @returns {Object} - 优惠券配置对象
  228. */
  229. getItemConfig(item) {
  230. let itemConfig = {
  231. btnText: '去使用',
  232. disabled: false,
  233. btnPlain: true
  234. }
  235. if (item.coupon_id == this.checkedCoupon.coupon_id) {
  236. itemConfig = {
  237. btnText: '取消使用',
  238. disabled: false,
  239. btnPlain: true
  240. }
  241. }
  242. return itemConfig
  243. },
  244. /**
  245. * 获取积分使用数据
  246. */
  247. getPoints() {
  248. this.$api.getPointsUseData().then(res => {
  249. if (!res.data.ratio) {
  250. this.usePointsFlag = false
  251. return
  252. } else {
  253. this.usePointsFlag = true
  254. }
  255. this.pointsData = res.data
  256. const {min_money, ratio, to_money} = this.pointsData
  257. const amount = this.orderData.amount_goods
  258. if (this.orderData.integral) {
  259. this.usePoints = ['points']
  260. let price = this.orderData.integral_price
  261. this.pointsShowData = {
  262. price: price.toFixed(2),
  263. points: Math.floor(price / to_money)
  264. }
  265. } else {
  266. let userPoints = 1000
  267. let price = Math.floor(amount * ratio / 100)
  268. let points = price * to_money
  269. points = this.userPoints > points ? points : this.userPoints
  270. price = points / to_money
  271. this.pointsShowData = {
  272. points: Math.floor(points),
  273. price: price.toFixed(2)
  274. }
  275. }
  276. })
  277. },
  278. /**
  279. * 获取购物车数据
  280. */
  281. getCartData() {
  282. this.cartIds = this.pageOptions.ids.split('_')
  283. this.$api.createPrevOrderByCart({id: this.cartIds}).then(res => {
  284. const {items, coupons, count_total, amount_total, integral = {}} = res.data
  285. this.goodsList = items.map(item => {
  286. const {goods_spec, price_selling} = item.sku
  287. item.stock_sales = item.num
  288. item = {
  289. goods_spec,
  290. price_selling,
  291. ...item
  292. }
  293. return item
  294. })
  295. this.couponList = coupons
  296. this.orderData.number_goods = count_total
  297. this.orderData.amount_goods = amount_total
  298. if (res.data.integral_use && res.data.integral_price) {
  299. this.usePointsFlag = true
  300. this.pointsShowData = {
  301. points: res.data.integral_use,
  302. price: (res.data.integral_price).toFixed(2)
  303. }
  304. } else {
  305. this.usePointsFlag = false
  306. }
  307. })
  308. },
  309. /**
  310. * 获取运费
  311. */
  312. getExpressFee() {
  313. this.$api.getPrevCartExpress({id: this.cartIds, addr_code: this.mAddress.code}).then(res => {
  314. this.orderData.amount_express = res.data
  315. })
  316. },
  317. /**
  318. * 前往支付
  319. */
  320. toPay() {
  321. if (!this.mAddress.code) {
  322. uni.showToast({
  323. title: '请选择收货地址'
  324. })
  325. return
  326. }
  327. if (this.pageOptions.type == 'cart') {
  328. const sendData = {
  329. id: this.cartIds,
  330. addr_code: this.mAddress.code,
  331. coupon_id: this.checkedCoupon.id,
  332. order_remark: this.order_remark,
  333. integral: this.integral
  334. }
  335. this.$api.createOrderByCart(sendData).then(res => {
  336. const {appId, nonceStr, paySign, signType, timeStamp} = res.data.param
  337. uni.requestPayment({
  338. provider: 'wxpay',
  339. nonceStr,
  340. package: res.data.param.package,
  341. paySign,
  342. signType,
  343. timeStamp,
  344. success: function (success) {
  345. uni.navigateTo({url: `/subPages/paySuccess/paySuccess?orderNo=${res.data.order.order_no}`})
  346. },
  347. fail: function (err) {
  348. uni.navigateTo({url: `/subPages/orderDetail/orderDetail?orderNo=${res.data.order.order_no}`})
  349. }
  350. })
  351. })
  352. } else {
  353. // uni.navigateTo({url: `/subPages/paySuccess/paySuccess?orderNo=${this.orderNo}`})
  354. this.$toWechatPay(this.orderNo, this.order_remark)
  355. }
  356. },
  357. /**
  358. * 地址确认
  359. */
  360. addressConfirm() {
  361. this.$api.submitOrderByAdress({order_no: this.orderNo, code: this.mAddress.code}).then(res => {
  362. this.orderData.amount_express = res.data.amount
  363. })
  364. },
  365. /**
  366. * 选择优惠券
  367. */
  368. choseCoupon() {
  369. if (this.couponList.length) {
  370. this.showCoupon = true
  371. } else {
  372. uni.showToast({
  373. title: '暂无可使用优惠券',
  374. icon: 'none'
  375. })
  376. }
  377. },
  378. /**
  379. * 获取优惠券列表
  380. */
  381. getCouponList() {
  382. this.$api.getCouponByOrder({order_no: this.orderNo}).then(res => {
  383. this.couponList = res.data
  384. })
  385. },
  386. /**
  387. * 处理优惠券选择
  388. * @param {Object} item - 优惠券对象
  389. */
  390. handleItem(item) {
  391. this.showCoupon = false
  392. if (item.coupon_id == this.checkedCoupon.coupon_id) {
  393. this.checkedCoupon = {id: 0, coupon_id: 0}
  394. } else {
  395. this.checkedCoupon = item
  396. }
  397. if (this.pageOptions.type != 'cart') {
  398. this.$api.submitOrderByCoupon({order_no: this.orderNo, id: this.checkedCoupon.id})
  399. }
  400. },
  401. /**
  402. * 获取订单详情
  403. */
  404. getOrderDetail() {
  405. this.$api.orderDetail({order_no: this.orderNo}).then(res => {
  406. this.goodsList = res.data.items || []
  407. this.orderData = res.data
  408. this.checkedCoupon = res.data.coupon || {}
  409. if (res.data.addr_code) {
  410. const {
  411. address_area,
  412. address_city,
  413. address_province,
  414. address_content,
  415. address_name,
  416. address_phone
  417. } = res.data.truck || {}
  418. this.mAddress = {
  419. code: res.data.addr_code,
  420. area: address_area,
  421. city: address_city,
  422. province: address_province,
  423. address: address_content,
  424. name: address_name,
  425. phone: address_phone
  426. }
  427. }
  428. const selectAddress = uni.getStorageSync('selectAddress') || undefined
  429. if (selectAddress) {
  430. const tempAddress = JSON.parse(selectAddress)
  431. if (!this.mAddress.code || (this.mAddress && this.mAddress.code != tempAddress.code)) {
  432. this.mAddress = tempAddress
  433. this.addressConfirm()
  434. }
  435. uni.removeStorageSync('selectAddress')
  436. }
  437. })
  438. },
  439. /**
  440. * 选择地址
  441. */
  442. selectAddress() {
  443. uni.navigateTo({
  444. url: '/subPages/addressMg/addressMg?isBack=true'
  445. })
  446. }
  447. }
  448. }
  449. </script>
  450. <style lang="scss" scoped>
  451. .coupon-list {
  452. padding: 40rpx 20rpx;
  453. }
  454. .common-page {
  455. height: 100vh;
  456. overflow-y: auto;
  457. padding: 20rpx;
  458. color: #2C2C2C;
  459. padding-bottom: 188rpx;
  460. box-sizing: border-box;
  461. }
  462. .settle-center-btn {
  463. height: 76rpx;
  464. line-height: 78rpx;
  465. width: 170rpx;
  466. padding: 0 29rpx;
  467. color: #fff;
  468. background: linear-gradient( 315deg, #CA9359 0%, #E2B98E 100%);
  469. border-radius: 292rpx 292rpx 292rpx 292rpx;
  470. font-size: 32rpx;
  471. text-align: center;
  472. margin-left: 30rpx;
  473. }
  474. .good-card {
  475. padding: 38rpx 22rpx;
  476. color: #7A7A7A;
  477. ::v-deep {
  478. .u-textarea {
  479. background: #F6F6F6;
  480. border-radius: 12rpx 12rpx 12rpx 12rpx;
  481. border: none;
  482. padding: 18rpx;
  483. .u-textarea__count {
  484. background-color: transparent !important;
  485. }
  486. }
  487. .u-checkbox__icon-wrap{
  488. margin-right: 0!important;
  489. }
  490. }
  491. }
  492. .goods-list {
  493. margin: 0 30rpx;
  494. padding: 30rpx 0;
  495. border-bottom: 1rpx solid #F5F5F5;
  496. .list-info {
  497. width: 100%;
  498. }
  499. }
  500. .goods-total {
  501. justify-content: flex-end;
  502. margin: 27rpx 20rpx;
  503. }
  504. .address-box {
  505. // width: 100%;
  506. display: flex;
  507. flex-direction: row;
  508. align-items: center;
  509. padding: 30rpx 22rpx;
  510. .address-view {
  511. flex: 1;
  512. display: flex;
  513. flex-direction: column;
  514. .t1 {
  515. font-size: 28rpx;
  516. margin-top: 10rpx;
  517. font-family: PingFang SC-Medium, PingFang SC;
  518. font-weight: 400;
  519. color: #333333;
  520. }
  521. .t2 {
  522. font-size: 28rpx;
  523. font-family: PingFang SC-Heavy, PingFang SC;
  524. font-weight: 600;
  525. color: #333333;
  526. margin-top: 20rpx;
  527. }
  528. }
  529. }
  530. </style>