liding
2025-04-30 4ae5681e4a92c1cc98e811135098c71958c48a02
src/views/business/reliabilityPlan/index.vue
@@ -49,19 +49,21 @@
          <el-cascader v-model="proPlanForm.productName" :options="itemParameterData.cascaderField.sample.tree"
            :props="{ value: 'name', label: 'name', checkStrictly: false, multiple: false, emitPath: false }"
            :show-all-levels="false" clearable filterable placeholder="请选择产品名称" size="small" style="width: 100%;"
            :disabled="operationType === 'review'" @change="handleProductNameChange">
            :disabled="operationType === 'review' || operationType === 'submit'" @change="handleProductNameChange">
          </el-cascader>
        </el-form-item>
        <el-form-item label="产品型号" prop="productType">
          <el-select v-model="proPlanForm.productType" clearable filterable placeholder="请选择产品型号"
            :disabled="operationType === 'review' || !proPlanForm.productName" style="width: 100%;">
            :disabled="operationType === 'review' || !proPlanForm.productName || operationType === 'submit'"
            style="width: 100%;">
            <el-option v-for="item in typeOption" :key="item.id" :label="item.modelName" :value="item.modelName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="零件号" prop="partNo">
          <el-select v-model="proPlanForm.partNo" placeholder="请选择" clearable filterable
            :disabled="operationType === 'review' || !proPlanForm.productName" style="width: 100%;">
            :disabled="operationType === 'review' || !proPlanForm.productName || operationType === 'submit'"
            style="width: 100%;">
            <el-option v-for="item in partNoOption" :key="item.id" :label="item.partNo" :value="item.partNo">
            </el-option>
          </el-select>
@@ -76,25 +78,35 @@
      </el-form>
      <div slot="footer" class="foot">
        <el-button v-if="operationType !== 'review'" @click="closeProDia">取 消</el-button>
        <el-button v-if="operationType !== 'review'" type="primary" :loading="submitProLoading" @click="submitProForm">保
        <el-button v-if="operationType !== 'review' && operationType !== 'submit'" type="primary"
          :loading="submitProLoading" @click="submitProForm(0)">保
          存</el-button>
        <el-button v-if="operationType == 'submit'" type="primary" :loading="submitProLoading"
          @click="submitProForm(1)">提 交</el-button>
        <el-button v-if="operationType === 'review'" :loading="submitProLoading"
          @click="submitProForm(0)">不通过</el-button>
          @click="submitProForm(3)">不通过</el-button>
        <el-button v-if="operationType === 'review'" type="primary" :loading="submitProLoading"
          @click="submitProForm(1)">通过</el-button>
          @click="submitProForm(2)">通过</el-button>
        <el-button v-if="operationType === 'review'" type="primary" :loading="submitMatLoading"
          @click="submitProForm(0)">变 更</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="materialDia" title="原辅材计划">
      <el-form :model="materialForm" ref="materialForm" :rules="materialRules" label-width="90px" size="small">
        <el-form-item label="原辅材名称" prop="materialName">
          <el-cascader v-model="materialForm.materialName" :options="itemParameterData.cascaderField.sample.tree"
            :props="{ value: 'name', label: 'name', checkStrictly: false, multiple: false }" :show-all-levels="false"
            clearable filterable placeholder="请选择原辅材名称" size="small" style="width: 100%;"
            :disabled="operationType === 'review'"></el-cascader>
            :props="{ value: 'name', label: 'name', checkStrictly: false, multiple: false, emitPath: false }"
            :show-all-levels="false" clearable filterable placeholder="请选择原辅材名称" size="small" style="width: 100%;"
            :disabled="operationType === 'review' || operationType === 'submit'" @change="handleMaterialNameChange">
          </el-cascader>
        </el-form-item>
        <el-form-item label="零件号" prop="partNo">
          <el-input v-model="materialForm.partNo" placeholder="请填写零件号"
            :disabled="operationType === 'review'"></el-input>
          <el-select v-model="materialForm.partNo" placeholder="请选择" clearable filterable
            :disabled="operationType === 'review' || !materialForm.materialName || operationType === 'submit'"
            style="width: 100%;">
            <el-option v-for="item in materialPartNoOption" :key="item.id" :label="item.partNo" :value="item.partNo">
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="审核人" prop="reviewerId">
          <el-select v-model="proPlanForm.reviewerId" clearable filterable size="small" style="width: 50%;"
