| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <template>
- <view class="container">
- <view v-if="loading" class="loading-wrap">
- <text class="loading-text">加载中...</text>
- </view>
- <scroll-view v-else scroll-y class="content">
- <!-- Address Section -->
- <view class="section address-section" @click="goSelectAddress">
- <view v-if="selectedAddress" class="address-content">
- <view class="address-top">
- <text class="receiver-name">{{ selectedAddress.receiverName }}</text>
- <text class="receiver-phone">{{ formatPhone(selectedAddress.phone) }}</text>
- <text v-if="selectedAddress.isDefault === 1" class="default-badge">默认</text>
- </view>
- <text class="address-detail">
- {{ selectedAddress.province }}{{ selectedAddress.city }}{{ selectedAddress.district }}{{ selectedAddress.street }}
- </text>
- <text class="address-arrow">›</text>
- </view>
- <view v-else class="address-empty" @click.stop="goAddAddress">
- <text class="address-empty-icon">📍</text>
- <text class="address-empty-text">请添加收货地址</text>
- <text class="address-arrow">›</text>
- </view>
- </view>
- <!-- Order Items Section -->
- <view class="section">
- <text class="section-title">商品信息</text>
- <view
- v-for="item in items"
- :key="item.productId"
- class="order-item"
- >
- <image
- class="item-image"
- :src="item.coverImage || '/static/default-product.png'"
- mode="aspectFill"
- />
- <view class="item-info">
- <text class="item-name">{{ item.productName }}</text>
- <text class="item-qty">x{{ item.quantity }}</text>
- </view>
- <text class="item-price">{{ formatPriceWithSymbol(item.unitPrice) }}</text>
- </view>
- </view>
- <!-- Freight Section -->
- <view class="section">
- <view class="info-row">
- <text class="info-label">运费</text>
- <text class="info-value">{{ formatPriceWithSymbol(freight) }}</text>
- </view>
- </view>
- <!-- Remark Section -->
- <view class="section">
- <view class="info-row">
- <text class="info-label">备注</text>
- <input
- class="remark-input"
- v-model="remark"
- placeholder="选填,给商家留言"
- placeholder-style="color: #ccc; font-size: 26rpx;"
- />
- </view>
- </view>
- <view class="bottom-spacer"></view>
- </scroll-view>
- <view class="bottom-bar">
- <view class="bottom-left">
- <text class="total-label">合计: </text>
- <text class="total-amount">{{ formatPriceWithSymbol(actualAmount + freight) }}</text>
- </view>
- <button
- :class="['submit-btn', submitting ? 'disabled' : '']"
- :disabled="submitting"
- @click="onSubmit"
- >提交订单</button>
- </view>
- </view>
- </template>
- <script>
- import config from '@/config.js'
- export default {
- data() {
- return {
- items: [],
- selectedAddress: null,
- freight: 0,
- remark: '',
- loading: false,
- submitting: false,
- buyerId: null,
- actualAmount: 0
- }
- },
- onLoad() {
- this.buyerId = uni.getStorageSync('userId')
- var stored = uni.getStorageSync('checkoutItems')
- if (stored) {
- this.items = stored
- this.calcAmount()
- }
- this.loadDefaultAddress()
- },
- methods: {
- calcAmount() {
- var total = 0
- for (var i = 0; i < this.items.length; i++) {
- total = total + (this.items[i].unitPrice * this.items[i].quantity)
- }
- this.actualAmount = total
- },
- loadDefaultAddress() {
- this.loading = true
- var that = this
- uni.request({
- url: config.danshop('/danshop/address/list'),
- method: 'POST',
- data: { userId: this.buyerId },
- header: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + uni.getStorageSync('token')
- },
- success: function(res) {
- that.loading = false
- if (res.data && res.data.code === 200) {
- var list = res.data.data || []
- for (var i = 0; i < list.length; i++) {
- if (list[i].isDefault === 1) {
- that.selectedAddress = list[i]
- break
- }
- }
- if (!that.selectedAddress && list.length > 0) {
- that.selectedAddress = list[0]
- }
- }
- },
- fail: function() {
- that.loading = false
- }
- })
- },
- goSelectAddress() {
- var self = this
- uni.navigateTo({
- url: '/pages/shop/address/address?selectMode=1',
- events: {
- onAddressSelect: function(data) {
- self.selectedAddress = data
- }
- },
- success: function(res) {
- res.eventChannel.on('onAddressSelect', function(data) {
- self.selectedAddress = data
- })
- }
- })
- },
- goAddAddress() {
- uni.navigateTo({ url: '/pages/shop/address-edit/address-edit' })
- },
- onSubmit() {
- if (!this.selectedAddress) {
- uni.showToast({ title: '请选择收货地址', icon: 'none' })
- return
- }
- if (this.items.length === 0) {
- uni.showToast({ title: '请选择商品', icon: 'none' })
- return
- }
- this.submitting = true
- var orderItems = []
- for (var i = 0; i < this.items.length; i++) {
- orderItems.push({
- productId: this.items[i].productId,
- quantity: this.items[i].quantity
- })
- }
- var that = this
- uni.request({
- url: config.danshop('/danshop/order/create'),
- method: 'POST',
- data: {
- buyerId: this.buyerId,
- addressId: this.selectedAddress.id,
- items: orderItems,
- remark: this.remark,
- freight: this.freight
- },
- header: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + uni.getStorageSync('token')
- },
- success: function(res) {
- that.submitting = false
- if (res.data && res.data.code === 200) {
- var order = res.data.data
- uni.showToast({ title: '下单成功', icon: 'success' })
- uni.removeStorageSync('checkoutItems')
- setTimeout(function() {
- uni.navigateTo({
- url: '/pages/shop/payment/payment?orderNo=' + order.orderNo + '&amount=' + order.actualAmount
- })
- }, 1000)
- } else {
- uni.showToast({ title: res.data.message || '下单失败', icon: 'none' })
- }
- },
- fail: function() {
- that.submitting = false
- uni.showToast({ title: '网络请求失败', icon: 'none' })
- }
- })
- },
- formatPrice(price) {
- if (price === null || price === undefined) return '0.00'
- return (Number(price) / 100).toFixed(2)
- },
- formatPhone(phone) {
- if (!phone) return ''
- if (phone.length === 11) {
- return phone.substr(0, 3) + '****' + phone.substr(7)
- }
- return phone
- }
- }
- }
- </script>
- <style scoped>
- .container {
- min-height: 100vh;
- background: #f5f5f5;
- }
- .loading-wrap {
- display: flex;
- justify-content: center;
- padding-top: 200rpx;
- }
- .loading-text {
- font-size: 28rpx;
- color: #999;
- }
- .content {
- height: calc(100vh - 120rpx);
- }
- .section {
- background: #fff;
- margin: 20rpx;
- border-radius: 16rpx;
- padding: 24rpx;
- }
- .section-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- margin-bottom: 20rpx;
- display: block;
- }
- .address-section {
- position: relative;
- }
- .address-content {
- position: relative;
- }
- .address-top {
- display: flex;
- align-items: center;
- margin-bottom: 10rpx;
- }
- .receiver-name {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- margin-right: 20rpx;
- }
- .receiver-phone {
- font-size: 26rpx;
- color: #666;
- }
- .default-badge {
- font-size: 20rpx;
- color: #F97316;
- background: #fff7e6;
- padding: 2rpx 12rpx;
- border-radius: 20rpx;
- margin-left: 12rpx;
- }
- .address-detail {
- font-size: 26rpx;
- color: #999;
- line-height: 1.5;
- }
- .address-arrow {
- position: absolute;
- right: 0;
- top: 50%;
- font-size: 40rpx;
- color: #ccc;
- transform: translateY(-50%);
- }
- .address-empty {
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 30rpx 0;
- position: relative;
- }
- .address-empty-icon {
- font-size: 40rpx;
- margin-right: 12rpx;
- }
- .address-empty-text {
- font-size: 28rpx;
- color: #999;
- }
- .order-item {
- display: flex;
- align-items: center;
- padding: 16rpx 0;
- border-bottom: 1rpx solid #f5f5f5;
- }
- .order-item:last-child {
- border-bottom: none;
- }
- .item-image {
- width: 80rpx;
- height: 80rpx;
- border-radius: 8rpx;
- background: #f0f0f0;
- margin-right: 16rpx;
- }
- .item-info {
- flex: 1;
- display: flex;
- flex-direction: column;
- min-width: 0;
- }
- .item-name {
- font-size: 26rpx;
- color: #333;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- margin-bottom: 6rpx;
- }
- .item-qty {
- font-size: 22rpx;
- color: #999;
- }
- .item-price {
- font-size: 26rpx;
- color: #F97316;
- font-weight: bold;
- margin-left: 16rpx;
- }
- .info-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 8rpx 0;
- }
- .info-label {
- font-size: 26rpx;
- color: #999;
- }
- .info-value {
- font-size: 26rpx;
- color: #333;
- }
- .remark-input {
- flex: 1;
- text-align: right;
- font-size: 26rpx;
- color: #333;
- }
- .bottom-spacer {
- height: 140rpx;
- }
- .bottom-bar {
- position: fixed;
- bottom: 0;
- left: 0;
- right: 0;
- height: 100rpx;
- background: #fff;
- border-top: 1rpx solid #eee;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 30rpx;
- z-index: 100;
- }
- .bottom-left {
- display: flex;
- align-items: baseline;
- }
- .total-label {
- font-size: 26rpx;
- color: #666;
- }
- .total-amount {
- font-size: 36rpx;
- color: #F97316;
- font-weight: bold;
- }
- .submit-btn {
- background: linear-gradient(135deg, #F97316, #FB923C);
- color: #fff;
- font-size: 28rpx;
- font-weight: bold;
- padding: 0 60rpx;
- height: 72rpx;
- line-height: 72rpx;
- border-radius: 36rpx;
- border: none;
- }
- .submit-btn::after {
- border: none;
- }
- .submit-btn.disabled {
- background: #ddd;
- color: #999;
- }
- </style>
|