Fixiaobai
2023-11-16 4bf457a5c8433c9ec6f0ec86b2c1c20c5e667391
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
<template>
  <div class="mod-config" style="height:100%;">
    <basic-container style="height:100%;" class="poc-basic-container">
      <el-row type="flex" justify="space-around" style="height:100%;">
        <el-col :span="13">
          <div>
            <div
              style="display:flex;justify-content:space-between;margin-bottom:8px;"
            >
              <div style="line-height:32px;font-weight:bold;">
                POC节点
              </div>
              <div><el-button @click="savePoc">保存</el-button></div>
            </div>
            <el-tree
              :data="treeData"
              node-key="id"
              default-expand-all
              :expand-on-click-node="false"
              @node-click="handleNodeClick"
            >
              <span class="custom-tree-node" slot-scope="{ node, data }">
                <span>{{ node.label }}</span>
                <span>
                  <el-button
                    type="text"
                    size="mini"
                    @click="() => append(data)"
                  >
                    新增
                  </el-button>
                  <el-button
                    type="text"
                    size="mini"
                    @click.stop="() => remove(node, data)"
                  >
                    删除
                  </el-button>
                </span>
              </span>
            </el-tree>
          </div>
        </el-col>
        <el-col :span="10">
          <div style="height: 100%;">
            <div style="display:flex;font-size:14px;margin-bottom:8px;">
              <div>标识:</div>
              <div>{{ currTreeNodeData.id }}</div>
            </div>
            <div
              style="display:flex;font-size:14px;justify-content:space-between;margin-bottom:8px;"
            >
              <div style="display:flex;width: 48%;">
                <div style="line-height:32px;width:70px;">节点描述:</div>
                <div style="width:calc(100% - 100px)">
                  <el-input v-model="currTreeNodeData.label"></el-input>
                </div>
              </div>
              <div style="display:flex;width: 48%;">
                <div style="line-height:32px;">工序:</div>
                <div style="width:calc(100% - 100px)">
                  <el-input v-model="currTreeNodeData.operationName"></el-input>
                </div>
              </div>
            </div>
            <div
              style="display:flex;font-size:14px;justify-content:space-between;margin-bottom:8px;"
            >
              <div style="display:flex;width: 48%;">
                <div style="line-height:32px;width:70px;">零件描述:</div>
                <div style="width:calc(100% - 100px)">
                  <el-input v-model="currTreeNodeData.partName"></el-input>
                </div>
              </div>
              <div style="display:flex;width: 48%;">
                <div style="line-height:32px;">数量:</div>
                <div style="width:calc(100% - 100px)">
                  <el-input v-model="currTreeNodeData.qty"></el-input>
                </div>
              </div>
            </div>
            <div
              style="display:flex;font-size:14px;justify-content:space-between;margin-bottom:8px;"
            >
              <div style="display:flex;width: 48%;">
                <div style="line-height:32px;width:70px;">单位:</div>
                <div style="width:calc(100% - 100px)">
                  <el-input v-model="currTreeNodeData.unit"></el-input>
                </div>
              </div>
            </div>
            <div
              style="display:flex;font-size:14px;margin-bottom:8px;justify-content:space-between;"
            >
              <div style="line-height:29px;">工序参数:</div>
              <div>
                <el-button
                  type="success"
                  icon="el-icon-plus"
                  circle
                  size="mini"
                  @click="addOperateParam"
                ></el-button>
              </div>
            </div>
            <div style="height: calc(100% - 180px)">
              <el-table
                :data="currTreeNodeData.paramList"
                style="width: 100%"
                height="100%"
              >
                <el-table-column type="index" width="50" label="序号">
                </el-table-column>
                <el-table-column prop="name" label="参数名" align="center">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.name"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="100" align="center">
                  <template slot-scope="scope">
                    <el-button
                      @click="deleteClick(scope.row, scope.$index)"
                      type="text"
                      size="small"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-col>
      </el-row>
    </basic-container>
  </div>
</template>
<style lang="scss" scoped>
.poc-basic-container >>> .el-card {
  height: 100%;
}
.poc-basic-container >>> .el-card__body {
  height: calc(100% - 20px);
}
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
</style>
<script>
import { mapGetters } from 'vuex'
import { addObj } from '@/api/basic/poc'
 
export default {
  data() {
    return {
      treeData: [
        {
          id: 1,
          label: '演示成品',
          operationName: '演示成品工序',
          partName: '演示成品',
          qty: 1,
          unit: 'km',
          paramList: [],
          children: []
        }
      ],
      idIndex: 1,
      currTreeNodeData: {}
    }
  },
  components: {},
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    append(data) {
      const newChild = {
        id: ++this.idIndex,
        label: '演示半成品零件',
        operationName: '演示半成品工序',
        partName: '演示半成品零件',
        qty: 1,
        unit: 'km',
        paramList: [],
        children: []
      }
      if (!data.children) {
        this.$set(data, 'children', [])
      }
      data.children.push(newChild)
    },
    remove(node, data) {
      const parent = node.parent
      const children = parent.data.children || parent.data
      const index = children.findIndex((d) => d.id === data.id)
      children.splice(index, 1)
      this.currTreeNodeData = {}
    },
    handleNodeClick(data) {
      console.log('data', data)
      this.currTreeNodeData = data
    },
    addOperateParam() {
      if (this.currTreeNodeData.id) {
        this.currTreeNodeData.paramList.push({ name: '' })
      } else {
        this.$message.warning('请选择节点')
      }
    },
    deleteClick(row, index) {
      console.log()
      this.currTreeNodeData.paramList.splice(index, 1)
      this.$message.success('删除成功')
    },
    savePoc() {
      console.log('treeData', this.treeData)
      if (this.treeData[0].children.length > 0) {
        addObj(this.treeData).then((response) => {
          this.$message.success('保存成功')
        })
      } else {
        this.$message.error('需大于两个POC节点,请添加节点')
      }
    }
  }
}
</script>