hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<template>
  <div class="box-a">
    <v-header
      title="实有单位"
      :bar="bar"
      search
      @on-search="onSearch"
    ></v-header>
    <div class="but">
      <el-button
        @click="add()"
        size="small"
        type="primary"
      >新增</el-button>
      <el-button
        @click="exports()"
        size="small"
        type="primary"
      >导出</el-button>
      <div class="upload-box">
        <el-upload
          name="file"
          accept=".xls, .xlsx"
          :headers={Authorization:Authorization}
          class="upload-demo"
          :show-file-list="false"
          action="/api/huacheng-communitybackstage/common/data/company/import"
          :on-success="success"
          :on-error="error"
          multiple
        >
          <el-button
            type="primary"
            size="small"
          >导入
          </el-button>
        </el-upload>
      </div>
      <el-button
        @click="dow"
        size="small"
        type="primary"
      >下载模板</el-button>
    </div>
    <div>
      <v-tool-table
        :trs="trs"
        :tds="tds"
      >
        <template v-slot:category="{scope}">
          {{scope.category==1?'建筑类':'公共设施'}}
        </template>
        <template v-slot:floorType="{scope}">
          {{['','高层','中层','底层'][scope.floorType]}}
        </template>
        <template v-slot:btn="{scope}">
          <el-button
            @click="edit(scope.id)"
            type="text"
          >编辑</el-button>
          <el-button
            @click="clear(scope.id)"
            type="text"
          >删除</el-button>
        </template>
      </v-tool-table>
    </div>
    <v-tool-page
      :item="paged"
      @on-page="onPage"
    ></v-tool-page>
    <!---->
  </div>
</template>
<script>
export default {
  name: "index",
  props: [],
  components: {},
  data() {
    return {
      dialogVisible: false,
      Authorization: "",
      bar: [
        { title: "单位名称", name: "comName" },
        { title: "法人", name: "legalPerson" },
      ],
      tds: [],
      trs: [
        { text: "单位名称", val: "comName" },
        { text: "详细地址", val: "address", width: "" },
        { text: "法人", val: "legalPerson" },
        { text: "负责人", val: "leader" },
        { text: "联系人", val: "contactsPhone" },
        { text: "人员规模", val: "scope" },
        { text: "创建时间", val: "createAt" },
        { text: "操作", val: "btn" },
      ],
      search: {},
      paged: { pageNum: 1, total: 10, r: 0, pageSize: 10 },
    };
  },
  created() {
    this.Authorization = "Bearer " + demo.$session.get("token") || "";
    this.init();
  },
  mounted() {},
  watch: {},
  computed: {},
  methods: {
    edit(id) {
      this.$router.push({
        path: "/man_company_edit",
        query: { id: id },
      });
    },
    add() {
      // console.log(this.$route)
      this.$router.push({ path: "/man_company_edit" });
    },
    exports() {
      //导出
      this.$api.post("common/data/company/export", this.paged, (e) => {
        // console.log(e)
        window.location.href = e;
      });
    },
    clear(id) {
      this.$js.model("", "是否删除", (res) => {
        if (res) {
          this.$api.del("common/data/company/delete?id=" + id, "", (e) => {
            demo.toast("删除成功");
            this.init();
          });
        }
      });
    },
    onSearch(e) {
      // console.log(e)
      this.search = e;
      this.init();
    },
    init() {
      Object.assign(this.paged, this.search);
      this.$api.post("common/data/company/page", this.paged, (e) => {
        this.paged.total = e.total;
        this.tds = e.records;
      });
    },
    onPage(v) {
      //分页
      if (v.page === this.paged.pageNum && v.page && !v.reset) {
        return 0;
      }
      this.paged.pageNum = v.page;
      this.paged.pageSize = v.limit;
      this.init();
    },
    success(e) {
      if(e.code===200){
        demo.toast('导入成功');
      }else{
        demo.toast(e.msg);
      }
      this.init();
    },
    error(err) {
      console.log(err);
    },
    dow() {
      //下载模板
      this.$api.get("common/data/company/download/template", "", (e) => {
        // console.log(e)
        window.location.href = e;
      });
    },
  },
};
</script>
<style scoped>
.box-a {
  overflow: scroll;
}
.but {
  padding-bottom: 20px;
  display: flex;
}
.upload-box {
  margin: 0 16px;
}
</style>