|
@@ -0,0 +1,259 @@
|
|
|
|
+<template>
|
|
|
|
+ <div id="add">
|
|
|
|
+ <el-row>
|
|
|
|
+ <el-col :span="24" class="main animate__animated animate__backInRight">
|
|
|
|
+ <el-col :span="24" class="one">
|
|
|
|
+ <component :is="partsSearch" :is_back="true" @toBack="toBack()"></component>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="24" class="two">
|
|
|
|
+ <component :is="CForm" :fields="infoFields" :rules="rules" :form="form" labelWidth="auto" @save="toSave">
|
|
|
|
+ <template #type>
|
|
|
|
+ <el-option v-for="i in typeList" :key="i.model" :label="i.dict_label" :value="i.dict_value"></el-option>
|
|
|
|
+ </template>
|
|
|
|
+ <template #user>
|
|
|
|
+ <el-select clearable filterable multiple collapse-tags v-model="form.user" placeholder="请选择" style="width: 100%">
|
|
|
|
+ <el-option v-for="item in userList" :key="item.id" :label="item.name || item.company" :value="item.id">
|
|
|
|
+ <span style="float: left">{{ item.name || item.company }}</span>
|
|
|
|
+ <span style="float: right; color: #8492a6; font-size: 13px">{{ item.name ? '科学家' : '依托单位' }}</span>
|
|
|
|
+ </el-option>
|
|
|
|
+ </el-select>
|
|
|
|
+ </template>
|
|
|
|
+ <template #file>
|
|
|
|
+ <component :is="CUpload" model="file" :limit="limit" :url="url" :list="form.file" @change="onChange"></component>
|
|
|
|
+ </template>
|
|
|
|
+ <template #content>
|
|
|
|
+ <component :is="WangEditor" v-model="form.content" url="/files/studioadmin/other/upload"></component>
|
|
|
|
+ </template>
|
|
|
|
+ </component>
|
|
|
|
+ <!-- <data-form :fields="fields" :form="form" :rules="rules" @save="toSave" @dataChange="dataChange" :span="24">
|
|
|
|
+ <template #type>
|
|
|
|
+ <el-option v-for="i in typeList" :key="i.model" :label="i.dict_label" :value="i.dict_value"></el-option>
|
|
|
|
+ </template>
|
|
|
|
+ <template #user>
|
|
|
|
+ <el-select clearable filterable multiple collapse-tags v-model="form.user" placeholder="请选择" style="width: 100%">
|
|
|
|
+ <el-option v-for="item in userList" :key="item.id" :label="item.name || item.company" :value="item.id">
|
|
|
|
+ <span style="float: left">{{ item.name || item.company }}</span>
|
|
|
|
+ <span style="float: right; color: #8492a6; font-size: 13px">{{ item.name ? '科学家' : '依托单位' }}</span>
|
|
|
|
+ </el-option>
|
|
|
|
+ </el-select>
|
|
|
|
+ </template>
|
|
|
|
+ <template #file="{ item }">
|
|
|
|
+ <c-upload v-model="form[item.model]" url="/files/studioadmin/other/upload" accept="" listType="text" :limit="1"></c-upload>
|
|
|
|
+ </template>
|
|
|
|
+ <template #content>
|
|
|
|
+ <editor v-model="form.content" url="/files/studioadmin/other/upload"></editor>
|
|
|
|
+ </template>
|
|
|
|
+ </data-form> -->
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-row>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+<script setup lang="ts">
|
|
|
|
+import partsSearch from '@/components/c-search.vue';
|
|
|
|
+import CForm from '@/components/c-form.vue';
|
|
|
|
+import WangEditor from '@/components/wang-editor.vue';
|
|
|
|
+import CUpload from '@/components/c-upload.vue';
|
|
|
|
+import { useRoute } from 'vue-router';
|
|
|
|
+import type { Ref } from 'vue';
|
|
|
|
+import { ref, onMounted, reactive } from 'vue';
|
|
|
|
+import type { FormRules } from 'element-plus';
|
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
|
+import { MessageStore } from '@common/src/stores/studio/other/message'; // 列表 // 列表
|
|
|
|
+import { DictDataStore } from '@common/src/stores/users/sysdictdata'; // 字典表
|
|
|
|
+import type { IQueryResult } from '@/util/types.util';
|
|
|
|
+const message = MessageStore();
|
|
|
|
+const sysdictdata = DictDataStore();
|
|
|
|
+interface dataItem {}
|
|
|
|
+let route = useRoute();
|
|
|
|
+// 表单
|
|
|
|
+let form: Ref<{ content: string; file: dataItem[]; user: dataItem[] }> = ref({ content: '', file: [], user: [] });
|
|
|
|
+// 必填项
|
|
|
|
+const rules = reactive<FormRules>({
|
|
|
|
+ title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
|
|
|
|
+ send_time: [{ required: true, message: '请选择发送时间', trigger: 'change' }],
|
|
|
|
+ type: [{ required: true, message: '请选择接收人类型', trigger: 'change' }],
|
|
|
|
+ file: [{ required: true, message: '信息文件', trigger: 'change' }],
|
|
|
|
+ content: [{ required: true, message: '信息内容', trigger: 'change' }],
|
|
|
|
+});
|
|
|
|
+// 表单
|
|
|
|
+let infoFields: Ref<any[]> = ref([
|
|
|
|
+ { label: '标题', model: 'title' },
|
|
|
|
+ { label: '发送时间', model: 'send_time', type: 'datetime' },
|
|
|
|
+ { label: '接收人类型', model: 'type', type: 'select' },
|
|
|
|
+ { label: '信息文件', model: 'file', custom: true },
|
|
|
|
+ { label: '信息内容', model: 'content', custom: true },
|
|
|
|
+]); // 接收人类型
|
|
|
|
+let typeList: Ref<any[]> = ref([]);
|
|
|
|
+// 接收人
|
|
|
|
+let userList: Ref<any[]> = ref([]);
|
|
|
|
+
|
|
|
|
+let limit: Ref<number> = ref(1);
|
|
|
|
+let url: Ref<string> = ref('/files/studioadmin/other/upload');
|
|
|
|
+onMounted(async () => {
|
|
|
|
+ await searchOther();
|
|
|
|
+ await search();
|
|
|
|
+});
|
|
|
|
+const search = async () => {
|
|
|
|
+ let form = { user_id: this.user.id };
|
|
|
|
+ this.$set(this, `form`, form);
|
|
|
|
+};
|
|
|
|
+const onChange = (e: { model: string; value: Array<dataItem> }) => {
|
|
|
|
+ const { model, value } = e;
|
|
|
|
+ form.value[model] = value;
|
|
|
|
+};
|
|
|
|
+const dataChange = (model, value) => {
|
|
|
|
+ if (model == 'type') {
|
|
|
|
+ if (value == '3') {
|
|
|
|
+ infoFields.value.splice(3, 0, { label: '接收人', model: 'user', custom: true });
|
|
|
|
+ searchUser();
|
|
|
|
+ } else {
|
|
|
|
+ infoFields.value.filter((i) => i.model != 'user');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+// 查詢用戶
|
|
|
|
+ const searchUser=async()=> {
|
|
|
|
+ // 接收人
|
|
|
|
+ let user = [];
|
|
|
|
+ // 企业用户
|
|
|
|
+ let company = await this.cQuery({ status: '1' });
|
|
|
|
+ if (company.errcode == '0' && company.total > 0) {
|
|
|
|
+ for (const val of company.data) {
|
|
|
|
+ user.push({ id: val.id, company: val.company, phone: val.phone });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 科学家用户
|
|
|
|
+ let scientist = await this.sQuery({ status: '1' });
|
|
|
|
+ if (scientist.errcode == '0' && scientist.total > 0) {
|
|
|
|
+ for (const val of scientist.data) {
|
|
|
|
+ user.push({ id: val.id, name: val.name, phone: val.phone });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.$set(this, `userList`, user);
|
|
|
|
+ },
|
|
|
|
+ // 获取用户
|
|
|
|
+ getUser(e) {
|
|
|
|
+ let user = [];
|
|
|
|
+ for (const val of e) {
|
|
|
|
+ let data = this.userList.find((i) => i.id == val);
|
|
|
|
+ if (data) user.push(data);
|
|
|
|
+ }
|
|
|
|
+ return user;
|
|
|
|
+ },
|
|
|
|
+// 提交
|
|
|
|
+const toSave = async (data: { _id: string }) => {
|
|
|
|
+ let res: IQueryResult;
|
|
|
|
+ if (data._id) res = await message.update(data);
|
|
|
|
+ else res = await message.create(data);
|
|
|
|
+ if (res.errcode == 0) {
|
|
|
|
+ ElMessage({ type: 'success', message: '维护信息成功' });
|
|
|
|
+ toBack();
|
|
|
|
+ } else ElMessage({ type: 'warning', message: `${res.errmsg}` });
|
|
|
|
+};
|
|
|
|
+const toBack = () => {
|
|
|
|
+ window.history.go(-1);
|
|
|
|
+};
|
|
|
|
+// 查询其他信息
|
|
|
|
+const searchOther = async () => {
|
|
|
|
+ // 字典表---审核状态
|
|
|
|
+ const p1: IQueryResult = await sysdictdata.query({ dict_type: 'sys_yes_no' });
|
|
|
|
+ isuseList.value = p1.data as [];
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+<!-- <script>
|
|
|
|
+
|
|
|
|
+ methods: {
|
|
|
|
+ ...mapActions(['create']),
|
|
|
|
+ ...sysdictdata({ dQuery: 'query' }),
|
|
|
|
+ search() {
|
|
|
|
+ let form = { user_id: this.user.id };
|
|
|
|
+ this.$set(this, `form`, form);
|
|
|
|
+ },
|
|
|
|
+ // 选择接收人类型
|
|
|
|
+ dataChange({ model, value }) {
|
|
|
|
+ if (model == 'type') {
|
|
|
|
+ if (value == '3') {
|
|
|
|
+ this.fields.splice(3, 0, { label: '接收人', model: 'user', custom: true });
|
|
|
|
+ this.searchUser();
|
|
|
|
+ } else {
|
|
|
|
+ this.fields.filter((i) => i.model != 'user');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 查詢用戶
|
|
|
|
+ async searchUser() {
|
|
|
|
+ // 接收人
|
|
|
|
+ let user = [];
|
|
|
|
+ // 企业用户
|
|
|
|
+ let company = await this.cQuery({ status: '1' });
|
|
|
|
+ if (company.errcode == '0' && company.total > 0) {
|
|
|
|
+ for (const val of company.data) {
|
|
|
|
+ user.push({ id: val.id, company: val.company, phone: val.phone });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 科学家用户
|
|
|
|
+ let scientist = await this.sQuery({ status: '1' });
|
|
|
|
+ if (scientist.errcode == '0' && scientist.total > 0) {
|
|
|
|
+ for (const val of scientist.data) {
|
|
|
|
+ user.push({ id: val.id, name: val.name, phone: val.phone });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.$set(this, `userList`, user);
|
|
|
|
+ },
|
|
|
|
+ // 获取用户
|
|
|
|
+ getUser(e) {
|
|
|
|
+ let user = [];
|
|
|
|
+ for (const val of e) {
|
|
|
|
+ let data = this.userList.find((i) => i.id == val);
|
|
|
|
+ if (data) user.push(data);
|
|
|
|
+ }
|
|
|
|
+ return user;
|
|
|
|
+ },
|
|
|
|
+ // 保存信息
|
|
|
|
+ async toSave({ data }) {
|
|
|
|
+ if (data.type == '3') {
|
|
|
|
+ if (data.user.length > 0) {
|
|
|
|
+ data.user = this.getUser(data.user);
|
|
|
|
+ this.createMess(data);
|
|
|
|
+ } else {
|
|
|
|
+ this.$message({ message: `请选择指定用户`, type: 'error' });
|
|
|
|
+ }
|
|
|
|
+ } else this.createMess(data);
|
|
|
|
+ },
|
|
|
|
+ // 创建信息
|
|
|
|
+ async createMess(e) {
|
|
|
|
+ let res = await this.create(e);
|
|
|
|
+ if (this.$checkRes(res, `维护信息完成`, `${res.errmsg}`)) this.toBack();
|
|
|
|
+ },
|
|
|
|
+ // 查询其他信息
|
|
|
|
+ async searchOther() {
|
|
|
|
+ let res;
|
|
|
|
+ // 接收人类型
|
|
|
|
+ res = await this.dQuery({ dict_type: 'studio_message_type' });
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$set(this, `typeList`, res.data);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 返回
|
|
|
|
+ toBack() {
|
|
|
|
+ window.history.go('-1');
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ ...mapState(['user']),
|
|
|
|
+ },
|
|
|
|
+ metaInfo() {
|
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
|
+ },
|
|
|
|
+ watch: {
|
|
|
|
+ test: {
|
|
|
|
+ deep: true,
|
|
|
|
+ immediate: true,
|
|
|
|
+ handler(val) {},
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+</script> -->
|
|
|
|
+
|
|
|
|
+<style lang="less" scoped></style>
|