1
lzhe
2024-06-03 a786409d7f6769f43c107159dd84faf4a2927a9a
src/views/configuration/custom/addField.vue
@@ -15,7 +15,7 @@
            <el-col :span="24">
               <el-form-item label="字段类型">
                  <el-select v-model="addFieldForm.fieldType" style="width: 100%" placeholder="选择符合业务的字段类型">
                     <el-option v-for="item in fieldTypeList" :key="item.id" :label="item.title" :value="item.id"/>
                     <el-option v-for="item in fieldTypeList" :disabled="item.disabled" :key="item.id" :label="item.title" :value="item.id"/>
                  </el-select>
               </el-form-item>
            </el-col>
@@ -93,42 +93,49 @@
            <!-- 变量5 单选按钮-->
            <el-col :span="24" v-if="addFieldForm.fieldType == '5'">
               <el-form-item label="选项" class="specialItem">
                  <div v-for="(item,index) in addFieldForm.radioList" class="fieldContent">
                     <el-radio v-model="item.radio" :label="1" style="margin-right: 0px;"> </el-radio>
                     <el-input v-model="item.input" clearable></el-input>
                     <span class="remove-btn" @click="removeRadio(index)">删除</span>
                  </div>
                  <el-radio-group v-model="addFieldForm.selectOption" class="specialRadio">
                     <el-radio :label="item.value" style="margin-right: 0px;" v-for="(item,index) in addFieldForm.radioList">
                        <el-input v-model="item.label" clearable></el-input>
                        <span class="remove-btn" @click="removeRadio(index)">删除</span>
                     </el-radio>
                  </el-radio-group>
                  <div class="add-btn" @click="addRadio">添加选项</div>
               </el-form-item>
            </el-col>
            <el-col :span="24" v-if="addFieldForm.fieldType == '5'">
               <el-form-item label="排序方式">
                  <el-radio v-model="addFieldForm.radio" label="1">横向排列</el-radio>
                  <el-radio v-model="addFieldForm.radio" label="2">纵向排列</el-radio>
                  <el-radio v-model="addFieldForm.direction" label="0">横向排列</el-radio>
                  <el-radio v-model="addFieldForm.direction" label="1">纵向排列</el-radio>
               </el-form-item>
            </el-col>
            <!-- 变量6 多选按钮-->
            <el-col :span="24" v-if="addFieldForm.fieldType == '6'">
               <el-form-item label="选项" class="specialItem">
                  <div v-for="(item,index) in addFieldForm.checkboxList" class="fieldContent">
                  <el-checkbox-group v-model="addFieldForm.selectBoxOption" class="specialCheck">
                     <el-checkbox :label="item.value" :value="item.value" v-for="(item,index) in addFieldForm.checkboxList">
                        <el-input v-model="item.label" clearable></el-input>
                        <span class="remove-btn" @click="removeCheckbox(index)">删除</span>
                     </el-checkbox>
                  </el-checkbox-group>
                  <!-- <div v-for="(item,index) in addFieldForm.checkboxList" class="fieldContent">
                     <el-checkbox v-model="item.check" style="margin-right: 15px;"></el-checkbox>
                     <el-input v-model="item.input" clearable></el-input>
                     <span class="remove-btn" @click="removeCheckbox(index)">删除</span>
                  </div>
                  </div> -->
                  <div class="add-btn" @click="addCheckbox">添加选项</div>
               </el-form-item>
            </el-col> 
            <el-col :span="24" v-if="addFieldForm.fieldType == '6'">
               <el-form-item label="排序方式">
                  <el-radio v-model="addFieldForm.radio" label="1">横向排列</el-radio>
                  <el-radio v-model="addFieldForm.radio" label="2">纵向排列</el-radio>
                  <el-radio v-model="addFieldForm.direction" label="0">横向排列</el-radio>
                  <el-radio v-model="addFieldForm.direction" label="1">纵向排列</el-radio>
               </el-form-item>
            </el-col>
            <!-- 变量7 下拉选择器-->
            <el-col :span="24" v-if="addFieldForm.fieldType == '7'">
               <el-form-item label="选项" class="specialItem">
                  <div v-for="(item,index) in addFieldForm.selectList" class="fieldContent">
                     <el-input v-model="item.input" clearable></el-input>
                     <el-input v-model="item.label" clearable></el-input>
                     <span class="remove-btn" @click="removeSelect(index)">删除</span>
                  </div>
                  <div class="add-btn" @click="addSelect">添加选项</div>
