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
<template>
  <div class="page_policy">
    <v-header
      title="政策文件"
      search
      :bar="bar"
      @on-search="onSearch"
    ></v-header>
    <div class="add">
      <el-button type="primary" size="small" @click="add">新增</el-button>
    </div>
    <div class="tab">
      <v-tool-table :trs="trs" :tds="tds">
        <template v-slot:btn="item">
          <div class="table_flex">
            <!-- {{item.scope.id}} -->
            <span class="col_primary" @click="detail(item.scope)">查看</span>
            <span class="col_primary" @click="edit(item.scope)">编辑</span>
            <span class="col_primary" @click="del(item.scope)">删除</span>
          </div>
        </template>
        <template v-slot:time="item">
          <b>{{ time(item.scope.createAt) }}</b>
        </template>
        <template v-slot:status="item">
          <b>{{ item.scope.status * 1 === 2 ? "已发布" : "待发布" }}</b>
        </template>
        <template v-slot:policyType="item">
          <span v-if="item.scope.policyType===1">社工人才政策</span>
          <span v-if="item.scope.policyType===2">社会组织培育政策</span>
          <span v-if="item.scope.policyType===3">其他政策</span>
        </template>
      </v-tool-table>
    </div>
    <v-tool-page :item="paged" @on-page="onPage"></v-tool-page>
  </div>
</template>
 
<script>
import { mapState } from "vuex";
export default {
  props: {},
  components: {},
  data() {
    return {
      bar: [
        { title: "标题", name: "title" },
        {
          title: "状态",
          name: "status",
          type: "select",
          list: [
            { value: "1", label: "待发布" },
            { value: "2", label: "已发布" },
          ],
        },
        { title: "发布时间", name: "time", type: "times", types: "daterange" },
      ],
      trs: [
        { text: "序号", val: "id", width: "80px" },
        { text: "标题", val: "title" },
        { text: "阅览量", val: "readingVolume", width: "100px" },
        { text: "政策分类", val: "btn", slot: "policyType" },
        { text: "状态", val: "btn", slot: "status" },
        { text: "发布时间", val: "publishAt" },
        { text: "创建时间", val: "btn", slot: "time" },
        { text: "操作", val: "btn" },
      ],
      tds: [],
      paged: { page: 0, total: 0, r: 0, limit: 10 },
      search: {},
      os: {
        communityId: 0,
        content: "",
        cover: "",
        createAt: "",
        createBy: 0,
        createByName: "",
        id: 0,
        pageNum: 0,
        pageSize: 0,
        publishAt: "",
        publishAtBegin: "",
        publishAtEnd: "",
        readingVolume: 0,
        status: 0,
        title: "",
        type: 0,
      },
    };
  },
  watch: {
    vuex_page: {
      handler(n) {
        if (n.page === this.$route.path) {
          this.paged.page = 1;
          this.init();
        }
      },
      deep: true,
    },
  },
  computed: {
    ...mapState({ vuex_page: "pageReset" }),
  },
  methods: {
    // 时间转化
    time(v) {
      if (!v) return "";
      return demo.timeout(new Date(v).getTime(), "alls", "-");
    },
    // 查看
    detail(v) {
      this.$router.push(this.$nav.url("/com_policy_detail/" + v.id));
    },
    // 编辑
    edit(v) {
      this.$router.push(this.$nav.url("/com_policy_edit/" + v.id));
    },
    // 删除
    del(v) {
      this.$js.model("删除", "是否删除[" + v.title + "]", (res) => {
        if (res) {
          this.$api.del("communitypartybuilding/deletedynamic", v, () => {
            demo.toast("删除成功");
            this.init();
          });
        }
      });
    },
    // 分页点击
    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.init();
    },
    // 搜索
    onSearch(v) {
      this.search = demo.copy(v);
      if (v.time && v.time.length) {
        this.search.publishAtBegin = v.time[0];
        this.search.publishAtEnd = v.time[1];
      } else {
        this.search.publishAtBegin = "";
        this.search.publishAtEnd = "";
      }
      delete this.search.time;
      this.paged.page = 1;
      this.init();
    },
    // 新增
    add() {
      this.$router.push(this.$nav.url("/com_policy_add"));
    },
    init() {
      let v = demo.copy(Object.assign(this.os, this.search));
      v.type = "2";
      v.pageNum = this.paged.page;
      v.pageSize = this.paged.limit;
      this.$api.post("communitypartybuilding/pagedynamic", v, (e) => {
        this.paged.total = e.total;
        this.paged.r++;
        this.tds = e.records || [];
      });
    },
  },
  mounted() {},
};
</script>
<style lang='less' scoped>
.page_policy {
  overflow-y: auto;
  .tab,
  .add {
    margin-bottom: 10px;
  }
}
</style>