|
@@ -0,0 +1,248 @@
|
|
|
+<template>
|
|
|
+ <div class="app-container">
|
|
|
+ <div class="filter-container">
|
|
|
+ <el-input v-model="listQuery.city_name" placeholder="城市名" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
|
|
|
+ <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
|
|
|
+ 搜索
|
|
|
+ </el-button>
|
|
|
+<!-- <el-button type="primary" icon="el-icon-edit" @click="handleCreate(scope)">-->
|
|
|
+<!-- 创建开发城市-->
|
|
|
+<!-- </el-button>-->
|
|
|
+ </div>
|
|
|
+ <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
|
|
|
+ <el-table-column align="center" label="ID" width="80">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span>{{ scope.row.id }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <el-table-column align="center" label="城市">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span>{{ scope.row.sname }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column class-name="status-col" label="状态" width="80ß">
|
|
|
+ <template slot-scope="{row}">
|
|
|
+ <el-tag :type="row.status | statusFilter">
|
|
|
+ {{ row.status == '1' ? "正常" : "隐藏" }}
|
|
|
+ </el-tag>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column class-name="status-col" label="排序" width="80ß">
|
|
|
+ <template slot-scope="{row}">
|
|
|
+ <el-tag type="success">
|
|
|
+ {{ row.sort }}
|
|
|
+ </el-tag>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column align="center" label="Actions" width="190" class-name="small-padding fixed-width">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleUpdate(scope)">
|
|
|
+ 修改
|
|
|
+ </el-button>
|
|
|
+ <el-button :type="scope.row.status == '1' ? 'danger' : 'success'" size="mini" icon="el-icon-turn-off" style="margin-left: 10px;" @click="handleDelete(scope)">
|
|
|
+ {{ scope.row.status == '1' ? "隐藏" : "开启" }}
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
|
|
|
+ <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
|
|
|
+ <el-form ref="dataForm" :model="temp" label-position="left" label-width="70px" style="width: 400px; margin-left:50px;">
|
|
|
+ <el-form-item label="城市" prop="sname">
|
|
|
+ <el-input v-model="temp.sname" />
|
|
|
+<!-- <el-cascader v-model="temp.sname" :props="props" style="width: 330px;"></el-cascader>-->
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="排序" prop="sort">
|
|
|
+ <el-input v-model="temp.sort" placeholder="倒序" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button @click="dialogFormVisible = false">
|
|
|
+ 取消
|
|
|
+ </el-button>
|
|
|
+ <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
|
|
|
+ 确定
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { fetchList, deleteOpenArea, createOpenArea, updateOpenArea, fetchOpenArea } from '@/api/city'
|
|
|
+import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
|
|
|
+import waves from '@/directive/waves'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'ArticleList',
|
|
|
+ components: { Pagination },
|
|
|
+ directives: { waves },
|
|
|
+ filters: {
|
|
|
+ statusFilter(status) {
|
|
|
+ const statusMap = {
|
|
|
+ 1: 'success',
|
|
|
+ draft: 'info',
|
|
|
+ 2: 'danger'
|
|
|
+ }
|
|
|
+ return statusMap[status]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ list: null,
|
|
|
+ total: 0,
|
|
|
+ listLoading: true,
|
|
|
+ listQuery: {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10
|
|
|
+ },
|
|
|
+ temp: {
|
|
|
+ id: undefined,
|
|
|
+ sname: '',
|
|
|
+ sort: 0
|
|
|
+ },
|
|
|
+ dialogFormVisible: false,
|
|
|
+ dialogStatus: '',
|
|
|
+ textMap: {
|
|
|
+ update: '修改',
|
|
|
+ create: '创建'
|
|
|
+ },
|
|
|
+ props: {
|
|
|
+ lazy: true,
|
|
|
+ checkStrictly: true,
|
|
|
+ lazyLoad(node, resolve) {
|
|
|
+ const { level } = node
|
|
|
+ const query = {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 100
|
|
|
+ }
|
|
|
+ console.log(node)
|
|
|
+ query.pid = node.value ? node.value : 100000
|
|
|
+ fetchList(query).then(res => {
|
|
|
+ const nodes = []
|
|
|
+ console.log(res.data)
|
|
|
+ res.data.list.forEach(v => {
|
|
|
+ nodes.push({
|
|
|
+ value: v.id,
|
|
|
+ label: v.name,
|
|
|
+ leaf: level >= 2
|
|
|
+ })
|
|
|
+ })
|
|
|
+ resolve(nodes)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getList()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getList() {
|
|
|
+ this.listLoading = true
|
|
|
+ fetchList(this.listQuery).then(response => {
|
|
|
+ this.list = response.data.list
|
|
|
+ this.total = response.data.count
|
|
|
+ this.listLoading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleFilter() {
|
|
|
+ this.listLoading = true
|
|
|
+ fetchList(this.listQuery).then(response => {
|
|
|
+ this.list = response.data.list
|
|
|
+ this.total = response.data.count
|
|
|
+ this.listLoading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleDelete: function({ $index, row }) {
|
|
|
+ console.log(row.id)
|
|
|
+ const type = row.status === 1 ? '隐藏' : '开启'
|
|
|
+ this.$confirm('您确定要' + type + '吗', '警告', {
|
|
|
+ confirmButtonText: '是的',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ .then(async() => {
|
|
|
+ await deleteOpenArea(row.id)
|
|
|
+ const rs = await fetchOpenArea(row.id)
|
|
|
+ this.list.splice($index, 1, rs.data.info)
|
|
|
+ this.$message({
|
|
|
+ type: 'success',
|
|
|
+ message: type + '成功'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleUpdate({ $index, row }) {
|
|
|
+ this.temp = Object.assign({}, row) // copy obj
|
|
|
+ this.dialogStatus = 'update'
|
|
|
+ this.dialogFormVisible = true
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs['dataForm'].clearValidate()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleCreate() {
|
|
|
+ this.dialogStatus = 'create'
|
|
|
+ this.dialogFormVisible = true
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs['dataForm'].clearValidate()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ createData() {
|
|
|
+ createOpenArea(this.temp).then((rs) => {
|
|
|
+ fetchOpenArea(rs.data.addId).then(res => {
|
|
|
+ this.list.unshift(res.data.info)
|
|
|
+ this.dialogFormVisible = false
|
|
|
+ this.$notify({
|
|
|
+ title: '成功',
|
|
|
+ message: '创建成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ updateData() {
|
|
|
+ const tempData = Object.assign({}, this.temp)
|
|
|
+ if (!tempData.name) {
|
|
|
+ this.$notify({
|
|
|
+ title: '警告',
|
|
|
+ message: '城市名不能为空',
|
|
|
+ type: 'error',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ updateOpenArea(tempData).then(() => {
|
|
|
+ const index = this.list.findIndex(v => v.id === this.temp.id)
|
|
|
+ this.list.splice(index, 1, this.temp)
|
|
|
+ this.dialogFormVisible = false
|
|
|
+ this.$notify({
|
|
|
+ title: '成功',
|
|
|
+ message: '更新成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.edit-input {
|
|
|
+ padding-right: 100px;
|
|
|
+}
|
|
|
+.cancel-btn {
|
|
|
+ position: absolute;
|
|
|
+ right: 15px;
|
|
|
+ top: 10px;
|
|
|
+}
|
|
|
+.filter-container{
|
|
|
+ margin-bottom: 20px;
|
|
|
+}
|
|
|
+.filter-item {
|
|
|
+ margin-right: 10px;
|
|
|
+}
|
|
|
+
|
|
|
+</style>
|