zouyu
2023-11-16 a4add192450f06f9e4748e6513234510f431b21e
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
<template>
  <el-dialog
    width="80%"
    top="5vh"
    title="起始工序-工艺路线"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    class="operation-technology-dialog"
  >
    <div style="display:flex;justify-content:space-between;">
      <div style="width:47%;">
        <el-table
          ref="operationMultipleTable"
          class="operation-multiple-table"
          :data="operationList"
          tooltip-effect="dark"
          style="width: 100%"
          height="600"
          @selection-change="handleSelectionChange"
          @row-click="rowClick"
        >
          <el-table-column
            type="selection"
            width="55"
            :selectable="selectHandle"
          >
          </el-table-column>
          <el-table-column prop="operationNo" label="工序编号" width="120">
          </el-table-column>
          <el-table-column prop="name" label="工序名称" width="120">
          </el-table-column>
          <el-table-column prop="workCenter" label="工作中心" width="120">
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间">
          </el-table-column>
        </el-table>
      </div>
      <div style="width:47%;height: 600px;overflow:auto;">
        <div
          v-for="(item, index) in operateRoutingList"
          :key="index"
          style="margin-bottom:10px;"
        >
          <div style="font-weight:bold;">{{ item.operateName }}</div>
          <el-table
            :ref="'routing_' + item.operateId"
            :data="item.routingList"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="
              routingHandleSelectionChange($event, 'routing' + item.operateId)
            "
          >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column prop="routingNo" label="工艺路线编号">
            </el-table-column>
            <el-table-column prop="partNo" label="零件编号"> </el-table-column>
            <el-table-column
              prop="partName"
              label="零件名称"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间">
            </el-table-column>
            <el-table-column label="开启批次" width="100">
              <template slot-scope="scope">
                <el-switch v-model="scope.row.isGenerateSn"> </el-switch>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="innerVisible = false">取 消</el-button>
      <el-button
        type="primary"
        :disabled="isSubmit"
        v-thinclick="`selectRouting`"
        >确 定</el-button
      >
    </div>
  </el-dialog>
</template>
<script>
import { getRoutingByDocumentIdAndOperationId } from '@/api/technology/routing'
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    operationList: {
      type: Array,
      default: () => {
        return []
      }
    },
    taskList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      innerVisible: false,
      isSubmit: false,
      multipleSelection: [],
      operateRoutingList: []
    }
  },
  created() {},
  methods: {
    rowClick(row, column) {
      if (row.commonChecked) {
        // 取消选中,并删除左侧工序及对应工艺路线列表
        row.commonChecked = false
        this.$refs.operationMultipleTable.toggleRowSelection(row, false)
        // 删除右侧对应的工艺路线
        this.delTechnologyList(row)
      } else {
        // 选中,并增加左侧工序及对应工艺路线列表
        row.commonChecked = true
        this.$refs.operationMultipleTable.toggleRowSelection(row, true)
        this.queryTechnologyList(row)
      }
    },
    selectHandle(row, index) {
      return false
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    routingHandleSelectionChange(val, routingType) {
      this[routingType] = val
    },
    // 删除工序对应的工艺路线
    delTechnologyList(operation) {
      // 根据id,找出technology
      const operateRouting = this.operateRoutingList.find((item) => {
        return item.operateId == operation.id
      })
      if (operateRouting) {
        const operateRoutingIndex = this.operateRoutingList.indexOf(
          operateRouting
        )
        // 删除时,记录下operateRoutingIndex之后,list中已勾选的信息
        const cacheList = []
        for (
          let i = operateRoutingIndex + 1;
          i < this.operateRoutingList.length;
          i++
        ) {
          const operateId = this.operateRoutingList[i].operateId
          const routingSelection = 'routing' + operateId
          cacheList.push({
            operateId: operateId,
            routingList: this[routingSelection]
          })
        }
        this.operateRoutingList.splice(operateRoutingIndex, 1)
        const _that = this
        this.$nextTick(() => {
          cacheList.forEach((item) => {
            const refName = 'routing_' + item.operateId
            const routingList = item.routingList
            routingList.forEach((ele) => {
              _that.$refs[refName][0].toggleRowSelection(ele, true)
            })
          })
        })
      }
    },
    // 查询工序对应的工艺路线
    queryTechnologyList(operation) {
      getRoutingByDocumentIdAndOperationId({
        documentId: this.taskList[0].technologyDocumentId,
        operationId: operation.id
      }).then((response) => {
        const resData = response.data
        const routingList = resData.data
        routingList.forEach((ele) => {
          this.$set(ele, 'isGenerateSn', true)
        })
        this.operateRoutingList.push({
          operateId: operation.id,
          operateName: operation.name,
          routingList: routingList
        })
        const routingRef = 'routing_' + operation.id
        const _that = this
        this.$nextTick(() => {
          _that.$refs[routingRef][0].toggleAllSelection(true)
        })
      })
    },
    selectRouting() {
      this.isSubmit = true
 
      // 拼接工艺路线
      const resultList = []
      this.operationList.forEach((item) => {
        if (item.commonChecked) {
          const routingSelection = 'routing' + item.id
          const routingSelectList = this[routingSelection]
          resultList.push({
            operationId: item.id,
            operationName: item.name,
            routingList: routingSelectList
          })
        }
      })
      console.log('resultList', resultList)
      if (resultList.length > 0 && resultList[0].routingList.length > 0) {
        let flag = true
        resultList.forEach((ele) => {
          if (
            ele.routingList &&
            ele.routingList != null &&
            ele.routingList.length > 0
          ) {
          } else {
            flag = false
          }
        })
        if (flag) {
          this.$emit('selectionRouting', resultList)
          this.innerVisible = false
        } else {
          this.$message.error('请选择工艺路线')
        }
      } else {
        this.$message.error('请先选择起始工序')
      }
 
      this.isSubmit = false
    }
  },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
      if (this.currshowlist) {
        this.operateRoutingList = []
        this.$nextTick(() => {
          //
        })
      }
    }
  },
  mounted() {}
}
</script>
<style scoped>
.operation-technology-dialog >>> .el-dialog__body {
  padding: 10px 20px 10px 20px;
}
/*默认已选中行,checkbox样式,多选*/
.operation-technology-dialog
  >>> .operation-multiple-table
  .el-table-column--selection
  .el-checkbox.is-checked
  .el-checkbox__inner {
  background-color: #006eff;
  border-color: #006eff;
}
.operation-technology-dialog
  >>> .operation-multiple-table
  .el-table-column--selection
  .el-checkbox.is-checked
  .el-checkbox__inner::after {
  border-color: #ffffff;
}
</style>