Commit 8c85ffe9 by cwq0219

省市区组件-完善

1 parent 2369808e
......@@ -24,6 +24,15 @@
<span v-show="errorBags.has('name')" class="error">{{ errorBags.first('name') }}</span>
</gl-form-item>
<gl-form-item label="商户地址:">
<city-area
ref="c"
:showCity="showCity"
:validateCity="validateCity"
:eventBus="eventBus"
@cityArea="getCityArea">
</city-area>
</gl-form-item>
<gl-form-item label="">
<gl-input
v-model="merchantForm.address"
placeholder="请输入详细地址"
......@@ -76,6 +85,8 @@
</template>
<script>
import Vue from 'vue'
import { CityArea } from '../components'
const isPhone = {
validate: (value, args) => {
return value.length === 11 && /^1[345789]\d{9}$/.test(value)
......@@ -86,6 +97,11 @@ export default {
data() {
return {
title: '新增商户',
// 省市区组件-配置
eventBus: null,
showCity: [1, 1, 1],
validateCity: [1, 1, 1],
areaInfo: {},
// phoneFixed: 11,
rules: {
merchantName: [{ required: true }],
......@@ -107,24 +123,42 @@ export default {
},
merchantForm: Object
},
components: {
CityArea
},
watch: {
isVisible() {
this.$validator.errors.clear()
isVisible(val) {
if (!val) {
this.$validator.errors.clear()
this.areaInfo = {}
}
}
},
mounted() {
this.$validator.extend('is_phone', isPhone)
this.eventBus = new Vue()
},
methods: {
handleClose() {
this.eventBus.$emit('reset')
this.$emit('hideDialog')
},
handleComfrim() {
this.$validator.validateAll().then((result) => {
if (result) {
this.$emit('comfirmDialog')
Promise.all([
this.$refs['c'].$validator.validateAll(),
this.$validator.validateAll()
]).then((result) => {
if (result[0] && result[1]) {
this.$emit('comfirmDialog', this.areaInfo)
this.eventBus.$emit('reset')
}
})
},
getCityArea(params) {
console.log(params)
this.areaInfo.provinceId = params[0]
this.areaInfo.cityId = params[1]
this.areaInfo.areaId = params[2]
}
}
}
......
......@@ -29,7 +29,12 @@
</gl-col>
<gl-col :span="12">
<gl-form-item label="地区:">
<gl-col :span="11">
<city-area
:showCity="showCity"
:eventBus="eventBus"
@cityArea="getCityArea"
></city-area>
<!-- <gl-col :span="11">
<gl-select
v-model="merchantSearch.provinceId"
placeholder="省"
......@@ -45,7 +50,7 @@
placeholder="市"
>
</gl-select>
</gl-col>
</gl-col> -->
</gl-form-item>
</gl-col>
<gl-col :span="12">
......@@ -116,11 +121,15 @@
</template>
<script>
import Vue from 'vue'
import { CityArea } from '../components'
export default {
name: 'SearchDialog',
data() {
return {
title: '高级搜索'
title: '高级搜索',
eventBus: null,
showCity: [1, 1]
}
},
props: {
......@@ -135,15 +144,28 @@ export default {
merchantSearch: Object,
statusItems: Object
},
components: {
CityArea
},
mounted() {
this.eventBus = new Vue()
},
methods: {
handleClose() {
this.eventBus.$emit('reset')
this.$emit('hideDialog', true)
},
handleComfrim() {
this.eventBus.$emit('reset')
this.$emit('comfirmDialog')
},
hideDialog() {
this.eventBus.$emit('reset')
this.$emit('hideDialog')
},
getCityArea(params) {
this.merchantSearch.provinceId = params[0]
this.merchantSearch.cityId = params[1]
}
}
}
......
......@@ -16,11 +16,11 @@
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
:current-page.sync="pageCount"
:page-sizes="[10, 20, 30, 40]"
:page-size="pageSize"
layout="sizes, total, ->, prev, pager, next, jumper"
:total="total"
:total="totalCount"
>
</gl-pagination>
</div>
......@@ -58,6 +58,12 @@ export default {
addVisible: false,
merchantForm: {
merchantName: '',
provinceId: '',
provinceName: '',
cityId: '',
cityName: '',
areaId: '',
areaName: '',
address: '',
merchantChannel: '',
contactor: '',
......@@ -81,8 +87,8 @@ export default {
1: '已停用'
},
// 分页所需参数-start
total: 10,
currentPage: 1,
totalCount: 10,
pageCount: 1,
pageSize: 10,
// 分页所需参数-end
ListTableData: {
......@@ -143,7 +149,7 @@ export default {
getParams() {
const params = this.$deep_clone(this.merchantSearch)
params.pageSize = this.pageSize
params.currentPage = this.currentPage
params.pageCount = this.pageCount
return params
},
// 接口请求-start
......@@ -152,7 +158,7 @@ export default {
params.methods = bizMethods.Search
request.req(params).then(res => {
this.ListTableData.data = res.merchants
this.total = res.pagination.totalCount
this.totalCount = res.pagination.totalCount
this.reset(this.merchantSearch)
}).catch(err => {
console.log(err)
......@@ -160,14 +166,16 @@ export default {
this.reset(this.merchantSearch)
})
},
saveMerchant() {
request.req(this.merchantForm).then(res => {
saveMerchant(areaInfo) {
this.merchantForm = Object.assign(this.merchantForm, areaInfo)
const params = this.merchantForm
params.methods = bizMethods.Create
request.req(params).then(res => {
notice.okTips()
this.reset(this.merchantForm)
}).catch(err => {
console.log(err)
notice.errorTips()
this.reset(this.merchantForm)
})
},
// 接口请求-end
......@@ -176,7 +184,7 @@ export default {
this.getList()
},
handleCurrentChange(val) {
this.currentPage = val
this.pageCount = val
this.getList()
},
reset(params) {
......@@ -207,9 +215,9 @@ export default {
this.handleAdd()
this.reset(this.merchantForm)
},
handleAddComfirm() {
handleAddComfirm(areaInfo) {
this.handleAdd()
this.saveMerchant()
this.saveMerchant(areaInfo)
}
}
}
......
......@@ -101,9 +101,6 @@ export default {
city(val) {
!val ? this.areaList = [] : false
}
// eventBus(val) {
// console.log(val)
// },
// eventBus: {
// handler(__eventBus) {
// if (__eventBus) {
......@@ -118,9 +115,7 @@ export default {
mounted() {
// console.log(this.showCity)
this.eventBus.$on('reset', () => {
this.province = ''
this.city = ''
this.area = ''
this.resetAll()
})
// 初始化
this.$request({ url: 'http://192.168.3.171:7300/mock/5be17454f31545347559d499/config/area_config' }).then(data => {
......@@ -133,6 +128,16 @@ export default {
})
},
methods: {
resetAll() {
this.province = ''
this.city = ''
this.area = ''
this.mutIndex = []
clearTimeout(timer)
const timer = setTimeout(() => {
this.$validator.errors.clear()
}, 400)
},
// 选择省
selectProvince(val) {
this.mutArray = [val, null, null]
......@@ -155,13 +160,16 @@ export default {
this.mutArray[1] = val
this.mutArray[2] = null
const i = this.mutIndex[0]
this.AllData[i].cityInfoList.forEach((element, index) => {
if (element.cityId === val) {
this.mutIndex[1] = index
}
})
if (this.AllData[i]) {
this.AllData[i].cityInfoList.forEach((element, index) => {
if (element.cityId === val) {
this.mutIndex[1] = index
}
})
}
val ? this.getArea(this.mutIndex[0], this.mutIndex[1]) : false
this.area = ''
this.mutIndex[2] = ''
val ? this.$emit('cityArea', this.mutArray) : false
},
// 选择区
......@@ -172,18 +180,22 @@ export default {
// 获取市
getCity(index) {
const arr = []
this.AllData[index].cityInfoList.forEach(element => {
arr.push({ cityId: element.cityId, cityName: element.cityName })
})
this.cityList = arr
if (this.AllData[index]) {
this.AllData[index].cityInfoList.forEach(element => {
arr.push({ cityId: element.cityId, cityName: element.cityName })
})
this.cityList = arr
}
},
// 获取区
getArea(i, j) {
const arr = []
this.AllData[i].cityInfoList[j].areaInfoList.forEach(element => {
arr.push({ areaId: element.areaId, areaName: element.areaName })
})
this.areaList = arr
if (this.AllData[i]) {
this.AllData[i].cityInfoList[j].areaInfoList.forEach(element => {
arr.push({ areaId: element.areaId, areaName: element.areaName })
})
this.areaList = arr
}
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!