@@ -105,13 +117,18 @@
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="foot">
        <el-button v-if="operationType !== 'review'" @click="closeMaterialRulesDia">取 消</el-button>
        <el-button v-if="operationType !== 'review'" type="primary" :loading="submitMatLoading"
          @click="submitMaterialRulesForm">保 存</el-button>
        <el-button v-if="operationType !== 'review'" @click="closeMaterialRulesDia">取
          消</el-button>
        <el-button v-if="operationType !== 'review' && operationType !== 'submit'" type="primary"
          :loading="submitMatLoading" @click="submitMaterialRulesForm(0)">保 存</el-button>
        <el-button v-if="operationType == 'submit'" type="primary" :loading="submitProLoading"
          @click="submitMaterialRulesForm(1)">提 交</el-button>
        <el-button v-if="operationType === 'review'" :loading="submitMatLoading"
          @click="submitMaterialRulesForm(0)">不通过</el-button>
          @click="submitMaterialRulesForm(3)">不通过</el-button>
        <el-button v-if="operationType === 'review'" type="primary" :loading="submitMatLoading"
          @click="submitMaterialRulesForm(1)">通过</el-button>
          @click="submitMaterialRulesForm(2)">通 过</el-button>
        <el-button v-if="operationType === 'review'" type="primary" :loading="submitMatLoading"
          @click="submitMaterialRulesForm(0)">变 更</el-button>
      </div>
    </el-dialog>
  </div>
@@ -146,6 +163,7 @@
      tableData: [],
      typeOption: [],
      partNoOption: [], // 添加产品型号选项数据
      materialPartNoOption:[],
      tableLoading: false,
      itemParameterData: {
        cascaderField: {
@@ -163,21 +181,25 @@
          label: '审核状态',
          prop: 'state',
          formatData: (params) => {
            if (params == 1) {
            if (params == 0 || !params) {
              return '待提交'
            } else if (params == 1) {
              return '待审核'
            } else if (params == 2) {
              return '通过'
            } else if (params == 0) {
            } else if (params == 3) {
              return '不通过'
            } else {
              return null
            }
          },
          formatType: (params) => {
            if (params == 1) {
              return 'success'
            } else if (params == 0) {
            if (params == 0 || !params) {
              return 'warning'
            } else if (params == 1) {
              return 'danger'
            } else {
              return null
            } else if (params == 2) {
              return 'success'
            } else if (params == 3) {
              return 'danger'
            }
          }
        },
@@ -191,7 +213,33 @@
              type: 'text',
              clickFun: (row) => {
                this.openAddDia('edit', row);
              }
              },
              disabled: (row) => {
                return row.state > 0
              },
            },
            {
              name: '计划',
              type: 'text',
              clickFun: (row) => {
                this.$router.push({
                  path: "/reliabilityPlan/plan", query: {
                    id: row.id,
                    type: '成品',
                    state: row.state
                  }
                });
              },
            },
            {
              name: '提交',
              type: 'text',
              clickFun: (row) => {
                this.openAddDia('submit', row);
              },
              disabled: (row) => {
                return row.state > 0
              },
            },
            {
              name: '审核',
@@ -207,7 +255,7 @@
                this.handleDelete(row);
              },
              disabled: (row) => {
                return row.state == 1
                return row.state > 0
              },
            },
          ]
@@ -230,21 +278,25 @@
          label: '审核状态',
          prop: 'state',
          formatData: (params) => {
            if (params == 1) {
            if (params == 0 || !params) {
              return '待提交'
            } else if (params == 1) {
              return '待审核'
            } else if (params == 2) {
              return '通过'
            } else if (params == 0) {
            } else if (params == 3) {
              return '不通过'
            } else {
              return null
            }
          },
          formatType: (params) => {
            if (params == 1) {
              return 'success'
            } else if (params == 0) {
            if (params == 0 || !params) {
              return 'warning'
            } else if (params == 1) {
              return 'danger'
            } else {
              return null
            } else if (params == 2) {
              return 'success'
            } else if (params == 3) {
              return 'danger'
            }
          }
        },
@@ -258,7 +310,33 @@
              type: 'text',
              clickFun: (row) => {
                this.openAddDia('edit', row);
              }
              },
              disabled: (row) => {
                return row.state > 0
              },
            },
            {
              name: '计划',
              type: 'text',
              clickFun: (row) => {
                this.$router.push({
                  path: "/reliabilityPlan/plan", query: {
                    id: row.id,
                    type: '原辅材',
                    state: row.state
                  }
                });
              },
            },
            {
              name: '提交',
              type: 'text',
              clickFun: (row) => {
                this.openAddDia('submit', row);
              },
              disabled: (row) => {
                return row.state > 0
              },
            },
            {
              name: '审核',
@@ -274,7 +352,7 @@
                this.handleDeleteM(row);
              },
              disabled: (row) => {
                return row.state == 1
                return row.state > 0
              },
            },
          ]
