feat: 已实现订单基本逻辑,到完成,却订单售后
This commit is contained in:
@@ -18,7 +18,11 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { formatAddress, readAddresses, readChosenAddressId, saveChosenAddressId } from './address-data'
|
||||
import { mapActions, mapState } from 'pinia'
|
||||
import { Toast } from 'vant'
|
||||
import { postFunction } from '@/api/supplied-service'
|
||||
import { useUserStore } from '@/store/user'
|
||||
import { formatAddress, readChosenAddressId, saveChosenAddressId } from './address-data'
|
||||
import JoyfulSelectionAddressListSkeleton from '@/skeleton-view/joyful-selection/address/index.vue'
|
||||
|
||||
export default {
|
||||
@@ -33,6 +37,7 @@ export default {
|
||||
disabledList: []
|
||||
}),
|
||||
computed: {
|
||||
...mapState(useUserStore, ['supplierId', 'userId']),
|
||||
addressList() {
|
||||
return this.addresses.map(item => ({
|
||||
id: item.id,
|
||||
@@ -44,18 +49,54 @@ export default {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.addresses = readAddresses()
|
||||
this.chosenAddressId = readChosenAddressId()
|
||||
this.$nextTick(() => {
|
||||
this.loading = false
|
||||
})
|
||||
this.loadAddresses()
|
||||
},
|
||||
methods: {
|
||||
onSelect(item) {
|
||||
...mapActions(useUserStore, ['fetchBridgeToken']),
|
||||
async loadAddresses() {
|
||||
this.loading = true
|
||||
try {
|
||||
await this.fetchBridgeToken()
|
||||
|
||||
if (!this.supplierId || !this.userId) {
|
||||
Toast('用户信息不完整,请重新进入商城')
|
||||
this.addresses = []
|
||||
return
|
||||
}
|
||||
|
||||
const data = await postFunction('address-list', {
|
||||
supplierId: this.supplierId,
|
||||
userId: this.userId
|
||||
})
|
||||
this.addresses = data?.addresses || []
|
||||
this.chosenAddressId = readChosenAddressId() || this.addresses.find(item => item.isDefault)?.id || this.addresses[0]?.id || ''
|
||||
} catch (error) {
|
||||
Toast(error.message || '查询地址失败,请稍后再试')
|
||||
this.addresses = []
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
async onSelect(item) {
|
||||
this.chosenAddressId = item.id
|
||||
saveChosenAddressId(item.id)
|
||||
|
||||
if (this.$route.query.from === 'checkout') {
|
||||
const address = this.addresses.find(addressItem => addressItem.id === item.id)
|
||||
if (address) {
|
||||
try {
|
||||
await postFunction('address-save', {
|
||||
...address,
|
||||
supplierId: this.supplierId,
|
||||
userId: this.userId,
|
||||
addressId: address.id,
|
||||
isDefault: true
|
||||
})
|
||||
} catch (error) {
|
||||
Toast(error.message || '璁剧疆榛樿鍦板潃澶辫触锛岃绋嶅悗鍐嶈瘯')
|
||||
return
|
||||
}
|
||||
}
|
||||
this.$router.back()
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user