<template>
|
<view class="container">
|
|
<view class="group-chat-box">
|
|
<u-form :model="form" ref="uForm">
|
|
<u-form-item label-width='132' prop="title" label="通知标题" :required="true">
|
<u-input type='text' v-model="form.title" placeholder="请输入通知标题" />
|
</u-form-item>
|
|
<u-form-item label-width='132' prop="content" label="通知内容" :required="true">
|
<u-input type='textarea' v-model="form.content" placeholder="请输入通知内容" />
|
</u-form-item>
|
|
<u-form-item label-width='132' label="接收人">
|
|
<u-input type='textarea' v-model="form.recipientPeople" placeholder="请选择指令接收人"
|
@click="recipientClick" autoHeight />
|
|
<!-- <u-button slot="right" type="success" size="mini" @click="recipientClick">选择接收人</u-button> -->
|
|
<u-popup :closeable="true" v-model="recipientShow" mode="bottom" height="50%" border-radius="14">
|
|
<view>
|
|
<u-checkbox-group v-show="recipientList.length > 0" @change="checkboxGroupChange"
|
:wrap='true' :size="40">
|
|
<u-checkbox v-model="item.checked" v-for="(item, index) in recipientList" :key="index"
|
:name="item.id" shape="circle"
|
style="padding: 0 40rpx; height: 92rpx; position: relative; box-sizing: border-box;">
|
|
<view style="margin-left: 22rpx">
|
{{item.real_name}}
|
</view>
|
|
</u-checkbox>
|
|
</u-checkbox-group>
|
|
<view style=" height: 92rpx; padding: 0 40rpx;" v-show="recipientList.length == 0">
|
|
暂无数据
|
|
</view>
|
|
</view>
|
|
</u-popup>
|
|
</u-form-item>
|
|
</u-form>
|
|
</view>
|
|
<view class="establish-box">
|
<u-button class="submit" type="primary" @click="initiateClick">发送
|
</u-button>
|
</view>
|
|
<view>
|
<u-toast ref="uToast" />
|
</view>
|
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
recipientShow: false,
|
recipientList: [],
|
|
form: {
|
title: '',
|
content: '',
|
recipientData: [],
|
recipientPeople: ''
|
},
|
rules: {
|
content: [{
|
min: 5,
|
required: true,
|
message: '通知内容不能少于5个字',
|
trigger: ['change', 'blur'],
|
}],
|
|
title: [{
|
required: true,
|
message: '请输入通知标题',
|
trigger: ['change', 'blur'],
|
}],
|
|
},
|
createData: null,
|
};
|
},
|
onLoad() {
|
this.createData = this.$store.state.UserData
|
},
|
onReachBottom() {
|
|
},
|
mounted() {},
|
onReady() {
|
|
this.$refs.uForm.setRules(this.rules);
|
|
},
|
methods: {
|
recipientClick() {
|
|
if (this.recipientList.length > 0) {
|
this.recipientShow = true;
|
return
|
}
|
|
var data = null;
|
|
if (this.$store.state.UserData.rname[0] ==
|
'保安公司管理员') {
|
|
data = {
|
type: 2,
|
deptid: this.$store.state.UserData.dept_id
|
}
|
|
uni.request({
|
url: this.$store.state.piAPI + "/blade-user/seleL",
|
method: "get",
|
data: data,
|
success: (res) => {
|
|
this.recipientList = []
|
res.data.data.forEach(item => {
|
|
if (item.id != this.$store.state
|
.UserData.user_id
|
) {
|
|
item.checked = false;
|
this.recipientList.push(item)
|
|
}
|
|
})
|
|
this.recipientShow = true;
|
|
}
|
});
|
|
|
} else {
|
|
uni.request({
|
url: this.$store.state.piAPI + '/blade-user/pages?dispatch=0&jurisdiction=' + this.$store
|
.state.UserData.jurisdiction + '¤t=1&size=999999',
|
method: "get",
|
data: data,
|
success: (res) => {
|
|
this.recipientList = []
|
res.data.data.records.forEach(item => {
|
|
if (item.id != this.$store.state
|
.UserData.user_id
|
) {
|
|
item.checked = false
|
item.real_name = item.realName
|
this.recipientList.push(item)
|
|
}
|
|
})
|
|
this.recipientShow = true;
|
|
}
|
});
|
|
|
}
|
|
},
|
|
checkboxGroupChange(e) {
|
var that = this
|
|
this.form.recipientData = e
|
|
var str = ""
|
var num = 0
|
|
that.form.recipientData.forEach((item, index) => {
|
that.recipientList.forEach((it, index) => {
|
if (item == it.id) {
|
if (num > 0) {
|
str += '、';
|
str += it.real_name;
|
} else {
|
str += it.real_name
|
}
|
num += 1
|
return
|
}
|
})
|
})
|
|
this.form.recipientPeople = str
|
|
},
|
|
getCurrentTime() {
|
let date = new Date();
|
let dateYear = date.getFullYear(); //获取年
|
let dateMonth = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1); //获取月
|
let dateDate = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); //获取当日
|
let dateDay = date.getDay(); //获取当日星期数
|
let dateHours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(); //获取小时
|
let dateMinutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(); //获取分钟
|
let dateSeconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(); //获取秒
|
|
return dateYear + '-' + dateMonth + '-' + dateDate + ' ' + dateHours + ':' + dateMinutes + ':' +
|
dateSeconds
|
},
|
|
initiateClick() {
|
|
this.$refs.uForm.validate(valid => {
|
if (valid) {
|
|
if (this.form.recipientData.length == 0) {
|
this.$refs.uToast.show({
|
title: '请最少选择一个接收人',
|
})
|
return
|
}
|
|
var receivedNameStr = []
|
|
this.form.recipientData.forEach(it => {
|
|
this.recipientList.forEach(item => {
|
|
if (it.id == item.id) {
|
receivedNameStr.push(item.real_name)
|
}
|
|
})
|
|
})
|
|
uni.request({
|
url: this.$store.state.piAPI + "/blade-system/dept/detail",
|
method: "get",
|
data: {
|
id: this.createData.dept_id
|
},
|
success: (result) => {
|
|
var deptCategory = result.data.data.deptCategory;
|
|
uni.request({
|
url: this.$store.state.piAPI + "/blade-desk/notice/submit",
|
method: "post",
|
data: {
|
type: 1,
|
title: this.form.title,
|
content: this.form.content,
|
category: deptCategory,
|
deptId: this.createData.dept_id,
|
releaseTime: this.getCurrentTime(),
|
receivedName: receivedNameStr.toString(),
|
receivedIds: this.form.recipientData.toString(),
|
},
|
success: (res) => {
|
if (res.data.msg == "操作成功") {
|
this.$refs.uToast.show({
|
title: '新增通知成功',
|
type: 'success',
|
url: '/pages/message/message'
|
})
|
}
|
}
|
});
|
|
}
|
});
|
|
|
} else {
|
console.log('验证失败');
|
}
|
});
|
},
|
|
|
}
|
};
|
</script>
|
|
|
<style lang="scss">
|
.submit {
|
border: none;
|
width: 94%;
|
height: 86rpx;
|
line-height: 86rpx;
|
box-sizing: border-box;
|
border-radius: 15rpx;
|
color: #ffffff;
|
font-size: 38rpx;
|
|
}
|
|
.container {
|
height: 100%;
|
|
.group-chat-box {
|
height: calc(100% - 116rpx);
|
padding: 0 36rpx;
|
box-sizing: border-box;
|
overflow-y: auto;
|
}
|
|
.establish-box {
|
position: relative;
|
height: 116rpx;
|
background: #fff;
|
text-align: center;
|
|
uni-button {
|
margin: 0;
|
position: absolute;
|
top: 0;
|
left: 0;
|
right: 0;
|
bottom: 0;
|
margin: auto;
|
}
|
|
}
|
|
}
|
</style>
|