feat:address-vuex

master
ewall 5 years ago
parent 976363846c
commit b47fa05f22

@ -42,7 +42,10 @@ import {
Grid,
GridItem,
DropdownMenu,
DropdownItem
DropdownItem,
ContactCard,
ContactList,
ContactEdit
} from 'vant'
Vue.use(Toast)
@ -86,3 +89,6 @@ Vue.use(Toast)
.use(GridItem)
.use(DropdownMenu)
.use(DropdownItem)
.use(ContactCard)
.use(ContactList)
.use(ContactEdit)

@ -33,7 +33,8 @@ const routes = [
component: () => import('@/views/category'),
meta: {
title: '分类',
showTab: true
showTab: true,
keepAlive: true
}
},
// 购物车
@ -80,7 +81,7 @@ const routes = [
{
path: '/address',
name: 'Address',
component: () => import('@/views/address'),
component: () => import('@/views/address/list'),
meta: {
title: '地址管理'
}
@ -111,6 +112,24 @@ const routes = [
meta: {
title: '搜索结果'
}
},
// 确认订单
{
path: '/order/confirm',
name: 'OrderConfirm',
component: () => import('@/views/order/confirm'),
meta: {
title: '确认订单'
}
},
// 订单列表
{
path: '/order/list',
name: 'OrderList',
component: () => import('@/views/order/list'),
meta: {
title: '订单列表'
}
}
]

@ -3,10 +3,14 @@ const getters = {
id: state => state.user.id,
name: state => state.user.name,
userInfo: state => state.user.userInfo,
// address
defaultId: state => state.address.defaultId,
addressList: state => state.address.addressList,
selectedAddress: state => state.address.selectedAddress,
// search
searchKey: (state) => {
searchKey: state => {
if (state.search.searchKey.length <= 0) {
return JSON.parse(localStorage.getItem('searchKey')) || []
} else {

@ -1,14 +1,39 @@
import { getAddress } from '@/api/address'
const state = {
defaultId: '',
addressList: [],
selectedAddress: {}
}
const mutations = {
SET_ADDRESS: (state, list) => {
state.selectedAddress = list
SET_DEFAULT_ID: (state, id) => {
state.defaultId = id
},
SET_ADDRESS_LIST: (state, list) => {
state.addressList = list
},
SET_SELECTED_ADDRESS: (state, item) => {
state.selectedAddress = item
}
}
const actions = {}
const actions = {
// 获取地址列表
getList({ commit }) {
return new Promise((resolve, reject) => {
getAddress()
.then(res => {
const data = res.entry
commit('SET_ADDRESS_LIST', data)
resolve(data)
})
.catch(error => {
reject(error)
})
})
}
}
export default {
namespaced: true,

@ -3,53 +3,50 @@
<nav-bar title="编辑地址" />
<van-address-edit
:address-info="addressInfo"
:area-list="areaList"
show-postal
show-delete
show-set-default
show-search-result
:search-result="searchResult"
:area-columns-placeholder="['请选择', '请选择', '请选择']"
@save="onSave"
@delete="onDelete"
@change-detail="onChangeDetail"
/>
</div>
</template>
<script>
import areaList from '@/utils/area.js'
import { mapGetters } from 'vuex'
import NavBar from '@/components/NavBar'
import areaList from '@/utils/area.js'
export default {
name: 'AddressEdit',
data() {
return {
areaList,
searchResult: []
addressInfo: {}
}
},
components: {
NavBar
},
computed: {
...mapGetters(['addressList'])
},
mounted() {
const { index } = this.$route.query
this.addressInfo = this.addressList[Number(index)]
console.log('adfasd', this.addressList, this.addressInfo)
},
methods: {
onSave() {
// Toast('save')
onSave(value) {
console.log('>>>>', value)
},
onDelete() {
// Toast('delete')
},
onChangeDetail(val) {
if (val) {
this.searchResult = [
{
name: '黄龙万科中心',
address: '杭州市西湖区'
}
]
} else {
this.searchResult = []
}
}
}
}

@ -1,58 +0,0 @@
<template>
<div class="address-list">
<nav-bar title="我的地址" />
<van-address-list
v-model="defaultId"
:list="list"
default-tag-text="默认"
@add="onAdd"
@edit="onEdit"
@select="onSelect"
/>
</div>
</template>
<script>
import NavBar from '@/components/NavBar'
import { getAddress } from '@/api/address'
export default {
name: 'Address',
components: {
NavBar
},
data() {
return {
defaultId: '1',
list: []
}
},
mounted() {
this.getAddress()
},
methods: {
getAddress() {
getAddress().then(res => {
this.list = res.entry
})
},
onSelect(item, index) {
this.$store.commit('address/SET_ADDRESS', item)
this.$toast.success('选择成功')
this.$router.go(-1)
},
onAdd() {
this.$router.push({
path: '/address/edit'
})
},
onEdit(item, index) {
// Toast(':' + index)
}
}
}
</script>
<style>
</style>

@ -0,0 +1,69 @@
<template>
<div class="address-list">
<nav-bar title="我的地址" />
<van-address-list
v-model="id"
:list="list"
default-tag-text="默认"
@add="onAdd"
@edit="onEdit"
@select="onSelect"
/>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import NavBar from '@/components/NavBar'
export default {
name: 'Address',
components: {
NavBar
},
data() {
return {
list: []
}
},
computed: {
// TODO:
...mapGetters(['defaultId']),
id: {
get() {
return this.defaultId
},
set(val) {
this.$store.commit('address/SET_DEFAULT_ID', val)
}
}
},
async mounted() {
this.list = await this.$store.dispatch('address/getList')
},
methods: {
onSelect(item, index) {
this.$store.commit('address/SET_SELECTED_ADDRESS', item)
this.$router.go(-1)
},
onAdd() {
this.$router.push({
path: '/address/edit'
})
},
onEdit(item, index) {
this.$toast('编辑地址:' + index)
this.$router.push({
path: '/address/edit',
query: {
index
}
})
}
}
}
</script>
<style>
</style>

@ -0,0 +1,39 @@
<template>
<div class="order-confirm">
<nav-bar title="确认订单" />
<van-contact-card
:type="contact.type"
:name="contact.name"
:tel="contact.tel"
@click="onContact"
/>
</div>
</template>
<script>
export default {
name: 'OrderConfirm',
data() {
return {
contact: {
type: 'add',
name: '',
tel: ''
}
}
},
methods: {
onContact() {
this.$router.push({
path: '/address'
})
}
}
}
</script>
<style lang="scss" scoped>
.order-confirm {
}
</style>

@ -0,0 +1,14 @@
<template>
<div class="order-list">111</div>
</template>
<script>
export default {
name: 'OrderList'
}
</script>
<style lang="scss" scoped>
.order-list {
}
</style>

@ -65,8 +65,7 @@ export default {
this.$router.push({
path: '/search/list',
query: {
key: value,
t: +new Date()
key: value
}
})
}

Loading…
Cancel
Save