@@ -167,6 +174,7 @@
      emits: ['success', 'closed'],
      data() {
         return {
            dialogData: {},
            inputTypeList: [  //输入格式
               {title: "无",id: "1"},
               {title: "手机号码",id: "mobile"},
@@ -181,8 +189,8 @@
               {title: "单选按钮",id: "5"},
               {title: "多选按钮",id: "6"},
               {title: "下拉选择器",id: "7"},
               {title: "业务字段-人员",id: "8"},
               {title: "默认",id: "9"}
               {title: "业务字段-人员",id: "9"},
               {title: "默认",id: "10",disabled: true}
            ],
            dateFormatList: [  //日期格式
               {title: "年-月",id: "yyyy-MM"},
@@ -205,6 +213,7 @@
               defaultValue: "",
               maxlength: 20,
               updateShow: false,
               viewShow: true,
               fieldType: "1",  //字段类型,默认输入框
               formatName: "",
               supportUpdate: "1",
@@ -221,22 +230,10 @@
                  value: "month",
                  format: "yyyy-MM"
               },
               radio: '1',
               num: 0,
               numLast: 9999,
               test: "",
               check: false,
               code: "",
               dictValue: "",
               sort: "",
               isSealed: false,
               remark: "",
               dictKey: "-1",
               test: "",
               viewShow: true,
               numArea: 200,
               dateType: "1",
               direction: "0",
               radioList: [],
               selectOption: "",
               selectBoxOption: [],
               checkboxList: [],
               selectList: []
            },
@@ -290,7 +287,10 @@
               };
            }
         },
         saveSubmit() {
         fieldSubmit() {  //保存
            this.saveSubmit('closeDialog');
         },
         saveSubmit(isClose) {  //保存并继续
            var obj = {
               businessType: 1,
               fieldDescription: this.addFieldForm.fieldDescription,
@@ -335,16 +335,49 @@
               }
               obj.propertyJson = JSON.stringify(propertyJson);
            }
            console.log(obj);
            return;
            this.$HTTP.post(`/api/blade-system/custom-template-field/insert`,obj).then(res=> {
            if(this.addFieldForm.fieldType == "5") {  //单选按钮
               var propertyJson = {
                  selectOption: this.addFieldForm.selectOption,
                  options: this.addFieldForm.radioList,
                  direction: this.addFieldForm.direction
               }
               obj.propertyJson = JSON.stringify(propertyJson);
            }
            if(this.addFieldForm.fieldType == "6") {  //多选按钮
               var propertyJson = {
                  selectOption: this.addFieldForm.selectBoxOption,
                  options: this.addFieldForm.checkboxList,
                  direction: this.addFieldForm.direction
               }
               obj.propertyJson = JSON.stringify(propertyJson);
            }
            if(this.addFieldForm.fieldType == "7") {  //下拉选择器
               var propertyJson = {
                  options: this.addFieldForm.selectList
               }
               obj.propertyJson = JSON.stringify(propertyJson);
            }
            obj.businessType = this.$route.query.type;
            var that = this;
            if(this.mode == "edit") {
               var url = "/api/blade-system/custom-template-field/update";
               var method = "put";
               obj.id  = this.dialogData.id;
            }else {
               var url = "/api/blade-system/custom-template-field/insert";
               var method = "post";
            }
            this.$HTTP[method](url,obj).then(res=> {
               if(res.code == 200) {
                  this.$message.success("提交成功");
                  that.$message.success("提交成功");
                  that.$emit("success",obj);
                  if(isClose == "closeDialog") {
                     that.visible = false;
                  }
               }else {
                  this.$message.error(res.msg);
                  that.$message.error(res.msg);
               }
            })
            console.log(obj)
         },
         removeRadio(index) {
            this.addFieldForm.radioList.splice(index,1);
@@ -353,7 +386,7 @@
            var flag = false;
            if(this.addFieldForm.radioList.length > 0) {
               this.addFieldForm.radioList.forEach(item=> {
                  if(item.input == "") {
                  if(item.label == "") {
                     flag = true;
                  }
               })
@@ -362,7 +395,7 @@
               this.$message.error("请输入上一个自定义选项的内容");
               return;
            }
            this.addFieldForm.radioList.push({radio: "",input: ""});
            this.addFieldForm.radioList.push({label: "",value: "radiosSelect" + (this.addFieldForm.radioList.length + 1),parentId: 0});
         },
         removeCheckbox(index) {
            this.addFieldForm.checkboxList.splice(index,1);
@@ -371,7 +404,7 @@
            var flag = false;
            if(this.addFieldForm.checkboxList.length > 0) {
               this.addFieldForm.checkboxList.forEach(item=> {
                  if(item.input == "") {
                  if(item.label == "") {
                     flag = true;
                  }
               })
@@ -380,7 +413,7 @@
               this.$message.error("请输入上一个自定义选项的内容");
               return;
            }
            this.addFieldForm.checkboxList.push({check: "",input: ""});
            this.addFieldForm.checkboxList.push({label: "",value: "checkboxSelect" + (this.addFieldForm.checkboxList.length + 1),parentId: 0});
         },
         removeSelect(index) {
            this.addFieldForm.selectList.splice(index,1);
@@ -389,7 +422,7 @@
            var flag = false;
            if(this.addFieldForm.selectList.length > 0) {
               this.addFieldForm.selectList.forEach(item=> {
                  if(item.input == "") {
                  if(item.label == "") {
                     flag = true;
                  }
               })
@@ -398,7 +431,7 @@
               this.$message.error("请输入上一个自定义选项的内容");
               return;
            }
            this.addFieldForm.selectList.push({input: ""});
            this.addFieldForm.selectList.push({label: "",value: "select" + (this.addFieldForm.selectList.length + 1),parentId: 0});
         },
         //显示
         open(mode='add'){
@@ -406,32 +439,35 @@
            this.visible = true;
            return this
         },
         //表单提交方法
         fieldSubmit(){
            var obj = Object.assign({},this.addFieldForm);
            this.$refs.dialogForm.validate(async (valid) => {
               if (valid) {
                  this.isSaveing = true;
                  this.$HTTP.post("/api/blade-system/dict/submit",obj).then(res=> {
                     this.isSaveing = false;
                     if(res.code == 200) {
                        this.$emit('success', this.addFieldForm, this.mode);
                        this.visible = false;
                        this.$message.success("操作成功");
                     }else {
                        this.$alert(res.message, "提示", {type: 'error'});
                     }
                  })
               }else{
                  return false;
               }
            })
         },
         //表单注入数据
         setData(data){
            console.log(data)
            //可以和上面一样单个注入,也可以像下面一样直接合并进去
            //Object.assign(this.addFieldForm, data);
            this.dialogData = data;
            this.$HTTP.get(`/api/blade-system/custom-template-field/get/${data.id}`).then(res=> {
               if(res.code == 200) {
                  res.data.fieldType = String(res.data.fieldType);
                  res.data.format = res.data.format == "0"?"0":"1";
                  res.data.direction = String(res.data.direction);
                  res.data.updateShow = res.data.updateShow == "1"?true:false;
                  res.data.viewShow = res.data.viewShow == "1"?true:false;
                  res.data.supportUpdate = String(res.data.supportUpdate);
                  if(res.data.fieldType != "10") {
                     this.addFieldForm = Object.assign(res.data,JSON.parse(res.data.propertyJson));
                  }else {
                     this.addFieldForm = res.data;
                  }
                  this.addFieldForm.format = String(this.addFieldForm.format);
                  if(res.data.fieldType == "5") {
                     this.addFieldForm.radioList = this.addFieldForm.options;
                  }
                  if(res.data.fieldType == "6") {
                     this.addFieldForm.checkboxList = this.addFieldForm.options;
                     this.addFieldForm.selectBoxOption = this.addFieldForm.selectOption;
                  }
                  if(res.data.fieldType == "7") {
                     this.addFieldForm.selectList = this.addFieldForm.options;
                  }
               }
            })
         }
      }
   }
@@ -443,9 +479,18 @@
   cursor: pointer;
}
.specialItem /deep/ .el-form-item__content{
   display: flex;
   flex-direction: column;
    align-items: flex-start;
}
.specialRadio,.specialCheck {
   display: flex;
   flex-direction: column;
    align-items: flex-start;
}
.specialRadio label,.specialCheck label{
   margin-bottom: 8px;
}
.fieldContent {
   display: flex;
    align-items: flex-start;