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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<template>
  <div class="box-content">
    <v-header
      :title="titleName + '管理'"
      search
      :bar="bar"
      @on-search="onSearch"
    ></v-header>
    <div class="add fl-sb">
      <el-button type="primary" size="small" @click.stop="clickHandle('add')"
        >新增</el-button
      >
    </div>
    <div class="tab">
      <el-table :data="tableList" border ref="multipleTable" size="mini">
        <el-table-column label="序号" align="center" width="50" type="index">
        </el-table-column>
        <el-table-column label="网格员名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.name || "-" }}
          </template>
        </el-table-column>
        <el-table-column label="联系电话" align="center">
          <template slot-scope="scope">
            {{ scope.row.phone || "-" }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="所属社区" align="center">
          <template slot-scope="scope">
            {{ scope.row.ncommunityName || "-" }}
          </template>
        </el-table-column> -->
        <el-table-column label="操作" align="center" fixed="right" width="150">
          <template slot-scope="scope">
            <el-button
              size="small"
              type="text"
              style="padding: 0"
              @click="clickHandle('edit', scope.row)"
              >编辑</el-button
            >
            <el-button
              @click="clickHandle('delete', scope.row)"
              size="small"
              type="text"
              style="padding: 0"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <v-tool-page :item="paged" @on-page="onPage"></v-tool-page>
    <!-- 新增弹框 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleCloseData"
      append-to-body
    >
      <div>
        <el-form
          :model="form"
          :rules="rules"
          label-position="right"
          ref="ruleForm"
          label-width="150px"
          class="demo-ruleForm"
        >
          <el-form-item :label="titleName + '名称'" prop="name">
            <el-input
              class="input-width"
              placeholder="请输入"
              size="small"
              v-model.trim="form.name"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系电话" prop="phone">
            <el-input
              class="input-width"
              placeholder="请输入"
              size="small"
              v-model.trim="form.phone"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="请选择社区" prop="communityId">
            <el-select
              class="input-width"
              v-model="form.communityId"
              clearable
              placeholder="请选择社区"
            >
              <el-option
                v-for="item in communityList"
                :key="item.communityId"
                :label="item.name"
                :value="item.communityId"
              >
              </el-option>
            </el-select>
          </el-form-item> -->
        </el-form>
        <div class="fl-cen">
          <el-button size="small" @click="handleCloseData">取 消</el-button>
          <el-button
            size="small"
            type="primary"
            :loading="btnloading"
            @click="submitHandle"
            >确 定</el-button
          >
        </div>
      </div>
    </el-dialog>
    <!-- 查看详情 -->
  </div>
</template>
 
<script>
import { mapState } from "vuex";
import { objCopyPro, dateTime } from "../../utils/common";
export default {
  data() {
    return {
      titleName: "网格员",
      dialogVisible: false,
      dialogTitle: "新增",
      bar: [
        { title: "网格员名称", name: "name" },
        { title: "联系电话", name: "phone" },
        // {
        //   title: "所属小区",
        //   name: "communityId",
        //   type: "select",
        //   list: [],
        // },
      ],
      tableList: [],
      paged: { page: 0, total: 0, r: 0, limit: 10 },
      search: {},
      btnloading: false,
      form: {
        phone: "",
        name: "",
        communityId: "",
      }, // 表单
      rules: {
        name: [
          {
            required: true,
            message: "请输入网格员名称",
            trigger: "blur",
          },
        ],
        phone: [
          {
            required: true,
            message: "请输入联系电话",
            trigger: "blur",
          },
        ],
      }, // 表单验证
      communityList: [],
    };
  },
  computed: {
    ...mapState({ vuex_page: "pageReset" }),
  },
  watch: {
    vuex_page: {
      handler(n) {
        if (n.page === this.$route.path) {
          this.paged.page = 1;
          this.getTable();
        }
      },
      deep: true,
    },
  },
  mounted() {
    this.getCommunityList();
  },
  methods: {
    getCommunityList() {
      const ARR_COMMUNITY_LIST = [];
      this.$api.get("communityactivity/community/list", {}, (e) => {
        this.communityList = e;
        e.forEach((item) => {
          ARR_COMMUNITY_LIST.push({
            label: item.name,
            value: item.communityId,
          });
        });
        this.bar[2].list = ARR_COMMUNITY_LIST;
      });
    },
    reTime(t) {
      return dateTime(t);
    },
    onSearch(v) {
      this.search = demo.copy(v);
      this.paged.page = 1;
      this.getTable();
    },
    // 分页点击
    onPage(v) {
      if (v.page === this.paged.page && v.page && !v.reset) {
        return 0;
      }
      this.paged.page = v.page;
      this.paged.limit = v.limit;
      this.getTable();
    },
    // 获取数据
    getTable() {
      let v = demo.copy(
        Object.assign(this.search, {
          page: this.paged.page,
          size: this.paged.limit,
        })
      );
      this.$api.post("comActEasyPhotoMember/queryAll", v, (e) => {
        this.paged.total = e.total;
        this.paged.r++;
        this.tableList = e.records || [];
      });
    },
    clickHandle(type, row) {
      switch (type) {
        case "add": {
          this.dialogTitle = "新增";
          this.dialogVisible = true;
          break;
        }
        case "edit": {
          this.$api.get("comActEasyPhotoMember/" + row.id, {}, (e) => {
            e.communityId += "";
            this.form = objCopyPro(this.form, e);
            this.dialogTitle = "编辑";
            this.dialogVisible = true;
          });
          break;
        }
        case "delete": {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            this.$api.get("comActEasyPhotoMember/del", { id: row.id }, () => {
              demo.toast("删除成功");
              this.getTable();
            });
          });
          break;
        }
        default: {
          break;
        }
      }
    },
    submitHandle() {
      this.$refs["ruleForm"].validate((val) => {
        if (val) {
          if (this.dialogTitle === "新增") {
            this.$api.post("comActEasyPhotoMember", this.form, () => {
              demo.toast("新增成功");
              this.handleCloseData();
              this.getTable();
            });
          } else if (this.dialogTitle === "编辑") {
            this.$api.post("comActEasyPhotoMember/update", this.form, () => {
              demo.toast("编辑成功");
              this.handleCloseData();
              this.getTable();
            });
          }
        }
      });
    },
    handleCloseData() {
      this.$refs["ruleForm"].resetFields(); // 重置表单
      this.form = {
        phone: "",
        name: "",
        communityId: "",
      };
      this.dialogVisible = false;
    },
  },
};
</script>
<style>
.el-table .cell {
  font-size: 14px;
  color: #444;
}
.el-dialog {
  width: 800px !important;
}
</style>
<style lang='less' scoped>
.box-content {
  overflow-y: auto;
  .tab,
  .add {
    margin-bottom: 10px;
  }
}
.input-width {
  width: 250px;
}
.textarea-width {
  width: 350px;
}
.uopload-text {
  width: 100px;
  height: 100px;
  border: 1px dashed #999;
}
.label-text {
  width: 120px;
  text-align: right;
}
.content-text {
  width: 400px;
}
.l-15 {
  line-height: 1.5;
}
.goods-box {
  width: 400px;
}
</style>