北尚诉办前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

379 lines
13 KiB

<template>
<el-card shadow="never"
class="aui-card--fill">
<div class="mod-news__news}">
<el-form :inline="true"
:model="dataForm"
@keyup.enter.native="getDataListSearch()">
<el-form-item label="所属机构">
<el-cascader v-model="deptIdList"
:options="options"
:props="{ checkStrictly: true }"
clearable></el-cascader>
</el-form-item>&nbsp;
<el-form-item label="类别" label-width="68px">
<el-select v-model="dataForm.category"
clearable
placeholder="所属类别">
<el-option v-for="item in categorys"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="关键字" label-width="68px" >
<el-form-item>
<el-input v-model="dataForm.keyword" @keyup.native="btKeyUpkeyword"
placeholder="请输入标题"
clearable></el-input>
</el-form-item>
</el-form-item>
<br>
<el-form-item label="提交时间"
prop="startTime">
<el-date-picker v-model="dataForm.startTime"
type="date"
:picker-options="pickerBeginDateBefore"
value-format="yyyy-MM-dd"
format="yyyy-MM-dd"
placeholder="选择日期时间"
style="width:200px;" @change="changeTime">
</el-date-picker>
</el-form-item>
<el-form-item label="至"
label-width="25px"
prop="endTime">
<el-date-picker v-model="dataForm.endTime"
type="date"
:picker-options="pickerBeginDateAfter"
value-format="yyyy-MM-dd"
format="yyyy-MM-dd"
placeholder="选择日期时间"
style="width:200px;" @change="changeTime">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="success" @click="getDataListSearch()">{{ $t('query') }}</el-button>
</el-form-item>
<el-form-item>
<el-button v-if="$hasPermission('news:news:save')"
type="primary"
@click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
</el-form-item>
<el-form-item>
<el-button v-if="$hasPermission('news:news:delete')"
type="danger"
@click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
</el-form-item>
</el-form>
<el-table v-loading="dataListLoading"
:data="dataList"
border
@selection-change="dataListSelectionChangeHandle"
style="width: 100%;">
<el-table-column label="序号"
width="50px"
align="center">
<template slot-scope="scope">
{{scope.$index+1}}
</template>
</el-table-column>
<el-table-column prop="newsTitle"
label="标题名称"
header-align="center"
align="center"
min-width="250"
show-overflow-tooltip></el-table-column>
<el-table-column prop="readingAmount"
label="阅读量"
header-align="center"
width="100"
align="center"></el-table-column>
<el-table-column prop="likeNumber"
label="支持数"
width="100"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="unLikeNumber"
label="不支持数"
width="100"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="createdTime"
label="提交时间"
header-align="center"
width="180"
align="center"></el-table-column>
<el-table-column prop="creatorName"
label="提交人"
header-align="center"
min-width="200"
show-overflow-tooltip
align="center"></el-table-column>
<el-table-column label="有效时间" width="360" header-align="center" align="center">
<template slot-scope="scope">
{{scope.row.newsReleaseStartTime}} 到 {{scope.row.newsReleaseEndTime}}
</template>
</el-table-column>
<el-table-column :label="$t('handle')"
fixed="right"
header-align="center"
align="center"
width="150">
<template slot-scope="scope">
<el-button type="text"
size="small"
@click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
<el-button type="text"
size="small"
@click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
<el-button type="text"
size="small"
@click="publist(scope.row)">发布</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination :current-page="page"
:page-sizes="[10, 20, 50, 100]"
:page-size="limit"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="pageSizeChangeHandle"
@current-change="pageCurrentChangeHandle">
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update v-if="addOrUpdateVisible"
ref="addOrUpdate"
@refreshDataList="getDataList"></add-or-update>
</div>
</el-card>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './news-add-or-update'
export default {
mixins: [mixinViewModule],
data () {
return {
mixinViewModuleOptions: {
getDataListURL: '/news/news/page',
getDataListIsPage: true,
deleteURL: '/news/news',
deleteIsBatch: true
},
dataForm: {
id: '',
streetId: '',
communityId: '',
gridId: '',
startTime: '',
endTime: '',
keyword: '',
category: '',
draft: '1'
},
time: '',
streetList: [],
communityList: [],
gridList: [],
options: [],
deptIdList: [],
categorys: [],
id: '',
pickerBeginDateBefore: {
disabledDate: (time) => {
let beginDateVal = this.dataForm.endTime
if (beginDateVal) {
return time.getTime() > new Date(beginDateVal + ' 00:00:00').getTime()
}
}
},
pickerBeginDateAfter: {
disabledDate: (time) => {
let EndDateVal = this.dataForm.startTime
if (EndDateVal) {
return time.getTime() < new Date(EndDateVal + ' 00:00:00').getTime()
}
}
},
}
},
created () {
this.$http
.get(`/sys/user/deptOptions/getByLoginUser`)
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.options = res.data.options
})
.catch(() => { })
this.getDeptInfoList('street', localStorage.getItem('street') === null ? '1169154711480528897' : localStorage.getItem('street'))
this.getListCategory()
},
methods: {
newsUpDownState: function (row) {
return row.newsUpDownState === 0 ? '下线' : '上线'
},
publishState: function (row) {
var stdt = new Date(row.newsReleaseStartTime.replace('-', '/'))
var eddt = new Date(row.newsReleaseEndTime.replace('-', '/'))
var nowdt = new Date()
if (nowdt < stdt) {
return '未发布'
} else if (nowdt > eddt) {
return '已过期'
}
return '发布中'
},
// 获取部门列表
getDeptInfoList (dataReceiver, faDeptId) {
this.$http.get(`/sys/dept/sublist/` + faDeptId).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
if (dataReceiver === 'street') {
this.streetList = res.data
} else if (dataReceiver === 'community') {
this.communityList = res.data
} else if (dataReceiver === 'grid') {
this.gridList = res.data
}
}).catch(() => { })
},
changeStreet (event) {
if (this.dataForm.streetId === '') {
this.communityList = []
this.gridList = []
this.dataForm.communityId = ''
this.dataForm.gridId = ''
return
}
this.dataForm.streetId = event
let choosenItem = this.streetList.filter(item => item.id === this.dataForm.streetId)[0]
this.initDeptIdAndName(choosenItem)
this.dataForm.communityId = this.dataForm.gridId = null
this.communityList = this.gridList = []
this.getDeptInfoList('community', event)
},
changeCommunity (event) {
if (this.dataForm.communityId === '') {
this.gridList = []
this.dataForm.gridId = ''
return
}
this.communityId = event
let choosenItem = this.communityList.filter(item => item.id === this.dataForm.communityId)[0]
this.initDeptIdAndName(choosenItem)
this.dataForm.gridId = null
this.gridList = []
this.getDeptInfoList('grid', event)
},
changeGrid (event) {
this.dataForm.gridId = event
let choosenItem = this.gridList.filter(item => item.id === this.gridId)[0]
this.initDeptIdAndName(choosenItem)
},
initDeptIdAndName (choosenItem) {
this.dataForm.dept = choosenItem.name
this.dataForm.deptId = choosenItem.id
},
setRegistTime () {
console.log(this.time[0])
this.dataForm.startTime = this.time[0]
this.dataForm.endTime = this.time[1]
},
getListCategory () {
this.$http.get(`/news/newscategory/category/`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.categorys = res.data
}).catch(() => { })
},
// 发布
publist (row) {
this.$confirm(this.$t('prompt.info', { 'handle': '发布' }), this.$t('发布'), {
confirmButtonText: this.$t('confirm'),
cancelButtonText: this.$t('cancel'),
type: 'warning'
}).then(() => {
let id = row.id
this.$http.post(`/news/news/draftsPublishNews/${id}`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
}
})
this.getDataList()
}).catch(() => { })
}).catch(() => { })
},
// 获取数据列表
getDataList () {
if (this.time === null) {
this.dataForm.startTime = ''
this.dataForm.endTime = ''
}
this.dataListLoading = true
this.$http.get(
this.mixinViewModuleOptions.getDataListURL,
{
params: {
order: this.order,
orderField: this.orderField,
page: this.mixinViewModuleOptions.getDataListIsPage ? this.page : null,
limit: this.mixinViewModuleOptions.getDataListIsPage ? this.limit : null,
...this.dataForm
}
}
).then(({ data: res }) => {
this.dataListLoading = false
if (res.code !== 0) {
this.dataList = []
this.total = 0
return this.$message.error(res.msg)
}
this.dataList = this.mixinViewModuleOptions.getDataListIsPage ? res.data.list : res.data
if (this.dataList.length>0){
this.dataList.forEach(item=>{
let a = item.newsReleaseStartTime.substring(0,item.newsReleaseStartTime.indexOf(" "));
let b = item.newsReleaseEndTime.substring(0,item.newsReleaseEndTime.indexOf(" "));
item.newsReleaseStartTime = a
item.newsReleaseEndTime = b
})
}
this.total = this.mixinViewModuleOptions.getDataListIsPage ? res.data.total : 0
}).catch(() => {
this.dataListLoading = false
})
},
//特殊字符处理
btKeyUpkeyword(e){
e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~!#¥%……&*()={}|《》?:“”【】\\[\]、;‘’,。、\s+]/g, '')
this.dataForm.keyword = e.target.value
},
},
components: {
AddOrUpdate
},
watch: {
'deptIdList': function (val) {
if (val.length !== 0) {
this.dataForm.gridId = val[val.length - 1]
} else {
this.dataForm.gridId = ''
}
}
}
}
</script>