@@ -62,8 +62,8 @@
:custom-request="onFileUpload"
:file-list="form.patrolInfo.otherInfoFiles"
:preview-file="onPreviewFile"
- @change="onFileChange"
- @preview="onFilePreview"
+ @change="(data) => onFileChange(data, 'otherInfoFiles')"
+ @preview="(data) => onFilePreview(data, 'otherInfoFiles')"
list-type="picture-card"
>
@@ -74,11 +74,11 @@
-
+
@@ -98,7 +98,7 @@ const defaultForm = {
settlementTiltFiles: [],
otherInfo: null,
otherInfoFiles: [],
- MainSafety: null,
+ mainSafety: null,
},
};
export default {
@@ -119,9 +119,14 @@ export default {
/** 其他成员属性 */
codes: {},
+ fileFieldArr: ['settlementTiltFiles', 'otherInfoFiles'],
};
},
methods: {
+ /**
+ * 必要的方法
+ * 在打开编辑页时允许填充数据
+ */
async onFillData() {
this.loading = true;
{
@@ -129,11 +134,45 @@ export default {
/** 将默认数据覆盖到form */
const record = this.param && this.param.record;
- const form = this.$_.cloneDeep(defaultForm);
if (record) {
- this.$_.giveDeep(form, record);
+ // this.$_.giveDeep(form, record);
+ // this.fileFieldArr.forEach((key) => {
+ // const fileValue = [];
+ // const fileList = !!record.patrolInfo[key] ? record.patrolInfo[key].split(',') : [];
+ // for (let i = 0; i < fileList.length; i++) {
+ // const file = await PreviewFile(fileList[i]);
+ // const base64 = await BlobToBase64(file);
+ // fileValue.push({
+ // uid: fileList[i],
+ // response: fileList[i], // 用于和新上传的文件一同回传
+ // name: file.name,
+ // url: base64,
+ // status: 'done',
+ // });
+ // }
+ // defaultForm.patrolInfo[key] = fileValue;
+ // });
+ for (var key in defaultForm.patrolInfo) {
+ if (key.indexOf('Files') > -1) {
+ const fileValue = [];
+ const fileList = !!record.patrolInfo[key] ? record.patrolInfo[key].split(',') : [];
+ for (let i = 0; i < fileList.length; i++) {
+ const file = await PreviewFile(fileList[i]);
+ const base64 = await BlobToBase64(file);
+ fileValue.push({
+ uid: fileList[i],
+ response: fileList[i], // 用于和新上传的文件一同回传
+ name: file.name,
+ url: base64,
+ status: 'done',
+ });
+ }
+ defaultForm.patrolInfo[key] = fileValue;
+ }
+ }
}
+ const form = this.$_.cloneDeep(defaultForm);
this.form = form;
}
this.loading = false;
@@ -150,8 +189,10 @@ export default {
const record = this.$_.cloneDeep(this.form);
/** 验证通过后可以对数据进行转换得到想要提交的格式 */
+ this.fileFieldArr.forEach((key) => {
+ record.patrolInfo[key] = record.patrolInfo[key].map((p) => p.response).join(',');
+ });
/* ... */
- //record.facadePhoto = record.facadePhoto.map((p) => p.response).join(',');
reslove(record);
} else {
@@ -178,8 +219,8 @@ export default {
/* ... */
/* 上传图片相关 Begin */
- onFileChange({ fileList }) {
- this.form.patrolInfo.settlementTiltFiles = fileList;
+ onFileChange({ fileList }, key) {
+ this.form.patrolInfo[key] = fileList;
},
onPreviewFile(file) {
return new Promise((resolve) => {
@@ -198,10 +239,10 @@ export default {
onError();
}
},
- onFilePreview(file) {
+ onFilePreview({ file }, key) {
const items = [];
- for (let i = 0; i < this.form.patrolInfo.settlementTiltFiles.length; i++) {
- const _file = this.form.patrolInfo.settlementTiltFiles[i];
+ for (let i = 0; i < this.form.patrolInfo[key].length; i++) {
+ const _file = this.form.patrolInfo[key][i];
const img = new Image();
const src = _file.url || _file.thumbUrl;
img.src = src;
@@ -212,7 +253,7 @@ export default {
});
}
this.$refs['photo-swipe'].initPhotoSwipe(items, {
- index: this.form.patrolInfo.settlementTiltFiles.indexOf(file),
+ index: this.form.patrolInfo[key].indexOf(file),
});
},
/* 上传图片相关 End */