Commit c064cea1 authored by 罗林杰's avatar 罗林杰

修改修改保存bug,增加单选填空上传组件

parent d1674991
......@@ -77,6 +77,9 @@ export default {
},
defaultValue: {
default: ''
},
result: {
default: ''
}
},
data() {
......
......@@ -104,7 +104,7 @@ export default {
if (this.defaultValue) {
this.value = this.defaultValue
this.$emit('changeVal', { name: this.prop, val: this.result })
this.$emit('makeRecord', { name: this.prop, record: this.result })
this.$emit('makeRecord', { name: this.prop, record: this.value })
} else {
this.reset()
}
......
......@@ -8,6 +8,7 @@ import checkInput from './checkInput.vue'
import radioInput from './radioInput.vue'
import inputUpload from './inputUpload.vue'
import checkInputUpload from './checkInputUpload.vue'
import radioInputUpload from "./radioInputUpload.vue";
Vue.component('FormRadio', radio)
Vue.component('FormRadioUpload', radioUpload)
Vue.component('FormCheckboxUpload', checkboxUpload)
......@@ -17,3 +18,4 @@ Vue.component('FormInput', input)
Vue.component('FormCheckbox', checkbox)
Vue.component('FormCheckInput', checkInput)
Vue.component('FormRadioCheck', radioInput)
Vue.component('FormRadioInputUpload', radioInputUpload)
......@@ -75,6 +75,9 @@ export default {
},
defaultValue: {
default: ''
},
result: {
default: ''
}
},
data() {
......
......@@ -22,6 +22,9 @@ export default {
},
defaultValue: {
default: ''
},
result: {
default: ''
}
},
......
<template>
<div class="checkbox-input-box">
<div>
<div v-for="(i, k) in items.options" class="checkbox-item" :key="k">
<el-radio
:disabled="status"
v-model="selectedOption"
:label="k"
@change="handleRadioChange(k)"
>{{' '}}
</el-radio>
<el-input
v-bind="items"
placeholder="请输入"
:disabled="selectedOption !== k"
style="width: 10rem;margin-left: -30px;margin-right: 10px"
v-model="model.list[k].value"
@input="input"
>
</el-input>
<div style="width: 20rem; display: inline-block; vertical-align: middle">
{{ i.object }}
</div>
</div>
</div>
<el-upload
class="upload-demo"
ref="fileUpload"
:action="uploadImgUrl"
:on-preview="handlePreview"
v-model="model.file"
:on-remove="handleRemove"
accept=".pdf ,.doc ,.docx ,.xls, .xlsx"
:before-remove="beforeRemove"
:show-file-list="false"
:limit="1"
:on-success="handleSuccess"
:on-exceed="handleExceed"
:headers="headers"
>
<el-button size="small" :disabled="status" type="primary"
>上传文件</el-button
>
<div slot="tip" class="el-upload__tip">
<div v-if="model.path">
<el-link :href="model.path">{{ model.name }}</el-link>
</div>
</div>
</el-upload>
</div>
</template>
<script>
export default {
props: {
items: {
type: Object,
default: () => ({})
},
prop: {
type: String,
default: ''
},
merge: {
type: Boolean,
default: false
},
status: {
type: Boolean,
default: false
},
defaultValue: {
default: ''
},
result: {
default: ''
}
},
data() {
return {
model: {
value: '',
list: [],
file: '',
path: '',
name: ''
},
selectedOption: null, // 记录当前选中的索引
headers: {
Authorization: 'Bearer ' + this.$store.getters.token
},
uploadImgUrl: process.env.VUE_APP_BASE_API + '/common/uploadMinio'
};
},
created() {
this.reset();
},
watch: {
defaultValue(newVal) {
this.model = newVal; // 直接赋值,保留原有数据结构
this.selectedOption = this.model.list.findIndex(item => item.check);
},
status(newVal) {
this.reset();
this.$emit('changeVal', { name: this.prop, val: [] });
this.$emit('makeRecord', { name: this.prop, record: {} });
}
},
mounted() {
if (this.defaultValue) {
this.model = this.defaultValue;
this.selectedOption = this.model.list.findIndex(item => item.check);
this.$emit('changeVal', { name: this.prop, val: this.result })
this.$emit('makeRecord', { name: this.prop, record: this.model })
} else {
this.reset();
}
},
methods: {
reset() {
this.model.list = [];
this.selectedOption = null;
this.items.options.forEach((item, index) => {
this.model.list.push({
value: '',
check: false,
useCaseNo: item.useCaseNo,
key: item.value,
id: item.id,
flag: item.flag
});
});
},
handleRadioChange(newKey) {
this.model.list.forEach((option, index) => {
option.check = index === newKey;
});
this.selectedOption = newKey;
if (this.merge) {
const selectedItem = this.items.options[newKey];
this.$emit('mergeVal', {
name: newKey,
flag: selectedItem.flag ? selectedItem.flag.split(',') : []
});
}
this.input();
},
input() {
const selected = this.model.list[this.selectedOption];
const arr = selected ? [selected.useCaseNo] : [];
this.$emit('changeVal', { name: this.prop, val: arr.join(',') });
this.$emit('makeRecord', { name: this.prop, record: this.model });
},
handleRemove(file, fileList) {
console.log(file, fileList)
},
handlePreview(file) {
console.log(file)
},
handleSuccess(res, file) {
if (res.code === 200) {
this.model.path = process.env.VUE_APP_IMAGE_API + res.url
this.model.name = res.originalFilename
this.$refs.fileUpload.clearFiles()
this.$message.success('上传成功')
} else {
this.$message.error('error')
}
},
handleExceed(files, fileList) {
this.$message.warning(
`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
files.length + fileList.length
} 个文件`
)
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`)
}
}
};
</script>
<style lang="scss" scoped>
.checkbox-item {
margin-bottom: 10px;
}
.checkbox-input-box {
display: flex;
align-items: center;
justify-content: space-between;
}
</style>
......@@ -84,7 +84,7 @@
</template>
<div class="page-footer">
<el-button type="primary" @click="handleConfirm"> 确定 </el-button>
<el-button type="primary" @click="handleConfirm"> 取消 </el-button>
<el-button type="primary" @click="cancel"> 取消 </el-button>
</div>
</page-standard>
</template>
......@@ -207,6 +207,11 @@ export default {
}
})
},
cancel() {
this.$router.push({
path: '/plan/list'
})
},
handleInspectionItem(item) {
// 查看item.value在this.checkTestScenarioList里面存不存在
// 存在则删除
......
......@@ -154,7 +154,6 @@
></page-button>
</el-upload>
</div>
</div>
</template>
</el-table-column>
</el-table>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment