修改了企业的导出和导入的功能

This commit is contained in:
chendaze 2024-04-02 13:43:54 +08:00
parent 6652ebce7a
commit 6b2e85cbe9
2 changed files with 77 additions and 37 deletions

View File

@ -104,8 +104,15 @@ export function importData (data) {
return axios({
url: api.icsCustomerStaff + '/importData',
method: 'post',
headers: { 'Content-Type': 'multipart/form-data' },
params: data
data: data
})
}
export function exportTemplate () {
return axios({
url: api.icsCustomerStaff + '/exportTemplate',
method: 'post',
data: { }
})
}

View File

@ -316,42 +316,25 @@
</a-form>
<customer-contacts-modal ref='contactModal' @ok='handleContactSaved' />
<a-modal v-model="visible" title="导入用户" @ok="handleFileOk" >
<!-- <a-upload-dragger-->
<!-- name="file"-->
<!-- :multiple="true"-->
<!-- :file-list="fileList"-->
<!-- :action="uploadUrl"-->
<!-- :headers="headers"-->
<!-- @change="handleFileChange"-->
<!-- >-->
<!-- <p class="ant-upload-drag-icon">-->
<!-- <a-icon type="inbox" />-->
<!-- </p>-->
<!-- <p class="ant-upload-text">-->
<!-- 单击或拖动文件到此区域进行上传-->
<!-- </p>-->
<!-- </a-upload-dragger>-->
<div style='display: flex'>
<a-upload
:fileList="fileList"
:headers="headers"
accept=".xlsx,.xls"
@change="customChange"
:customRequest="customRequest">
<a-button type="primary" >导入</a-button>
<a-button type="primary" >导入用户数据</a-button>
</a-upload>
<!-- <a-upload-->
<!-- accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"-->
<!-- :customRequest="customRequest"-->
<!-- @change="customChange"-->
<!-- :disabled="uploadDisabled">-->
<!-- <a-button type="primary" :icon="uploadIcon" :disabled="uploadDisabled">导入</a-button>-->
<!-- </a-upload>-->
<a-button style='margin-left: 40px' type="primary" @click='exportTemplate'>导出用户模板</a-button>
</div>
</a-modal>
</a-card>
</template>
<script>
let downloadLoadingInstance;
import moment from 'moment'
import storage from 'store'
import { ACCESS_TOKEN } from '@/store/mutation-types'
@ -362,7 +345,8 @@ import {
getStaffList,
selectCustomerStaffList,
updateStaffByCustomer,
importData
importData,
exportTemplate
} from '@/api/admin/customer'
import {
getFloorList,
@ -372,7 +356,8 @@ import { getCustomerContractList } from '@/api/admin/customerContract'
import CustomerContactsModal from './modules/CustomerContactsModal.vue'
import CustomerAttachmentList from './modules/CustomerAttachmentList.vue'
import pick from 'lodash.pick'
import { message } from 'ant-design-vue'
import { download } from '@/utils/request'
export default {
name: 'BaseForm',
components: {
@ -430,6 +415,10 @@ export default {
title: '手机号',
dataIndex: 'mobile'
},
{
title: '性别',
dataIndex: 'gender'
},
{
title: '操作',
key: 'operation',
@ -511,17 +500,58 @@ export default {
this.floorList = res.data
})
},
exportTemplate(){
exportTemplate().then(res =>{
console.log(res)
this.downloadFile(res)
})
},
downloadFile (data) {
let fileName = '客户导入模板'
let link = document.createElement('a')
let blob = new Blob([data], {type: 'application/vnd.ms-excel;charset=utf-8'});
console.log(blob)
link.style.display = 'none';
link.download = fileName+'.xlsx';
link.href = URL.createObjectURL(blob);
// link.setAttribute('download', fileName+'.xlsx');
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href); // URL
document.body.removeChild(link);
// console.log(data)
// var link = document.createElement('a')
// //
// if (!data) {
// return
// }
// link.style.display = 'none'
// link.href = window.URL.createObjectURL(new Blob([data]))
// link.setAttribute('download', '.xls')
// document.body.appendChild(link)
// link.click()
},
customRequest(file){
// file
// formData
// uploadFile
const formData = new FormData()
formData.append('file', file.file)
console.log(file)
importData({ filePath:file.file.name }).then(res => {
if (res.success) {
importData(formData).then(res => {
if (res.code == 0) {
// ,
file.onSuccess(res, file.file)
file.status = 'done'
this.visible =false
this.$message.success(res.msg)
} else {
file.onError()
file.status = 'error'
@ -537,6 +567,9 @@ export default {
this.file =info.file.response
this.fileName = result.fileName
}
},
customChange(){
},
//
importUser(){