notice.vue 5.08 KB
<template>
	<view class="page">
		<view class="coupon-tab">
			<view class="tab" :class="{'action':TabShow===0}" @click="onCouponTab(0,'360234116366468357')">
				<text>公示</text>
			</view>
			<view class="tab" :class="{'action':TabShow===1}" @click="onCouponTab(1,'530362479830631685')">
				<text>通知</text>
			</view>
		</view>
		<!-- 搜索 -->
		<view class="search-head">
			<view class="search">
				<image src="../../static/fdj1.png"></image>
				<text></text>
				<input type="text" v-model="keyword" placeholder="搜索关键词" />
			</view>
			<view class="btn" @click="search">
				<text>搜索</text>
			</view>
		</view>
		
		<!-- 文章数据  通知区域Tabshow为0显示-->
		<view v-if="TabShow===0">
			<!-- 党的建设发布 -->
			<view class="postCon" v-show="isAdmin"
				@click="toPostNotice()">
				公式公告发布
			</view>
			<!-- <mescroll-body ref="mescrollRef" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption"
				:top="0"> -->
			<view>
				<view class="article-data">
					<view class="article-list">
						<view class="list" v-for="(item,index) in noticeList" @click="onArticle(item.id)" :key="index">
							<view class="item">
								<view class="title">
									<text class="two-omit">{{item.title}}</text>
								</view>
								<view class="find-collect">
									<view class="find">
										<text>{{item.createTime}}</text>
									</view>
								</view>
							</view>
							<view class="thumb" v-if="item.isImg">
								<image :src="baseUrl + item.imgUrl[0].url"></image>
							</view>
							<view class="thumb" v-else>
								<image src="../../static/img/img3.jpg"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- </mescroll-body> -->
		</view>
		
		<!-- 通知区域Tabshow为1显示 -->
		<view v-if="TabShow===1">
			<!-- 党的建设发布 -->
			<view class="postCon" v-show="isAdmin"
				@click="toPostNotice()">
				公式公告发布
			</view>
			<view>
				<view class="article-data">
					<view class="article-list">
						<view class="list" v-for="(item,index) in noticeList" @click="onArticle(item.id)" :key="index">
							<view class="item">
								<view class="title">
									<text class="two-omit">{{item.title}}</text>
								</view>
								<view class="find-collect">
									<view class="find">
										<text>{{item.createTime}}</text>
									</view>
								</view>
							</view>
							<view class="thumb" v-if="item.isImg">
								<image :src="baseUrl + item.imgUrl[0].url"></image>
							</view>
							<!-- <view class="thumb" v-else>
								<image src="../../static/img/img3.jpg"></image>
							</view> -->
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import utils from '../../service/utils';
	export default {
		data() {
			return {
				TabShow: 0,
				categorrId:'360234116366468357',
				// 公式列表
				publicityList:[],
				// 通知列表
				noticeList:[],
				// 判断你是否有图片
				isImg:false,
				// downOption:{
					
				// }
				keyword:'',
				isAdmin:false,
				baseUrl: "http://deyanggaoxin.fengshiyun.com",
			};
		},
		onLoad() {
			this.getUser()
			this.getNoticeList(this.categorrId)
		},
		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
					// this.isAdmin = userCode.userInfo.isCompany
					console.log(userCode)
					if(userCode.userInfo.userId === 'admin'){
						this.isAdmin = true
					}
				} else {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
				}
			},
			// 获取公式列表
			getNoticeList(id){
				let that = this
				that.API.getNoticeList({
					categoryId:id,
					pageSize:500
				}).then(res=>{
					if(res.code == 200){
						that.noticeList = res.data.list.map(it=>{
							return {
								...it,
								createTime:utils.formatTime(it.createTime),
								isImg: it.imgUrl.length > 0
							}
						})
						// if(that.noticeList.)
					}
					console.log(that.noticeList)
				})
			},
			// 跳转到公式公告发布
			toPostNotice(){
				uni.navigateTo({
					url: '/pages/postNotice/postNotice'
				})
			},
			onCouponTab(type,id) {
				this.TabShow = type;
				this.categorrId = id
				this.getNoticeList(id)
			},
			onArticle(item) {
				uni.navigateTo({
					url: `/pages/newsDetail/newsDetail?data=${JSON.stringify(item)}`
				})
			},
			search(){
				let that = this
				that.API.getNoticeList({
					categoryId:this.categorrId,
					keyword:this.keyword
				}).then(res=>{
					if(res.code == 200){
						that.noticeList = res.data.list.map(it=>{
							return {
								...it,
								createTime:utils.formatTime(it.createTime),
								isImg: it.imgUrl.length > 0
							}
						})
						// if(that.noticeList.)
					}
					console.log(that.noticeList)
				})
			}
		}
	}
</script>

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