jinlin
2024-10-22 26ebef24f023a80f5be5ff27c93585f70688f6ee
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
<template>
  <div class="mod-taskReliability-operatConditModel}">
    <zt-table-wraper @dataLoaded="dataLoaded" ref="tableObj" :paging='false' defaultNotQuery="true"
                     query-url="/taskReliability/OperatConditModel/page"
                     delete-url="/taskReliability/OperatConditModel/" v-slot="{ table }">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="table.query()">
        <el-form-item>
          <el-button v-if="dataForm.productId" type="primary" @click="save()">保存</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="table.dataLoading" :data="table.dataList" height="100px"
                v-adaptive="{bottomOffset:70}" border @selection-change="table.selectionChangeHandle"
                row-key="iid"
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                :default-expand-all="true">
        <el-table-column prop="productName" label="产品节点"/>
        <el-table-column prop="modelId" label="产品模型">
          <template slot-scope="scope">
            <el-select v-model="scope.row.modelId" :disabled="scope.row.isDisabled == 1" placeholder="请选择"
                       style="width:100%" @change="modelChanged(scope.row)">
              <el-option
                         v-for="item in scope.row.modelList"
                         :key="item.id"
                         :label="item.modelName"
                         :value="item.id"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100px">
          <template v-slot="{ row }">
            <el-button v-if="row.modelId" type="primary" size="small" @click="drawRBD(row)">查看模型</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog v-dialogDrag :title="title" top="1vh" width='95%' :visible.sync="dialogVisible2" v-if="dialogVisible2">
        <model-view ref="modelView"></model-view>
      </el-dialog>
    </zt-table-wraper>
  </div>
</template>
 
<script>
  import ModelView from "./ModelView";
  import cloneDeep from 'lodash/cloneDeep'
 
  export default {
    name: 'OperaConditModel',
    data() {
      return {
        dataForm: {
          id: '',
          operatConditId: '',
          productId: '',
        },
        mapModelNodes: {},
        modelList: [],
        dialogVisible2: false,
        isChange: false,
        title: ''
      }
    },
    components: {
      ModelView
    },
    mounted() {
      this.getModelNodes()
    },
    methods: {
      init(param) {
        console.log(param, '')
        this.dataForm.operatConditId = param.row.id
        this.dataForm.productId = param.productId
        this.$refs.tableObj.query()
      },
      dataLoaded(dataList) {
        dataList[0].isDisabled = 0
        if (!dataList[0].modelId && dataList[0].modelList.length == 1) {
          console.log(dataList[0].modelList[0].id, ' dataList[0].modelList[0].modelId')
          dataList[0].modelId = dataList[0].modelList[0].id
          console.log(dataList[0], 'dataLoaded(dataList)')
          this.modelChangedProess(dataList[0])
        }
      },
      async save() {
        let res = await this.$http.post('/taskReliability/OperatConditModel/', this.$refs.tableObj.dataList[0])
        if (res.success) {
          this.$tip.success()
          this.isChange = false
          this.$refs.tableObj.query()
        }
      },
      async getModelNodes() {
        let res = await this.$http.get(`/taskReliability/OperatConditModel/getModelNodes?shipId=0`)
        console.log(res, 'res taskReliability')
        console.log(res.data, 'res.data taskReliability')
        if (res.data) {
          this.mapModelNodes = res.data
 
        }
      },
      modelChanged(row) {
        this.isChange = true
        this.modelChangedProess(row)
      },
      modelChangedProess(row) {
        let modelId = row.modelId
        let modelNodes = this.mapModelNodes[modelId]
        console.log(modelId, 'modelChanged modelId')
        console.log(modelNodes, 'modelChanged modelNodes')
        console.log(row.children, 'row.children')
 
        for (let subRow of row.children) {
          console.log(subRow, 'subRow')
          console.log(subRow.productId, 'subRow.productId')
          if (modelNodes.indexOf(subRow.productId) != -1) {
            subRow.isDisabled = 0
            if (subRow.modelList.length == 1) {
              subRow.modelId = subRow.modelList[0].id
              console.log(subRow.modelId, 'subRow.modelId 111')
              console.log(this.mapModelNodes[subRow.modelId], 'this.mapModelNodes[subRow.modelId] 111')
            } else {
              //subRow.modelId = null
            }
          } else {
            subRow.isDisabled = 1
            subRow.modelId = null
          }
          this.nodeIteration(subRow)
        }
      },
      nodeIteration(parentRow) {
        for (let subRow of parentRow.children) {
          if (parentRow.modelId) {
            subRow.isDisabled = 0
            if (subRow.modelList.length == 1) {
              subRow.modelId = subRow.modelList[0].id
            }
          } else {
            subRow.isDisabled = 1
            subRow.modelId = null
          }
          this.nodeIteration(subRow)
        }
      },
      drawRBD(row) {
        this.dialogVisible2 = true
        this.title=row.modelName + '模型设计'
        let param = {
          id: row.modelId,
          modelName: row.modelName,
        }
        this.$nextTick(() => {
          this.$refs.modelView.init(param)
        })
      }
    }
  }
</script>