<el-dialog title="上传机构图片印章" :visible.sync="updateImageSealVisible" center class="templateDialog" width="800px">
<el-form :model="imgData" label-width="210px" ref="imgData" :rules="addTemplateRules" class="template" >
<el-form-item label="上传图片" prop="img">
<label slot="label">图片印章</label>
<el-upload v-model="imgData.img" ref='upload'
class="avatar-uploader" list-type="picture-card" action=""
accept="image/png"
:http-request="httpRequest"
:before-upload="beforeAvatarUpload" >
<i class="el-icon-plus"></i>
</el-upload>
</el-form-item>
<el-form-item label="印章高度:" prop="height">
<el-input v-model="imgData.height" style="width: 300px"></el-input>
</el-form-item>
<el-form-item label="印章宽度:" prop="width">
<el-input v-model="imgData.width" style="width: 300px"></el-input>
</el-form-item>
<el-form-item label="印章别名:" prop="alias">
<el-input v-model="imgData.alias" style="width: 300px"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="updateImageSealVisible = false">取 消</el-button>
<el-button type="primary" @click="imgTemplateui">新增</el-button>
</div>
</el-dialog>
beforeAvatarUpload(file) {
console.log("进入");
const isJPG = file.type === 'image/png';
if (!isJPG) {
this.$message.error('上传头像图片只能是 PNG 格式!');
}
this.fileImg = file;
let _this = this;
let imgWidth = "";
let imgHeight = "";
let width;
let height;
const isSize = new Promise(function (resolve, reject) {
console.log(width, height);
let _URL = window.URL || window.webkitURL;
let img = new Image();
img.onload = function () {
imgWidth = img.width;
imgHeight = img.height;
console.log(imgWidth);
console.log(imgHeight);
console.log(imgWidth, imgHeight);
_this.imgData.width = imgWidth;
_this.imgData.height = imgHeight;
};
img.src = _URL.createObjectURL(file);
}).then(
() => {
return file;
},
);
return isJPG && isLt1M && isSize;
},
imgTemplateui(file){
if(this.fileImg == null){
return this.$message.error( '请上传图片')
}
this.imgData.accountId = this.orgId;
this.imgforData = new FormData();
this.imgforData.append("map",JSON.stringify(this.imgData))
this.imgforData.append("file",this.fileImg)
imgAddOrganization(this.imgforData).then((res) =>{
if (res.code != 0) {
return this.$message.error(res.message || '未知错误,请联系开发人员')
}
this.$message.success(res.message)
this.updateImageSealVisible = false;
this.$refs['imgData'].resetFields();
this.$refs.upload.clearFiles();
this.fileImg = null;
})
},