duhuizhe
2023-10-16 3aa55dd3f62cee2c1c4c0aa74e1570acf83f8927
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
<template>
  <win-lg :title="setting.title" @close="close" :width="'800px'">
    <el-card class="box-card" shadow="never">
      <div class="filter-container" style="margin-bottom: 10px">
        <my-search ref="searchBar" :items="items" @search="filterForm"></my-search>
      </div>
      <!--列表-->
      <my-table-v2 ref="myTable" :filter="filterFrom" :table="table"/>
    </el-card>
    <edit v-if="editSetting.show" :setting="editSetting" @close="closeNode" @search="search"></edit>
  </win-lg>
</template>
 
<script>
import MyTableV2 from '@/components/myTable/myTableV2';
import winLg from '@/components/win/win-lg'
import SettingIplatform from '@/utils/settingIplatform';
import items from './items';
import edit from './edit'
import {del, updStatus} from "@/api/projectConfig/stageNode";
 
export default {
  name: 'nodeConfig',
  components: {MyTableV2, winLg, edit},
  props: {
    // setting 中须至少包含控制dialog显示或隐藏的属性,其余属性可拓展
    // 将添加/修改的大量数据及逻辑从列表页面中分离出来,避免列表页面代码过多,审查困难
    // 若此页面须回传数据至父页面,可在引用组件时添加事件,本页面使用this.$emit('事件名',参数1,参数2...)回传数据
    setting: {
      type: Object,
      default: () => {
      }
    }
  },
  data() {
    return {
      // 搜索条件
      items: items,
      filterFrom: {
        nodeName: '',
        status: '1',
      },
      //新增编辑
      editSetting: {
        title: '',
        id: '',
        show: false,
      },
      // 表格数据
      table: {
        showIndex: true, // 是否显示序号
        expand: false, // 是否显示详情数据
        url: SettingIplatform.apiBaseURL + '/pc/p/temp/stage/node/list?stageId='+this.setting.stageId, // 请求地址
        // 工具条
        tools: {
          columnsCtrl: {
            // 列控制按钮
            show: false,
          },
          generalExport: {
            // 通用导出按钮
            show: false,
          },
          // 自定义工具条按钮
          custom: [
            {
              name: '新增',
              click: () => {
                this.showAdd(null);
              },
            },
          ],
        },
        // 列信息
        columns: [
          {title: '节点名称', field: 'nodeName', align: 'center'},
          {title: '顺序号', field: 'sort', align: 'center'},
          {title: '说明', field: 'remark', align: 'center'},
          {
            field: 'status',
            title: '状态',
            align: 'center',
            width: 80,
            switch: (row) => {
              return {
                value: row.status === 1, // 开
                label: row.status === 1 ? '启用' : '禁用', // 开的描述
                click: () => {
                  // 点击事件
                  this.updState(row);
                },
              };
            },
          },
        ],
        // 操作信息
        operation: {
          show: true, // 显示操作列
          width: '200', // 列宽
          attr: [
            {
              title: '编辑',
              events: (row) => {
                this.showAdd(row.id);
              },
            },
            {
              title: '删除',
              events: (row) => {
                this.handleDelete(row);
              },
            },
          ],
        },
        paging: {
          show: true, // 显示分页
          // 分页信息
          page: {
            small: false,
            pageNum: 1,
            pageSize: 10,
            total: 0,
          },
        },
      },
    };
  },
  mounted() {
  },
  methods: {
    close() {
      this.$emit('close')
    },
    closeNode() {
      this.editSetting.show = false
      this.$emit('search')
    },
    // 查询table列表
    search(pageNum) {
      if (pageNum != undefined) {
        this.$refs.myTable.search(pageNum);
      } else {
        this.$refs.myTable.search();
      }
    },
    filterForm(params) {
      this.filterFrom = Object.assign(this.filterFrom, params);
      this.search();
    },
    //添加、编辑
    showAdd(id) {
      let title = '添加';
      if (id != null) {
        title = '编辑';
      }
      this.editSetting.id = id||this.setting.id;
      this.editSetting.stageId = this.setting.stageId;
      this.editSetting.title = title;
      this.editSetting.show = true;
    },
    updState(row) {
      let text = row.status === 0 ? "启用" : "禁用";
      this.$modal.confirm('确认要' + text + '"' + row.nodeName + '"吗?').then(() => {
        let status = row.status === 1 ? 0 : 1
        updStatus({
          id: row.id,
          status
        }).then(res => {
          if (res) {
            row.status = row.status === 1 ? 0 : 1
            this.$modal.msgSuccess(text + "成功");
            this.search()
          }
        })
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除"' + row.nodeName + '"阶段?', {
        type: 'warning'
      }).then(() => {
        del({id:row.id}).then(res=>{
          this.$modal.msgSuccess( "删除成功");
          this.search()
        })
      })
    },
  },
};
</script>
 
<style scoped></style>