Houjie
3 天以前 ac71a144eeac2a5586c37686e72442173bfb1407
src/views/andon/modules/AndonResponseConfigForm.vue
@@ -1,49 +1,71 @@
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
    <j-form-container :disabled="disabled" class="andon-response-form">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
        <!-- 产线选择 -->
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item label="产线" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="factoryId">
              <a-row :gutter="24">
                <a-col :span="24">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label=""
                  >
                    <j-select-factory
                      :disabled="disabled"
                      v-model="model.factoryId"
                      :multi="true"
                      @back="backFactoryInfo"
                      :backProduction="true"
                      :treeProductOpera="true"
                    ></j-select-factory>
                  </a-form-item>
                </a-col>
              </a-row>
              <a-tree-select
                :disabled="disabled"
                v-model="model.factoryId"
                :tree-data="factoryTreeData"
                :allow-clear="true"
                :show-search="false"
                :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
                :tree-check-strictly="true"
                placeholder="请选择"
                style="width: 100%"
                @change="handleFactoryChange"
                class="custom-tree-select">
              <template slot="title" slot-scope="item">
                {{ item.title }}
              </template>
              </a-tree-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        <!-- 安灯类型和响应人配置 -->
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item label="安灯类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buttonId">
              <j-search-select-tag v-model="model.buttonId" placeholder="请输入安灯类型"
                                   dict="andon_button_config,button_name,id"></j-search-select-tag>
              <j-search-select-tag
                v-model="model.buttonId"
                placeholder="请选择"
                dict="andon_button_config,button_name,id"
              ></j-search-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="初始响应人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="firsterResponder">
              <j-select-user-by-dep :multi="false" v-model="model.firsterResponder" placeholder="请输入初始响应人"  ></j-select-user-by-dep>
            <a-form-model-item label="初始响应人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="firstResponder">
              <j-select-user-by-dep
                :multi="false"
                v-model="model.firstResponder"
                placeholder="请选择"
              ></j-select-user-by-dep>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item label="二级响应人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="secondResponder">
              <j-select-user-by-dep
                :multi="false"
                v-model="model.secondResponder"
                placeholder="请选择"
              ></j-select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="二级响应人(升级一次)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="secondResponder">
              <j-select-user-by-dep :multi="false" v-model="model.secondResponder" placeholder="请输入二级响应人(升级一次)"  ></j-select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="三级响应人(升级两次)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thirdResponder">
              <j-select-user-by-dep :multi="false" v-model="model.thirdResponder" placeholder="请输入三级响应人(升级两次)"  ></j-select-user-by-dep>
            <a-form-model-item label="三级响应人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thirdResponder">
              <j-select-user-by-dep
                :multi="false"
                v-model="model.thirdResponder"
                placeholder="请选择"
              ></j-select-user-by-dep>
            </a-form-model-item>
          </a-col>
        </a-row>
