<template>
|
<TableLayout :permissions="['business:areas:query']">
|
<!-- 搜索表单 -->
|
<el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
|
<el-form-item label="名称" prop="name">
|
<el-input v-model="searchForm.name" placeholder="请输入名称" @keypress.enter.native="search"></el-input>
|
</el-form-item>
|
<section>
|
<el-button type="primary" @click="search">搜索</el-button>
|
<el-button @click="reset">重置</el-button>
|
</section>
|
</el-form>
|
<!-- 表格和分页 -->
|
<template v-slot:table-wrap>
|
<el-table
|
ref="table"
|
v-loading="isWorking.search"
|
:data="tableData.list"
|
lazy
|
:load="load"
|
:tree-props="{ children: 'childList', hasChildren: 'hasChildren' }"
|
row-key="id"
|
stripe
|
border
|
:height="tableHeightNew - 40"
|
:header-row-class-name="'table-header'"
|
class="doumee-element-table"
|
@selection-change="handleSelectionChange"
|
>
|
<el-table-column prop="name" label="地区名称" min-width="100px">
|
<template slot-scope="{ row }">
|
{{row.name}}<span v-if="row.type ===0 && row.bigAreaName !=null && row.bigAreaName !=''" class="green">【{{row.bigAreaName}}】</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="createDate" label="创建时间" align="center" min-width="140px"></el-table-column>
|
<el-table-column prop="sortnum" label="排序" align="center" min-width="140px"></el-table-column>
|
<el-table-column label="状态" align="center" min-width="140px">
|
<template slot-scope="{ row }">
|
<el-switch
|
v-model="row.status"
|
active-color="#13ce66"
|
inactive-color="#ff4949"
|
active-value="1"
|
inactive-value="0">
|
</el-switch>
|
</template>
|
</el-table-column>
|
<el-table-column
|
v-if="containPermissions(['business:areas:update'])"
|
label="操作"
|
align="center"
|
min-width="80"
|
>
|
<template slot-scope="{ row }">
|
<el-button type="text" @click="openPriceRule(row)">计价规则</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</template>
|
<OperaCityPriceRuleWindow ref="operaCityPriceRuleWindow" @success="handlePriceRuleSuccess"/>
|
</TableLayout>
|
</template>
|
|
<script>
|
import BaseTable from '@/components/base/BaseTable'
|
import TableLayout from '@/layouts/TableLayout'
|
import Pagination from '@/components/common/Pagination'
|
import { listByParentId } from '@/api/business/areas'
|
import OperaCityPriceRuleWindow from '@/components/business/OperaCityPriceRuleWindow'
|
export default {
|
name: 'Areas',
|
extends: BaseTable,
|
components: { TableLayout, Pagination, OperaCityPriceRuleWindow },
|
data () {
|
return {
|
// 搜索
|
searchForm: {
|
type: 0,
|
parentId: ''
|
},
|
treeMaps: new Map(),
|
parentId: null
|
}
|
},
|
created () {
|
this.config({
|
module: '省市区信息表',
|
api: '/business/areas',
|
'field.id': 'id',
|
'field.main': 'id'
|
})
|
this.search()
|
},
|
methods: {
|
// 页码变更处理
|
handlePageChange (pageIndex) {
|
this.isWorking.search = true
|
listByParentId(this.searchForm)
|
.then(data => {
|
this.tableData.list = this.dataAddBool(data)
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking.search = false
|
})
|
},
|
dataAddBool(array) {
|
array.forEach(item => {
|
item.hasChildren = item.type != 2
|
// item.childList = item.childList && this.dataAddBool(item.childList)
|
})
|
return array
|
},
|
load(tree, treeNode, resolve) {
|
this.treeMaps.set(tree.id, { tree, treeNode, resolve })
|
listByParentId({ parentId: tree.id, type: tree.type + 1 })
|
.then(data => {
|
resolve(this.dataAddBool(data||[]))
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking.search = false
|
})
|
},
|
refreshLoadTree(parentId) {
|
if (this.treeMaps.get(parentId)) {
|
const { tree, treeNode, resolve } = this.treeMaps.get(parentId)
|
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, parentId, [])
|
if (tree) { // 重新执行父节点加载子级操作
|
this.load(tree, treeNode, resolve)
|
if (tree.parentId) { // 若存在爷爷结点,则执行爷爷节点加载子级操作,防止最后一个子节点被删除后父节点不显示删除按钮
|
const a = this.treeMaps.get(tree.parentId)
|
this.load(a.tree, a.treeNode, a.resolve)
|
}
|
}
|
} else {
|
this.handlePageChange()
|
}
|
},
|
update(parentId) {
|
this.refreshLoadTree(parentId)
|
},
|
openPriceRule(row) {
|
this.$refs.operaCityPriceRuleWindow.open('计价规则', row)
|
},
|
handlePriceRuleSuccess() {
|
this.$message.success('保存成功')
|
}
|
}
|
}
|
</script>
|