longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
  <flex-layout>
    <div class="flex-page-content">
      <el-table stripe size="mini" header-row-class-name="header-primary" height="100%" :data="tableData">
        <el-table-column prop="province" label="省" min-width="120" :resizable="false" align="center">
        </el-table-column>
        <el-table-column prop="city" label="市" min-width="120" :resizable="false" align="center">
        </el-table-column>
        <el-table-column prop="distinct" label="区县" min-width="120" :resizable="false" align="center">
        </el-table-column>
        <el-table-column prop="mapName" label="地图名称" min-width="280" :resizable="false" align="center">
        </el-table-column>
        <el-table-column label="操作" width="125" align="center">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" :disabled="scope.row.status==1"
                       :type="scope.row.status==1?'primary':'info'" size="mini">
              {{ scope.row.status == 1 ? '已激活' : '未激活' }}
            </el-button>
<!--            <el-button type="success" size="mini" @click="editMap(scope.row)">编辑</el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="flex-page-footer" slot="footer">
      <div class="el-pagination-btns">
        <el-button type="primary" round size="mini" icon="el-icon-search" @click="searchData">查询</el-button>
      </div>
      <div class="el-pagination-btns">
        <el-button type="primary" round size="mini" icon="el-icon-plus" @click="addMap">新增关联地图</el-button>
      </div>
    </div>
    <el-dialog title="新增关联地图" width="300px" :visible.sync="addDialog" :close-on-click-modal="false" top="0"
               class="dialog-center" :modal-append-to-body="false">
      <add-chart-map :list="tableData" @success="addSuccess" v-if="addDialog"></add-chart-map>
    </el-dialog>
    <el-dialog title="编辑关联地图" width="600px" :visible.sync="editDialog" :close-on-click-modal="false" top="0"
               class="dialog-center" :modal-append-to-body="false">
      <edit-chart-map :mapjson="mapjson" @success="editSuccess" v-if="editDialog"></edit-chart-map>
    </el-dialog>
  </flex-layout>
</template>
 
<script>
import {
  getAllMapOutlineAction,
  activeMapOutlineAction
} from '../../assets/js/api.js';
import addChartMap from '@/components/chartMapSetting/addChartMap';
import editChartMap from '@/components/chartMapSetting/editChartMap';
import mapJson from "../../../public/mapJson/js";
 
export default {
  components: {
    addChartMap,
    editChartMap
  },
  data() {
    return {
      tableData: [],
      addDialog: false,
      editDialog: false,
      mapjson: {},
      mapList: mapJson.mapList()
    }
  },
  methods: {
    handleClick(data) { //点击激活
      if (data.status == 1) {
        return
      }
      this.$confirm('是否激活该地图?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        //发送请求传送至后台
        let loading = this.$layer.loading(1);
        let Id = {
          'id': data.id
        };
        activeMapOutlineAction(Id).then((res) => {
          let rs = JSON.parse(res.data.result);
          if (rs.code == 1) {
            this.$layer.msg('激活成功!');
            this.tableData.map((item, index) => {
              item.status = 0
            });
            data.status = 1
          } else {
            this.$layer.msg('激活失败!');
          }
          // 关闭加载框
          this.$layer.close(loading);
        }).catch((err) => {
          console.log(err);
          // 关闭加载框
          this.$layer.close(loading);
        });
      });
    },
    addMap() { //添加地图
      this.addDialog = true;
    },
    editMap(data) { //编辑地图
      this.mapjson = data;
      this.editDialog = true;
    },
    searchData() { //查询数据
      let loading = this.$layer.loading(1);
      getAllMapOutlineAction().then((res) => {
        let rs = JSON.parse(res.data.result);
        if (rs.code == 1) {
          let data = rs.data.map(item=>{
            let mapInfo = mapJson.getItemByValue(item.name, this.mapList);
            item.mapName = mapInfo.label;
            return item;
          });
          this.tableData = data;
        }
        // 关闭加载框
        this.$layer.close(loading);
      }).catch((err) => {
        console.log(err);
        // 关闭加载框
        this.$layer.close(loading);
        this.$layer.msg('查询失败!')
      });
    },
    addSuccess() { //添加成功后查询数据
      // 关闭弹出面板
      this.addDialog = false
      // 从新查询数据
      this.searchData();
    },
    editSuccess() { //编辑成功后查询数据
      // 关闭弹出面板
      this.editDialog = false
      // 从新查询数据
      this.searchData();
    }
  },
  mounted() {
    this.searchData()
  },
}
</script>
 
<style scoped>
 
</style>