zhouwx
8 天以前 346ffdf4c528ecfa8471a13cdb6f3740a29262e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<template>
  <div class="notice">
    <el-dialog
        v-model="dialogVisible"
        :title="title"
        width="800px"
        :before-close="handleClose"
    >
      <el-form :model="state.noticeForm" size="default" ref="noticeRef" :rules="title === '新增' || title === '编辑' ? state.formRules : {}" label-width="140px" >
        <el-form-item label="单位名称:" prop="companyId" v-if="state.isAdmin">
          <el-select v-model="state.noticeForm.companyId" placeholder="请选择" @change="changeCom" filterable clearable style="width: 100%" :disabled="title == '查看' || title == '编辑' || !state.isAdmin">
            <el-option
                v-for="item in state.companyList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="质量手册颁布令:" v-if="showEditor"  required>
          <t-editor style="width: 800px" ref="myEditor" :toolbar="toolbar" :value="state.noticeForm.content" ></t-editor>
        </el-form-item>
        <el-form-item label="质量手册颁布令:" v-else>
          <div class="ql-container ql-snow" style="height: 500px;width: 100%;margin-top: 10px;" >
            <div class="ql-editor">
              <div class="reviewTable" v-html="state.noticeForm.content" ></div>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="批准人:" prop="checkId">
          <el-select clearable v-model="state.noticeForm.checkId" :disabled="title =='查看'" filterable placeholder="批准人" style="width: 100%">
            <el-option
                v-for="item in state.userList"
                :key="item.userId"
                :label="item.name"
                :value="item.userId"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer v-if="!isReview">
        <span class="dialog-footer">
            <el-button @click="handleClose" size="default">取 消</el-button>
            <el-button type="primary"  @click="onSubmit" size="default" v-preReClick>确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import {nextTick, onMounted, reactive, ref, toRefs, watch} from 'vue'
import WeEditor from "@/components/WeEditor/index.vue";
import TEditor from "@/components/Tinymce/Tinymce.vue"
import {ElMessage} from "element-plus";
import Cookies from "js-cookie";
import {getEmployeeRecords} from "@/api/onlineEducation/user";
import {addDecree, editDecree} from "@/api/decree";
 
 
const emit = defineEmits(["getList"]);
 
const dialogVisible = ref(false);
const toolbar = ref('fontsizeselect | undo redo')
const title = ref("");
const noticeRef = ref();
const fileList = ref([]);
const myEditor = ref();
const isReview = ref(false);
const showEditor = ref(true);
const state = reactive({
  noticeForm: {
    id: '',
    content: '',
    companyId:null,
    checkId:null,
    type:1,
    companyName: ''
  },
  formRules:{
    companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }],
    content: [{ required: true, message: '请输入质量手册颁布令', trigger: 'blur' }],
    checkId: [{ required: true, message: '请选择批准人', trigger: 'blur' }],
  },
  isAdmin: false,
  companyList: [],
  userList:[]
 
})
 
onMounted(() => {
 
});
const openDialog = async (type, value,companyList) => {
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  state.isAdmin = userInfo.userType === 0;
  if(state.isAdmin){
    state.companyList = companyList
    state.noticeForm.companyId = null
  }else  {
    state.noticeForm.companyId = userInfo.companyId
  }
  isReview.value = false;
  showEditor.value = false
  title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ;
  if(type === 'edit' || type === 'review') {
    Object.keys(state.noticeForm).forEach(key => {
      if (key in value) {
        state.noticeForm[key] = value[key]
      }
    })
  }
  if(type === 'review') {
    showEditor.value = false
    isReview.value = true;
  }
  if(type === 'edit' || type === 'add') {
    showEditor.value = true;
    isReview.value = false;
  }
  await getUserList()
  dialogVisible.value = true;
}
 
const onSubmit = async () => {
  state.noticeForm.content = tinyMCE.activeEditor.getContent();
  if(!state.isAdmin){
    const userInfo = JSON.parse(Cookies.get('userInfo'))
    state.noticeForm.companyId = userInfo.companyId
  }
  const valid = await noticeRef.value.validate();
  if(valid){
    if(title.value === '新增'){
      const {id,...data} = JSON.parse(JSON.stringify(state.noticeForm))
      const res = await addDecree(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '新增成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      reset();
      showEditor.value=false
      myEditor.value.clear();
      noticeRef.value.clearValidate();
      dialogVisible.value = false;
    }else if(title.value === '编辑') {
      const {...data} = JSON.parse(JSON.stringify(state.noticeForm))
      const res = await editDecree(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '编辑成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      reset();
      showEditor.value=false
      myEditor.value.clear();
      noticeRef.value.clearValidate();
      dialogVisible.value = false;
    }
  }
}
const getUserList = async ()=> {
  if(state.isAdmin && (state.noticeForm.companyId == 0 || state.noticeForm.companyId == null)){
    return
  }
  const res = await getEmployeeRecords({companyId: state.noticeForm.companyId})
  if(res.code == 200){
    state.userList = res.data ? res.data :[]
  }else{
    ElMessage.warning(res.message)
  }
}
const handleClose = () => {
  if(title.value ==="新增"|| title.value ==='编辑'){
    myEditor.value.clear();
    showEditor.value=false
  }
 
  reset()
  noticeRef.value.clearValidate();
  dialogVisible.value = false;
}
const reset = () => {
  state.noticeForm = {
    id: '',
    content: '',
    companyId:null,
    checkId:null,
    type:1,
    companyName: ''
  }
  state.companyList = []
  state.userList = []
}
const changeCom = () => {
  state.noticeForm.checkId = ''
  getUserList()
}
 
 
defineExpose({
  openDialog
});
 
</script>
 
<style scoped lang="scss">
.notice{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
  .file {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
}
.reviewTable {
  :deep(table){
    border: 1px solid #ccc;
    text-align: center;
  }
  :deep(table td){
    border: 1px solid #ccc;
    text-align: center;
    padding: 0 5px;
  }
  :deep(table th){
    border: 1px solid #ccc;
  }
}
 
 
</style>