123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <template>
- <Modal
- class="notice-dialog marker-modal"
- v-model="modalIsShow"
- title="消息"
- :mask-closable="false"
- footer-hide
- fullscreen
- @on-visible-change="visibleChange"
- >
- <div class="notice-container">
- <div v-if="IS_MARK_LEADER" class="notice-users">
- <div class="user-item user-all">
- <div>小组成员</div>
- <div
- :class="['user-selection', { 'is-active': userSelectAll }]"
- @click="selectAll"
- >
- <Icon v-if="userSelectAll" type="ios-checkmark-circle" />
- <Icon v-else type="md-radio-button-off" />
- </div>
- </div>
- <div
- v-for="user in markers"
- :key="user.id"
- class="user-item"
- @click="selectUser(user)"
- >
- <div class="user-avatar"><Icon type="md-contact" /></div>
- <div class="user-name" :title="user.name">{{ user.name }}</div>
- <div :class="['user-selection', { 'is-active': user.selected }]">
- <Icon v-if="user.selected" type="ios-checkmark-circle" />
- <Icon v-else type="md-radio-button-off" />
- </div>
- </div>
- </div>
- <div class="notice-body">
- <div ref="NoticeContent" class="notice-content">
- <div v-if="hasMore" class="notice-item notice-more" @click="nextPage">
- 获取更多
- </div>
- <div v-for="notice in notices" :key="notice.id" class="notice-item">
- <div class="notice-item-head">
- <span class="notice-head-users">
- {{ notice.relateUsers }}
- </span>
- <span class="notice-head-time">
- {{ notice.createTime }}
- </span>
- </div>
- <div class="notice-item-content" v-html="notice.content"></div>
- </div>
- </div>
- <div v-if="IS_MARK_LEADER" class="notice-send">
- <textarea placeholder="请输入" v-model="content"></textarea>
- <div class="notice-send-footer">
- <Button type="primary" :loading="loading" @click="toSend"
- >发送</Button
- >
- </div>
- </div>
- </div>
- </div>
- </Modal>
- </template>
- <script>
- import { mapState, mapMutations } from "vuex";
- import {
- userSendNoticeList,
- userReceiveNoticeList,
- fetchReleaseUnreadNotice,
- readNotice,
- sendNotice,
- leaderMarkUserList
- } from "@/api";
- import timeMixin from "@/plugins/timeMixin";
- export default {
- name: "ribbon-set-dialog",
- mixins: [timeMixin],
- data() {
- return {
- workId: "",
- subject: "",
- modalIsShow: false,
- curUserRoleType: this.$ls.get("user", { role: "" }).role,
- userSelectAll: false,
- markers: [],
- notices: [],
- current: 0,
- size: 10,
- content: "",
- hasMore: false,
- fetching: false,
- loading: false
- };
- },
- computed: {
- ...mapState("marker", ["curSubject"]),
- IS_MARKER() {
- return this.curUserRoleType === "MARKER";
- },
- IS_MARK_LEADER() {
- return this.curUserRoleType === "MARK_LEADER";
- }
- },
- mounted() {
- const [workId, subject] = this.$route.params.subjectId.split("-");
- this.workId = workId;
- this.subject = subject;
- this.initData();
- },
- beforeDestroy() {
- this.clearSetTs();
- },
- methods: {
- ...mapMutations("marker", ["setShortcut", "recoverShortcut"]),
- async initData() {
- if (this.IS_MARK_LEADER) {
- this.getLeaderMarkerList();
- this.getLeaderMarkerNoticeList();
- return;
- }
- if (this.IS_MARKER) {
- this.getMarkerNoticeList();
- this.addSetTime(() => {
- this.getNewNotice();
- }, 10 * 1000);
- }
- },
- visibleChange(visible) {
- if (visible) {
- if (this.IS_MARKER) {
- this.setNoticeRead();
- }
- this.goToBottom();
- this.setShortcut([]);
- } else {
- this.recoverShortcut();
- }
- },
- goToBottom() {
- this.$nextTick(() => {
- this.$refs.NoticeContent.scrollTop = this.$refs.NoticeContent.offsetHeight;
- });
- },
- async getLeaderMarkerList() {
- const markerId = this.$ls.get("user", { id: "" }).id;
- const data = await leaderMarkUserList({
- workId: this.workId,
- subject: this.subject,
- stage: this.curSubject.stage,
- markerId
- });
- const markers = data || [];
- this.markers = markers.map(item => {
- item.selected = false;
- return item;
- });
- },
- async nextPage() {
- if (this.fetching) return;
- this.fetching = true;
- this.current++;
- if (this.IS_MARKER) {
- await this.getMarkerNoticeList().catch(() => {});
- } else {
- await this.getLeaderMarkerNoticeList().catch(() => {});
- }
- this.fetching = false;
- },
- async getLeaderMarkerNoticeList() {
- const sendUserId = this.$ls.get("user", { id: "" }).id;
- const lastId = this.notices.length ? this.notices.slice(-1)[0].id : null;
- const data = await userSendNoticeList({
- subject: this.subject,
- stage: this.curSubject.stage,
- sendUserId,
- lastId,
- page: this.current,
- size: this.size
- });
- const notices = data.content.map(item => {
- item.receiveUser = JSON.parse(item.receiveUser);
- item.relateUsers = item.receiveUser.map(user => user.name).join(",");
- return item;
- });
- notices.reverse();
- this.hasMore = this.current + 1 < data.totalPages;
- this.notices = [...notices, ...this.notices];
- },
- parseMarkerNotice(info) {
- return {
- ...info.message,
- id: info.id,
- read: info.read,
- relateUsers: info.message.sendUserName
- };
- },
- async getMarkerNoticeList() {
- const receiveUserId = this.$ls.get("user", { id: "" }).id;
- const lastId = this.notices.length ? this.notices.slice(-1)[0].id : null;
- const data = await userReceiveNoticeList({
- subject: this.subject,
- stage: this.curSubject.stage,
- receiveUserId,
- lastId,
- page: this.current,
- size: this.size
- });
- const notices = data.content.map(item => {
- return this.parseMarkerNotice(item);
- });
- notices.reverse();
- this.hasMore = this.current + 1 < data.totalPages;
- this.notices = [...notices, ...this.notices];
- },
- async getNewNotice() {
- this.clearSetTs();
- const receiveUserId = this.$ls.get("user", { id: "" }).id;
- const resData = await fetchReleaseUnreadNotice({
- subject: this.subject,
- stage: this.curSubject.stage,
- receiveUserId
- }).catch(() => {});
- const data = resData || [];
- const noticeIds = this.notices.map(item => item.id);
- const validNotices = data
- .filter(item => !noticeIds.includes(item.id))
- .map(item => this.parseMarkerNotice(item));
- if (validNotices.length) {
- this.notices.push(...validNotices);
- this.open();
- this.goToBottom();
- this.$nextTick(() => {
- this.setNoticeRead();
- });
- }
- this.addSetTime(() => {
- this.getNewNotice();
- }, 10 * 1000);
- },
- setNoticeRead() {
- const noticeIds = this.notices
- .filter(item => !item.read)
- .map(item => item.id);
- if (!noticeIds.length) return;
- readNotice(noticeIds);
- },
- cancel() {
- this.modalIsShow = false;
- },
- open() {
- this.modalIsShow = true;
- },
- selectChange() {
- this.userSelectAll = !this.markers.some(item => !item.selected);
- },
- selectUser(user) {
- user.selected = !user.selected;
- this.selectChange();
- },
- selectAll() {
- this.userSelectAll = !this.userSelectAll;
- this.markers.forEach(user => {
- user.selected = this.userSelectAll;
- });
- },
- async toSend() {
- if (!this.content) {
- this.$Message.error("请输入内容");
- return;
- }
- const user = this.$ls.get("user", { id: "", name: "" });
- const markers = this.markers
- .filter(item => item.selected)
- .map(item => {
- return {
- id: item.id,
- name: item.name
- };
- });
- if (!markers.length) {
- this.$Message.error("请选择评卷员");
- return;
- }
- if (this.loading) return;
- this.loading = true;
- const data = {
- subject: this.subject,
- stage: this.curSubject.stage,
- sendUserId: user.id,
- sendUserName: user.name,
- content: this.content,
- markers
- };
- const res = await sendNotice(data).catch(() => {});
- this.loading = false;
- if (!res) return;
- this.content = "";
- res.receiveUser = JSON.parse(res.receiveUser);
- res.relateUsers = res.receiveUser.map(item => item.name).join(",");
- this.notices.push({ ...res });
- this.goToBottom();
- }
- }
- };
- </script>
|