official.vue 7.45 KB
<template>
	<view class="page">
		<view class="test">
			<!-- <uni-file-picker 
				v-model="files" 
				fileMediatype="all" 
				@select="select" 
				:limit="5"
				style="border: 1px solid red;margin-bottom: 30px;"
			/> -->
			<!-- <up-load></up-load> -->
			<view class="file_upload" style="width: 90%;height: 60rpx; margin: 0 auto;display: flex;color: white; align-items: center; justify-content: space-around; background-color: gray;border-radius: 20rpx;">
				<view class="file_name">
					{{fileName}}
				</view>
				<view class="" @click="handleUploadClick" style="display: flex;align-items: center;">
					<text>上传文件</text>
					<image src="../../static/image/upload.png" style="width: 20rpx;height: 20rpx;margin-left: 20rpx;" mode=""></image>
				</view>
				
			</view>
			<xe-upload ref="XeUpload" :options="uploadOptions" @callback="handleUploadCallback"></xe-upload>
			<wyh-tree-select :items="items" :activeIds="city_ids5" :selectAll="true" :isSearch="true" />
			<view class="official">
				<view>已选<text class="official-num">{{city_ids5.length}}</text>家企业</view>
				<view class="official-btn" @click="send">确认发送</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '@/utils/request.js'
	import upLoad from '@/components/ncc/ncc-upload/index.vue'
	export default {
		computed: {
			city_name5() {
				return this.getCityNames(this.city_ids5);
			}
		},
		components:{
			upLoad
		},
		data() {
			return {
				items: [],
				city_ids5: [],
				files: [],
				// 上传的文件路径
				fileUrl:'',
				uploadOptions: {
					url: 'http://deyanggaoxin.fengshiyun.com/api/file/Uploader/1', // 不传入上传地址则返回本地链接
					// url: '', // 不传入上传地址则返回本地链接
				},
				// 文件名
				fileName:'文件名',
				// 当前用户ID:
				userId:''
			}
		},
		onShow() {
			this.getUser()
			this.getCompanyList()
		},
		methods: {
			// 获取用户信息
			getUser(){
				if (uni.getStorageSync('user')) {
					let userCode = uni.getStorageSync('user')
					// console.log("用户的code", this.userCode)
					this.userId = userCode.userInfo.userId
					this.userName = userCode.userInfo.userAccount
					this.userIcon = userCode.userInfo.headIcon
					this.organizeName = userCode.userInfo.organizeName
					console.log(userCode)
				} else {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/index'
						})
					})
				}
			},
			 handleUploadClick(){
			            // 使用默认配置则不需要传入第二个参数
			            type: ['image', 'video', 'file'];
			            this.$refs.XeUpload.upload('file', {});
			            // this.$refs.XeUpload.upload('image', {
			            //  count: 6,
			            //  sizeType: ['original', 'compressed'],
			            //  sourceType: ['album'],
			            // });
			        },
			        handleUploadCallback(e) {
			            // e.type: ['choose', 'success', 'warning']
			            // choose 是options没有传入url,返回临时链接时触发
			            // success 是上传成功返回对应的数据时触发
			            // warning 上传或者选择文件失败触发
			            // ......
						console.log(e)
						this.fileUrl = e.data[0].response.data.url
						this.fileName = e.data[0].name
						
			        },
			// 获取机构列表
			getCompanyList(){
				request({
					url:'/api/permission/organize',
					methos:'get',
					data:{
						pageSize:500
					}
				}).then(res=>{
					if(res.code === 200){
						console.log(res)
						let zhuangBei = res.data.list.filter(it=>{
							return it.stage === '装备制造'
						}).map(it=>{
							return {
								...it,
								text:it.fullName,
								id:it.id,
								type:false
							}
						})
						let yiYao = res.data.list.filter(it=>{
							return it.stage === '医药'
						}).map(it=>{
							return {
								...it,
								text:it.fullName,
								id:it.id,
								type:false
							}
						})
						let food = res.data.list.filter(it=>{
							return it.stage === '食品'
						}).map(it=>{
							return {
								...it,
								text:it.fullName,
								id:it.id,
								type:false
							}
						})
						let hangKong = res.data.list.filter(it=>{
							return it.stage === '通用航空'
						}).map(it=>{
							return {
								...it,
								text:it.fullName,
								id:it.id,
								type:false
							}
						})
						let caiLiao = res.data.list.filter(it=>{
							return it.stage === '先进材料'
						}).map(it=>{
							return {
								...it,
								text:it.fullName,
								id:it.id,
								type:false
							}
						})
						let another = res.data.list.filter(it=>{
							return it.stage === '其他' || it.stage === null
						}).map(it=>{
							return {
								...it,
								text:it.fullName,
								id:it.id,
								type:false
							}
						})
						console.log('装备制造',zhuangBei)
						console.log('医药',yiYao)
						console.log('食品',food)
						console.log('通用航空',hangKong)
						console.log('先进材料',caiLiao)
						console.log('其他',another)
						this.items = [
							{
								text:'全部',
								children:res.data.list.map(it=>{
							return {
								...it,
								text:it.fullName,
								id:it.id,
								type:false
							}
						})
							},
							{
								text:'装备制造',
								children:zhuangBei
							},
							{
								text:'医药',
								children:yiYao
							},
							{
								text:'食品',
								children:food
							},
							{
								text:'通用航空',
								children:hangKong
							},
							{
								text:'先进材料',
								children:caiLiao
							},
							{
								text:'其他',
								children:another
							},
						]
					}
				})
			},
			onItem(res) {
				console.log(res);
			},
			// select(e){
			// 	console.log("上传文件",e)
			// 	this.files = e.tempFiles
			// 	// console.log(this.files)
			// },
			// success(e){
			// 	console.log('success',this.files)
				
			// },
			// 发送文件
			send() {
				console.log("111")
				let userInfo = uni.getStorageSync('user')
				console.log(userInfo)
				this.userId = userInfo.userInfo.userId
				console.log(this.userId)
				console.log('文件路径',this.fileUrl)
				if(this.city_ids5.length === 0){
					uni.showToast({
						title:"请选择企业"
					})
					return
				}
				for(let i=0;i<this.city_ids5.length;i++){
					request({
						url:'/api/Extend/basedocumenthandle',
						method:'post',
						data:{
							companyId:this.city_ids5[i],
							creatorUserId:this.userId,
							docmentUrl:this.fileUrl,
							docmentName:this.fileName
						},
						header:{
							"Content-Type": "application/json-patch+json"
						}
					}).then(res=>{
						console.log(res)
						if(res.code === 200){
							uni.showToast({
								icon:"success",
								title:"发送成功"
							})
						}else{
							uni.showToast({
								icon:"error",
								title:"发送失败,请重试"
							})
						}
					})
				}
				console.log(this.city_ids5)
				
			},
			getCityNames(ids) {
				if (!ids) return;
				if (ids.length == 0) {
					return '';
				}
				let city_name = [];
				this.items.map(function(item, index) {
					item.children.map(function(city, ind) {
						ids.map(function(id, i) {
							if (id == city.id) {
								city_name.push(city.text);
							}
						})
					})
				})
				return city_name.join(',');
			}
		},
		created() {

		}
	}
</script>

<style scoped lang="scss">
	@import 'official.scss';
</style>