@@ -53,113 +75,157 @@
</template>
<script>
import { httpAction, getAction } from '@/api/manage'
import { TreeSelect } from 'ant-design-vue'
  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import JSelectFactory from '@comp/jeecgbiz/JSelectFactory.vue'
  export default {
    name: 'AndonResponseConfigForm',
    components: {
      JSelectFactory
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
export default {
  name: 'AndonResponseConfigForm',
  components: {
    'a-tree-select': TreeSelect
  },
  props: {
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      model: {
        factoryId: '',
        buttonId: '',
        firstResponder: '',
        secondResponder: '',
        thirdResponder: ''
      },
      factoryTreeData: [],
      labelCol: { xs: { span: 24 }, sm: { span: 6 } },
      wrapperCol: { xs: { span: 24 }, sm: { span: 18 } },
      confirmLoading: false,
      validatorRules: {
        factoryId: [{ required: true, message: '产线是必选项', trigger: 'change' }],
        buttonId: [{ required: true, message: '安灯类型是必选项', trigger: 'change' }],
        firstResponder: [{ required: true, message: '初始响应人是必选项', trigger: 'change' }],
        secondResponder: [{ required: true, message: '二级响应人是必选项', trigger: 'change' }],
        thirdResponder: [{ required: true, message: '三级响应人是必选项', trigger: 'change' }]
      },
      url: {
        add: "/andonresponseconfig/andonResponseConfig/add",
        edit: "/andonresponseconfig/andonResponseConfig/edit",
        factoryTree: "/base/factory/queryTreeList"
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          factoryId: [
            { required: true, message: '产线是必选项', trigger: 'change' }
          ],
          buttonId: [
            { required: true, message: '安灯类型是必选项', trigger: 'change' }
          ],
          firsterResponder: [
            { required: true, message: '初始响应人是必选项', trigger: 'change' }
          ],
          secondResponder: [
            { required: true, message: '二级响应人是必选项', trigger: 'change' }
          ],
          thirdResponder: [
            { required: true, message: '三级响应人是必选项', trigger: 'change' }
          ],
        },
        url: {
          add: "/andonresponseconfig/andonResponseConfig/add",
          edit: "/andonresponseconfig/andonResponseConfig/edit",
          queryById: "/andonresponseconfig/andonResponseConfig/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      backFactoryInfo(info) {
        this.model.factoryIds = this.model.factoryId
        this.nextFactoryOptions = info.map((item, index, arr) => {
          let c = { label: item.text, value: item.value + '' }
          return c
        })
      },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
    }
  },
  created() {
    this.modelDefault = { ...this.model }
    this.loadFactoryTree()
  },
  methods: {
    loadFactoryTree() {
      this.confirmLoading = true
      getAction(this.url.factoryTree)
        .then(res => {
          if (res.success && Array.isArray(res.result)) {
            this.factoryTreeData = this.transformData(res.result)
            console.log('产线数据加载成功:', this.factoryTreeData)
          } else {
            this.$message.warning('产线数据为空或格式异常')
            this.factoryTreeData = []
          }
        })
      },
        .catch(err => {
          console.error('产线数据加载失败:', err)
          this.$message.error('加载产线数据失败,请重试')
        })
        .finally(() => {
          this.confirmLoading = false
        })
    },
    transformData(nodes) {
      return nodes.map(node => ({
        key: node.id,
        title: node.factoryName,
        value: node.id,
        children: node.children && node.children.length > 0 ? this.transformData(node.children) : []
      }))
    },
    handleFactoryChange(value) {
      this.model.factoryId = value
    },
    add() {
      this.model = { ...this.modelDefault }
      this.visible = true
    },
    edit(record) {
      this.model = { ...record }
      this.visible = true
    },
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.confirmLoading = true
          const httpurl = this.model.id ? this.url.edit : this.url.add
          const method = this.model.id ? 'put' : 'post'
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                this.$message.success(res.message)
                this.$emit('ok')
              } else {
                this.$message.warning(res.message)
              }
            })
            .finally(() => {
              this.confirmLoading = false
            })
        }
      })
    }
  }
</script>
}
</script>
<style scoped>
.andon-response-form {
  padding: 24px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.a-form-model-item {
  margin-bottom: 20px !important;
}
.ant-tree-select-selection {
  min-height: 32px !important;
}
/* 树形选择组件自定义样式 */
.custom-tree-select {
  /* 调整下拉菜单宽度,使其更适配内容 */
  & .ant-tree-select-dropdown .ant-tree-select-tree {
    width: 220px;
  }
  /* 节点 hover 效果 */
  & .ant-tree-select-tree-node:hover {
    background-color: #e6f7ff !important;
  }
  /* 节点选中效果 */
  & .ant-tree-select-tree-node-selected {
    background-color: #bae7ff !important;
  }
  /* 调整字体大小和行高 */
  & .ant-tree-select-tree-title {
    font-size: 14px;
    line-height: 24px;
  }
  /* 调整缩进,优化层级视觉效果 */
  & .ant-tree-select-tree-indent {
    width: 16px;
  }
}
</style>