Commit 86f2d00e by 张权

合并

1 parent 9854a015
<template>
<div class="report-components">
<div class="title">上传资料</div>
<el-upload action="https://jsonplaceholder.typicode.com/posts/" list-type="picture-card" :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="" />
</el-dialog>
<div v-for="item in materialData" :key="item.name">
<div>{{ item.label }}</div>
<el-upload :class="[(item.imgList ? item.limit != item.imgList.length : true) ? '' : 'hidePlusBtn']" :limit="item.limit" action="#" :before-upload="beforeAvatarUpload" list-type="picture-card" :ref="item.name + 'Ref'" :on-preview="handlePictureCardPreview" :on-remove="e => handleRemove(e, item.name)" :http-request="e => httpRequest(e, item.name)">
<i slot="default" class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="" />
</el-dialog>
</div>
</div>
</template>
......@@ -22,34 +25,98 @@ export default {
// },
data() {
return {
dialogVisible: false,
materialForm: {
cardInfo: '',
billInfo: '',
otherInfo: ''
},
fieldInfo: {
cardInfo: [],
billInfo: [],
otherInfo: []
},
materialData: [
{
label: '身份证',
name: 'cardInfo',
type: 'upload'
limit: 2,
imgList: []
},
{
label: '发票',
name: 'billInfo',
type: 'upload'
limit: 10,
imgList: []
},
{
label: '其他',
name: 'otherInfo',
type: 'upload'
limit: 1,
imgList: []
}
]
}
},
methods: {}
methods: {
beforeAvatarUpload(e) {
let AllImgExt = '.zip|.rar|.png|.jpg'
let extName = e.name.substring(e.name.lastIndexOf('.')).toLowerCase()
if (AllImgExt.indexOf(extName) === -1) {
this.$message.error('上传格式不正确')
return false
}
const size = e.size / 1024 / 1024
if (size > 9) {
this.$message.error('上传文件不可超过9M')
return false
}
},
httpRequest({ file: e }, fieldName) {
console.log(e, 456)
// // 转码base64
const reader = new FileReader()
reader.readAsDataURL(e)
reader.onload = event => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(',')
const targetNameList = e.name.split('.')
const fileInfo = targetNameList[targetNameList.length - 1] + '@' + arrBase64[1]
this.$apis.ghBeforeSale.uploadImgApi({ file: fileInfo }).then(res => {
console.log(res)
if (res) {
let targetItem = this.materialData.find(item => item.name === fieldName)
targetItem.imgList.push(res)
this.fieldInfo[fieldName].push(e.uid)
} else {
this.handleRemove(e, fieldName, 1)
}
})
}
},
handleRemove(e, fieldName, isDel) {
if (isDel) {
let id = this.$refs[fieldName + 'Ref'][0].uploadFiles.findIndex(item => item.uid === e.uid)
this.$refs[fieldName + 'Ref'][0].uploadFiles.splice(id, 1)
} else {
console.log(this.fieldInfo[fieldName], e.uid)
let targetId = this.fieldInfo[fieldName].findIndex(item => item === e.uid)
console.log(targetId)
}
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url
this.dialogVisible = true
}
}
}
</script>
<style lang="scss" scoped>
/deep/ .hidePlusBtn {
.el-upload--picture-card {
display: none;
}
}
.report-components {
background: white;
.title {
......
......@@ -30,9 +30,9 @@
</div>
<div class="account-info">
<glsx-combi-form ref="accountRef" :formRules="accountRule" labelWidth="144px" defaultWidth="320px" :formObj="accountForm" :formData="accountData">
<template slot="collectCity">
<!-- <template slot="collectCity">
<city-select @onChange="selectAddress"></city-select>
</template>
</template> -->
</glsx-combi-form>
</div>
</div>
......@@ -41,7 +41,6 @@
</template>
<script type="text/ecmascript-6">
import citySelect from './citySelect.vue'
import glsxCombiForm from '@/components/glsx-combi-form'
const phoneReg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/
export default {
......@@ -51,7 +50,6 @@ export default {
},
components: {
glsxCombiForm,
citySelect,
},
data() {
return {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!