@@ -376,9 +454,6 @@
    // 打开新增弹框
    openAddDia(type, row) {
      this.operationType = type
      this.getTypeOptions()
      this.getPartNoOptions()
      // this.getUserList()
      if (this.tabIndex === 0) {
        this.proPlanDia = true
        if (this.operationType === 'add') {
@@ -391,31 +466,78 @@
          }
        } else {
          this.proPlanForm = { ...row }
          // 编辑时获取选中节点的ID并加载相关数据
          const selectedNode = this.findNodeById(this.itemParameterData.cascaderField.sample.tree, row.productName)
          if (selectedNode) {
            this.getTypeOptions(selectedNode.id)
            this.getPartNoOptions(selectedNode.id)
          }
        }
      } else {
        this.materialDia = true
        if (this.operationType === 'add') {
          this.materialForm = {
            id: '',
            materialName: '',
            partNo: '',
            state: '',
            reviewerId: ''
          if (this.operationType === 'add') {
            this.materialForm = {
              id: '',
              materialName: '',
              partNo: '',
              state: '',
              reviewerId: ''
            }
          } else {
            this.materialForm = { ...row }
            // 编辑时获取选中节点的ID并加载相关数据
            const selectedNode = this.findNodeById(this.itemParameterData.cascaderField.sample.tree, row.materialName)
            if (selectedNode) {
              this.getMaterialPartNoOptions(selectedNode.id)
            }
          }
        } else {
          this.materialForm = { ...row }
        }
      }
    },
    //原辅材零件号选择
    handleMaterialNameChange(value) {
        if (value) {
          const selectedNode = this.findNodeById(this.itemParameterData.cascaderField.sample.tree, value)
          if (selectedNode) {
            this.getMaterialPartNoOptions(selectedNode.id)
          }
        } else {
          this.materialPartNoOption = []
          this.materialForm.partNo = ''
        }
      },
      // 获取原辅材零件号列表
      getMaterialPartNoOptions(materialId) {
        if (!materialId) {
          this.materialPartNoOption = []
          return
        }
        getPartNoList({ productId: materialId }).then(res => {
          if (res.code === 200) {
            this.materialPartNoOption = res.data || []
            if (this.materialPartNoOption.length === 0) {
              this.materialForm.partNo = ''
            }
          }
        }).catch(() => {
          this.materialPartNoOption = []
          this.materialForm.partNo = ''
        })
      },
    // 成品信息提交
    submitProForm(state) {
      this.submitProLoading = true
      if (this.operationType === 'add') {
        this.proPlanForm.state = ''
      } else {
        this.proPlanForm.state = state
      // 获取选中节点的ID
      const selectedNode = this.findNodeById(this.itemParameterData.cascaderField.sample.tree, this.proPlanForm.productName)
      const params = {
        ...this.proPlanForm,
        state: state === undefined ? null : parseInt(state),
        productId: selectedNode?.id,
        itemType: ['成品', '原辅材'][this.tabIndex] // 0成品1原辅材
      }
      addOrUpdateProduct(this.proPlanForm).then(res => {
      addOrUpdateProduct(params).then(res => {
        if (res.code === 200) {
          this.closeProDia()
          this.$message.success('操作成功')
@@ -435,12 +557,14 @@
    // 原辅材信息提交
    submitMaterialRulesForm(state) {
      this.submitMatLoading = true
      if (this.operationType === 'add') {
        this.materialForm.state = ''
      } else {
        this.materialForm.state = state
      // 获取选中节点的ID
      const selectedNode = this.findNodeById(this.itemParameterData.cascaderField.sample.tree, this.materialForm.materialName)
      const params = {
        ...this.materialForm,
        state: state === undefined ? null : parseInt(state),
        materialId: selectedNode?.id
      }
      addOrUpdateMaterial(this.materialForm).then(res => {
      addOrUpdateMaterial(params).then(res => {
        if (res.code === 200) {
          this.closeMaterialRulesDia()
          this.$message.success('操作成功')