华西海圻ELN前端工程
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.

1204 lines
44 KiB

  1. <template>
  2. <div class="flex flex1">
  3. <div class="flex1 flex">
  4. <el-input v-if="type === 'input'" :maxlength="item.maxlength || 50" :disabled="getDisabled()"
  5. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" @blur="onBlur"
  6. :placeholder="getPlaceholder()" v-model="inputValue" @input="onInputChange" @change="onInputChange" />
  7. <el-input v-else-if="type === 'textarea'" :maxlength="item.maxlength || 50" :disabled="getDisabled()"
  8. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" type="textarea" show-word-limit
  9. resize="none" @blur="onBlur" :rows="item.rows || 3" :placeholder="getPlaceholder()" v-model="inputValue"
  10. @input="onInputChange" @change="onInputChange" />
  11. <DecimalInput v-else-if="type === 'inputNumber'" @blur="onCommonHandleSaveRecord"
  12. :maxlength="item.maxlength || 10" class="flex1" :disabled="getDisabled()"
  13. :controls="item.controls || false" :min="item.min || 0" :prepend="item.prepend"
  14. :decimalDigits="item.precision || 6" :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')"
  15. :placeholder="getPlaceholder()" v-model="inputValue" @input="onInputChange" @change="onInputChange" />
  16. <el-select v-else-if="type === 'select'" class="flex1" :multiple="item.multiple"
  17. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" v-model="inputValue"
  18. :disabled="getDisabled()" :placeholder="getPlaceholder()" @remove-tag="onRemoveTag"
  19. @visible-change="onSelectBlur" @change="onInputChange">
  20. <el-option v-for="op in item.options" :key="op.value" :label="op.label" :value="op.value">
  21. </el-option>
  22. </el-select>
  23. <el-checkbox v-else-if="type === 'checkbox'" class="flex1" :multiple="item.multiple"
  24. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" v-model="inputValue"
  25. :disabled="getDisabled()" :placeholder="getPlaceholder()" @change="onItemCheckboxChange">
  26. </el-checkbox>
  27. <el-date-picker v-else-if="type === 'dateTime'" type="datetime" class="flex1"
  28. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" v-model="inputValue"
  29. :disabled="getDisabled()" format="yyyy/MM/dd HH:mm:ss" :placeholder="getPlaceholder()"
  30. @change="(val) => onDateChange(val, 'yyyy/MM/DD HH:mm:ss')">
  31. </el-date-picker>
  32. <el-date-picker v-else-if="type === 'datePicker'" class="flex1"
  33. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" v-model="inputValue"
  34. :disabled="getDisabled()" format="yyyy/MM/dd" :placeholder="getPlaceholder()"
  35. @change="(val) => onDateChange(val, 'yyyy/MM/DD')">
  36. </el-date-picker>
  37. <el-button v-else-if="type === 'button'" :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')"
  38. :disabled="getDisabled()" type="primary" @click="handleClickButton(item)">
  39. {{ item.buttonName }}
  40. </el-button>
  41. <div class="clickable"
  42. :class="getFillTypeStyle() + (getDisabled() ? ' disabled' : '') + (orangeBg ? ' orange-bg' : '')"
  43. v-else-if="item.type === 'clickable'" @click="handleClickable(item, $event)">
  44. <span v-if="inputValue">{{ inputValue }}</span>
  45. <span v-else class="default-placeholder-text">{{ getPlaceholder() }}</span>
  46. </div>
  47. <div class="clickable"
  48. :class="getFillTypeStyle() + (getDisabled() ? ' disabled' : '') + (orangeBg ? ' orange-bg' : '')"
  49. v-else-if="regentType.includes(item.type)" @click="onCommonHandleRegent(item, item.type)">
  50. <span v-if="inputValue">{{ inputValue }}</span>
  51. <span v-else class="default-placeholder-text">{{ getPlaceholder() }}</span>
  52. </div>
  53. <template v-else-if="type === 'attachment'">
  54. <el-upload ref="uploadRef" class="upload-demo" :action="uploadFileUrl" :on-preview="handlePreview"
  55. :headers="headers"
  56. :before-remove="beforeRemove"
  57. :on-remove="handleRemove" multiple :limit="10"
  58. :on-success="handleSuccess"
  59. :on-change="handleChange"
  60. :on-exceed="handleExceed" :file-list="fileList"
  61. :auto-upload="false">
  62. <el-button :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" size="small" type="primary">点击上传</el-button>
  63. <div slot="tip" class="el-upload__tip">支持扩展名.rar .zip .doc .docx .pdf .jpg文件大小不超过2MB</div>
  64. </el-upload>
  65. </template>
  66. </div>
  67. <div class="handle-row" v-if="isShowHandle()">
  68. <el-checkbox v-model="checkboxValue" v-if="getIsShowCheckboxIcon()" :disabled="getCheckboxDisabled()"
  69. class="mr-5" @change="onCheckboxChange"></el-checkbox>
  70. <div class="handle-icon" v-if="getIsShowQuestionIcon()" @click="onClickQuestion"
  71. @mouseenter="(e) => onMouseEnter('replyRecord', e)" @mouseleave="onMouseLeave">
  72. <Question :class="getQuestionColor()" />
  73. </div>
  74. <img v-if="getIsShowCopyIcon()" @click="onCopy" src="@/assets/images/copy-icon.svg" class="handle-icon"
  75. alt="" />
  76. <img v-if="getIsShowRecordIcon()" @mouseenter="(e) => onMouseEnter('fieldChanged', e)"
  77. @mouseleave="onMouseLeave" src="@/assets/images/record-icon.svg" class="handle-icon" alt="" />
  78. </div>
  79. <!-- 修改记录模态框 -->
  80. <div v-if="showModal && modificationRecords.length > 0" ref="modalRef"
  81. :class="['modification-modal', { 'show': showModal }]" @mouseenter="onModalEnter"
  82. @mouseleave="onModalLeave">
  83. <div class="modal-content">
  84. <div class="records-list">
  85. <div v-for="(record, index) in modificationRecords" :key="index" class="record-item">
  86. <!-- 字段修改记录 -->
  87. <div class="record-row" v-if="currentRecordType === 'fieldChanged'">
  88. <div>
  89. <span>{{ index + 1 }}.</span>
  90. <span> {{ getUserName(record) }} </span>
  91. <span>{{ record.time }} </span>
  92. <span>{{ modificationRecords.length - 1 == index ? "提交" : "修改" }}</span>
  93. </div>
  94. <div v-if="modificationRecords.length - 1 !== index">
  95. <div>原值{{ record.oldValue }}</div>
  96. <div>修改值{{ record.value }}</div>
  97. <div v-if="record.reason">备注{{ record.reason }}</div>
  98. </div>
  99. </div>
  100. <!-- 回复记录 -->
  101. <div class="record-row" v-if="currentRecordType === 'replyRecord'">
  102. <div>
  103. <span> {{ getUserName(record) }} </span>
  104. <span>{{ record.time }} </span>
  105. </div>
  106. <div>
  107. <div v-if="record.content">复核意见{{ record.content }}</div>
  108. <div v-if="record.reply">回复意见{{ record.reply }}</div>
  109. </div>
  110. </div>
  111. <hr v-if="index < modificationRecords.length - 1">
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. <el-dialog :close-on-click-modal="false" append-to-body :title="templateFillType == 'actFill' ? '回复意见' : '复核意见'"
  117. :visible.sync="visible" width="30%">
  118. <el-input v-model="replyContent" type="textarea" show-word-limit resize="none" rows="8" placeholder="输入内容"
  119. maxlength="500" />
  120. <span slot="footer" class="dialog-footer">
  121. <el-button @click="visible = false"> </el-button>
  122. <el-button type="primary" @click="onReplyConfirm"> </el-button>
  123. </span>
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <script>
  128. import Question from "./icons/Question.vue";
  129. import DecimalInput from "./DecimalInput.vue";
  130. import { EventBus } from "@/utils/eventBus";
  131. import moment from "moment";
  132. import { deepClone } from "@/utils/index";
  133. import { getuuid } from "@/utils/index.js";
  134. import { getToken } from "@/utils/auth"
  135. export default {
  136. inject: ['templateData', 'templateFillType', "getZdxgjl", "getFhyjjl", "updateZdxgjl", "replaceFhyjjl", "updateFhyjjl", "getFieldCheckObj", "updateFieldCheckObj"],
  137. components: {
  138. Question,
  139. DecimalInput,
  140. },
  141. props: {
  142. type: {//form类型 input/select等
  143. type: String,
  144. default: "input"
  145. },
  146. item: {
  147. type: Object,
  148. default: () => {
  149. return {
  150. placeholder: "",
  151. maxlength: 30,
  152. label: "",
  153. disabled: false,
  154. }
  155. }
  156. },
  157. // v-model 值
  158. value: {
  159. type: [String, Number, Array, Boolean],
  160. default: ''
  161. },
  162. // 错误状态
  163. error: {
  164. type: Boolean,
  165. default: false
  166. },
  167. // 橙色背景状态
  168. orangeBg: {
  169. type: Boolean,
  170. default: false
  171. },
  172. fieldKey: {
  173. type: String,
  174. default: ""
  175. },
  176. fieldItemLabel: {
  177. type: String,
  178. default: "",
  179. },
  180. //是否记录修改
  181. isFieldsRecord: {
  182. type: Boolean,
  183. default: true,
  184. },
  185. sourceFrom: {
  186. type: String,
  187. default: ""
  188. },
  189. },
  190. data() {
  191. return {
  192. inputValue: this.value,
  193. oldValue: this.value, // 记录上一次的值
  194. showModal: false, // 控制模态框显示
  195. modificationRecords: [], // 存储修改记录
  196. modalTimer: null, // 用于延迟隐藏模态框
  197. isHoveringModal: false, // 是否悬停在模态框上
  198. isHoveringMain: false, // 是否悬停在主元素上(这个实际上不需要,因为我们有事件处理)
  199. currentRecordType: '', // 当前悬停的记录类型(replyRecord 或 modifyRecord)
  200. replyContent: '', // 回复内容
  201. visible: false,//是否显示弹窗
  202. checkboxValue: this.getChecked(),//是否选中
  203. uuid: getuuid(), // 唯一标识符,用于EventBus事件匹配
  204. regentType: ['sj', 'gsp', 'mix', 'xj', 'xb', 'gyzj', 'mjy', 'yq'], //试剂/仪器/供试品等类型
  205. selectRegentInfo: {},//选择的试剂/仪器/供试品等信息
  206. fileList: [],//上传的文件列表
  207. uploadFileUrl: process.env.VUE_APP_BASE_API + "/file/upload",
  208. headers: {
  209. Authorization: "Bearer " + getToken(),
  210. },
  211. }
  212. },
  213. watch: {
  214. value(newVal) {
  215. this.inputValue = newVal;
  216. }
  217. },
  218. filters: {
  219. },
  220. mounted() {
  221. if(this.item.type === 'attachment'){
  222. try{
  223. this.fileList = JSON.parse(this.value);
  224. }catch(e){
  225. this.fileList = [];
  226. }
  227. }
  228. EventBus.$on('onExternalFieldUpdate', this.handleExternalFieldUpdate);
  229. EventBus.$on('onEditSignCancel', this.handleEditSignCancel);
  230. EventBus.$on('onEditSignCallback', this.handleEditSignCallback);
  231. //试剂
  232. EventBus.$on("onReagentSubmit", this.onReagentSubmit)
  233. //仪器
  234. EventBus.$on("onInstrumentSubmit", this.onMixReagentSubmit)
  235. //供试品/试剂/给药制剂等
  236. EventBus.$on("onMixReagentSubmit", this.onMixReagentSubmit)
  237. },
  238. unmounted() {
  239. EventBus.$off('onExternalFieldUpdate', this.handleExternalFieldUpdate);
  240. EventBus.$off('onEditSignCancel', this.handleEditSignCancel);
  241. EventBus.$off('onEditSignCallback', this.handleEditSignCallback);
  242. EventBus.$off("onReagentSubmit", this.onReagentSubmit)
  243. EventBus.$off("onInstrumentSubmit", this.onMixReagentSubmit)
  244. EventBus.$off("onMixReagentSubmit", this.onMixReagentSubmit)
  245. },
  246. methods: {
  247. onInstrumentSubmit(data){
  248. if(data.uuid !== this.uuid) return;
  249. this.selectRegentInfo = data;
  250. console.log(data,"yq")
  251. },
  252. // 删除前确认
  253. beforeRemove(file) {
  254. return this.$confirm(`确定移除 ${file.name}`)
  255. },
  256. // 文件状态改变时的钩子,添加文件、上传成功、上传失败时都会被调用
  257. handleChange(file, fileList) {
  258. // 如果是新添加的文件(status为ready),进行验证
  259. if (file.status === 'ready') {
  260. const isAllowedType = ['image/jpeg', 'image/png', 'image/gif', 'application/pdf',
  261. 'application/x-rar-compressed', 'application/zip',
  262. 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'].includes(file.raw.type)
  263. const isLt2M = file.size / 1024 / 1024 < 2
  264. if (!isAllowedType) {
  265. this.$message.error(`文件 ${file.name} 格式不支持!只能上传 JPG/PNG/GIF/PDF/RAR/ZIP/DOC/DOCX 格式的文件`)
  266. // 从fileList中移除该文件
  267. const index = fileList.indexOf(file);
  268. if (index > -1) {
  269. fileList.splice(index, 1);
  270. }
  271. this.fileList = [...fileList];
  272. return
  273. }
  274. if (!isLt2M) {
  275. this.$message.error(`文件 ${file.name} 大小超过2MB!`)
  276. // 从fileList中移除该文件
  277. const index = fileList.indexOf(file);
  278. if (index > -1) {
  279. fileList.splice(index, 1);
  280. }
  281. this.fileList = [...fileList];
  282. return
  283. }
  284. // 验证通过,手动提交上传
  285. this.$nextTick(() => {
  286. // 找到对应的upload组件并提交
  287. const uploadComponent = this.$refs.uploadRef;
  288. if (uploadComponent) {
  289. uploadComponent.submit();
  290. }
  291. });
  292. }
  293. // 更新fileList
  294. this.fileList = fileList;
  295. },
  296. handleSuccess(res, file, fileList) {
  297. if(res.code == 200){
  298. this.fileList = fileList;
  299. // 更新inputValue为文件路径列表,方便后续保存
  300. this.inputValue = JSON.stringify(this.getFileList(fileList));
  301. this.$emit("change",this.inputValue)
  302. this.onCommonHandleSaveRecord();
  303. this.$message.success('文件上传成功');
  304. } else {
  305. this.$message.error(res.message || '文件上传失败');
  306. // 上传失败,从列表中移除
  307. const index = fileList.indexOf(file);
  308. if (index > -1) {
  309. fileList.splice(index, 1);
  310. this.fileList = [...fileList];
  311. }
  312. }
  313. },
  314. getFileList(fileList) {
  315. const list = [];
  316. fileList.forEach(item => {
  317. const o = {name:item.name};
  318. if(item.url){//回填的数据
  319. o.url = item.url
  320. }else{//新上传的
  321. o.url = item.response.data.url
  322. }
  323. list.push(o)
  324. })
  325. return list;
  326. },
  327. handleRemove(file, fileList) {
  328. // 从列表中移除文件
  329. const index = fileList.indexOf(file);
  330. if (index > -1) {
  331. fileList.splice(index, 1);
  332. }
  333. // 更新inputValue为剩余文件路径列表
  334. this.inputValue = JSON.stringify(this.getFileList(fileList));
  335. this.$emit("change",this.inputValue)
  336. // 触发保存记录
  337. this.onCommonHandleSaveRecord();
  338. this.$message.success(`文件 ${file.name} 已移除`);
  339. },
  340. handlePreview(file) {
  341. if (file.url) {
  342. window.open(process.env.VUE_APP_FILE_DOMAIN + file.url, '_blank');
  343. }
  344. },
  345. handleExceed(files, fileList) {
  346. this.$message.warning(`当前限制选择 10 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
  347. },
  348. //试剂弹窗提交
  349. onMixReagentSubmit(data) {
  350. if (data.uuid !== this.uuid) return;
  351. this.inputValue = data.selectedId;
  352. this.selectRegentInfo = data;
  353. this.onCommonHandleSaveRecord(this.inputValue);
  354. // this.inputValue = this.item.label;
  355. },
  356. //统一处理试剂/供试品等弹窗
  357. onCommonHandleRegent(item, type) {
  358. if (this.templateFillType !== 'actFill') {
  359. return
  360. }
  361. let params = {
  362. studyFormId: this.templateData.id,
  363. uuid: this.uuid,
  364. sourceFrom: this.sourceFrom,
  365. }
  366. let eventName = "showSelectMixReagentDialog";
  367. if (type === "yq") {
  368. eventName = "showSelectInstrumentDialog";
  369. }else {
  370. const sjType = {
  371. sj: "1",//试剂
  372. gsp: "7",//供试品
  373. mix: "1",//试剂/供试品/试剂
  374. gyzj: "3",//给药制剂
  375. mjy: "5",//麻精药
  376. xj: "9",//细菌
  377. xb: "11",//细胞
  378. }
  379. params = {
  380. ...params,
  381. type: sjType[type]
  382. }
  383. }
  384. EventBus.$emit(eventName, params)
  385. // this.$emit('regent', item,type);
  386. },
  387. // 点击按钮
  388. handleClickButton(item) {
  389. this.$emit('clickButton', item);
  390. },
  391. onDateChange(val, format) {
  392. this.inputValue = moment(val).format(format);
  393. console.log(this.inputValue, "inputValue")
  394. this.onCommonHandleSaveRecord(this.inputValue);
  395. },
  396. getUserName(record) {
  397. const locale = this.$i18n.locale;
  398. if (locale === 'zh_CN') {
  399. return record.userNameCn;
  400. }
  401. return record.userNameEn;
  402. },
  403. // 处理电子签名取消事件
  404. handleEditSignCancel(data) {
  405. if (data.uuid === this.uuid) {
  406. this.resetRecord();
  407. }
  408. },
  409. // 处理电子签名确认回调事件
  410. handleEditSignCallback(data) {
  411. if (data.uuid === this.uuid) {
  412. this.onEditSignSave(data.data);
  413. }
  414. },
  415. onEditSignSave(data) {
  416. this.handleUpdateRecord(data)
  417. },
  418. getChecked() {
  419. return !!this.getFieldCheckObj()[this.fieldKey]?.checked;
  420. },
  421. getFillTypeStyle(type) {
  422. const { fillType } = this.item;
  423. const typeObj = {
  424. actFill: "orange-border",//实际填写的边框颜色
  425. green: "green-border",
  426. preFill: "blue-border",//预填写的边框颜色
  427. }
  428. // 如果有错误状态,返回红色边框样式,覆盖原有的边框颜色
  429. if (this.error) {
  430. return "error-border";
  431. }
  432. return typeObj[fillType] || ""
  433. },
  434. //确认回复
  435. onReplyConfirm() {
  436. if (!this.replyContent) {
  437. this.$message({
  438. message: '请输入内容',
  439. type: 'error'
  440. });
  441. return;
  442. }
  443. const baseInfo = this.getCommonRecordInfo();
  444. const record = {
  445. ...baseInfo,
  446. title: this.templateFillType == 'actFill' ? "回复意见" : "复核意见",
  447. time: moment().format("YYYY-MM-DD HH:mm:ss"),
  448. }
  449. if (this.templateFillType == 'actFill') {
  450. record.reply = this.replyContent;
  451. const deepList = deepClone(this.getFhyjjl());//实际填报应该是修改指定的字段
  452. const item = deepList.find(o => o.key == record.key);
  453. if (item) {
  454. item.reply = this.replyContent;
  455. }
  456. this.replaceFhyjjl(deepList);//实际填报应该是修改指定的字段
  457. } else {
  458. const records = this.getReplyRecords();
  459. record.content = this.replyContent;
  460. if (records.length > 0) {
  461. const o = records[0];
  462. if (o.reply && o.content) {//如果填报人员已回复,那么就产生一条新的记录。
  463. this.updateFhyjjl(record);//qc直接插入数据源
  464. } else {//如果填报人员未填报,只更新当条记录的复核内容
  465. const deepList = deepClone(this.getFhyjjl());
  466. const item = deepList.find(it => it.key == record.key);
  467. if (item) {
  468. item.content = this.replyContent;
  469. }
  470. this.replaceFhyjjl(deepList);
  471. }
  472. } else {
  473. this.updateFhyjjl(record);//qc直接插入数据源
  474. }
  475. }
  476. const params = {
  477. //reply:回复,content:复核
  478. type: this.templateFillType == 'actFill' ? "reply" : "content",
  479. newRecord: [record],
  480. resourceList: this.getFhyjjl(),
  481. }
  482. // 触发回复记录事件
  483. EventBus.$emit('onModifyRecord', params);
  484. // 清空回复内容
  485. this.replyContent = '';
  486. // 隐藏弹窗
  487. this.visible = false;
  488. },
  489. //获取question图标颜色
  490. getQuestionColor() {
  491. const records = this.getReplyRecords();
  492. if (records.length > 0) {
  493. const o = records[0];
  494. if (o.reply && o.content) {//有回复意见和复核意见
  495. return "green"
  496. } else if (o.content && !o.reply) {//只有复核意见
  497. return "orange"
  498. } else {
  499. return "gray"
  500. }
  501. } else {//没有回复记录
  502. return "gray"
  503. }
  504. },
  505. // 复选框变化处理
  506. onCheckboxChange(val) {
  507. //有提出意见就不能勾选
  508. if (this.templateFillType == 'qc' && this.getQuestionColor() === "orange") {
  509. this.checkboxValue = false;
  510. this.$message({
  511. message: '该表单还有质疑项未处理,无法勾选',
  512. type: 'error'
  513. });
  514. return;
  515. }
  516. this.checkboxValue = val;
  517. // 触发修改记录事件
  518. EventBus.$emit('onModifyRecord', {
  519. type: "checkbox",
  520. fieldCheckObj: JSON.stringify({ ...this.getFieldCheckObj(), [this.fieldKey]: { checked: val } }),//复选框状态对象
  521. });
  522. this.updateFieldCheckObj({ [this.fieldKey]: { checked: val } });
  523. // this.$emit('input', val);
  524. // this.$emit('change', val);
  525. },
  526. onRemoveTag(e) {
  527. this.onCommonHandleSaveRecord(this.inputValue);
  528. },
  529. onItemCheckboxChange() {
  530. this.onCommonHandleSaveRecord(this.inputValue);
  531. },
  532. // 下拉框失去焦点处理
  533. onSelectBlur(visible) {
  534. if (!visible) {
  535. this.onCommonHandleSaveRecord(this.inputValue);
  536. }
  537. },
  538. // 统一处理输入变化
  539. onInputChange(val) {
  540. const value = val !== undefined ? val : this.inputValue;
  541. this.$emit('input', value);
  542. this.$emit('change', value);
  543. // 根据输入值判断是否显示错误状态
  544. const isEmpty = this.isValueEmpty(value);
  545. if (this.error && !isEmpty) {
  546. this.$emit('update:error', false);
  547. } else if (!this.error && isEmpty) {
  548. this.$emit('update:error', true);
  549. }
  550. },
  551. // 统一处理失去焦点事件
  552. onBlur(e) {
  553. this.onCommonHandleSaveRecord(e.target.value);
  554. },
  555. // 点击question图标
  556. onClickQuestion() {
  557. const { templateFillType } = this;
  558. if (templateFillType == 'actFill' || templateFillType == 'qc') {
  559. if (templateFillType == 'qc') {
  560. const field = this.getFieldCheckObj()[this.fieldKey];
  561. if (field && field.checked) {
  562. this.$message({
  563. message: '该字段已勾选复核框,请先取消勾选后再进行提交疑问',
  564. type: 'error'
  565. });
  566. return;
  567. }
  568. }
  569. const records = this.getReplyRecords();
  570. let content = "";
  571. if (records.length > 0) {
  572. const o = records[0];
  573. if (!o.reply && templateFillType == 'qc') {//如果填报人员没有回复,qc点击的时候需要回填上次填报的信息
  574. content = o.content;
  575. } else if (templateFillType == 'actFill') {//如果qc没有复核,填报点击的时候需要回填上次填报的信息
  576. content = o.reply;
  577. }
  578. }
  579. this.replyContent = content;
  580. this.visible = true;
  581. }
  582. },
  583. async onCommonHandleSaveRecord(val) {
  584. const isEmpty = this.isValueEmpty(this.inputValue);
  585. if (this.error && !isEmpty) {
  586. this.$emit('update:error', false);
  587. } else if (!this.error && isEmpty) {
  588. this.$emit('update:error', true);
  589. }
  590. if (!this.isFieldsRecord) {//是否需要记录修改记录
  591. this.$emit("blur", this.inputValue);
  592. this.$emit('input', this.inputValue);
  593. this.$emit("change", this.inputValue);
  594. return;
  595. }
  596. // 值发生了变化,需要弹出密码输入框
  597. const isSame = this.isEqual(this.oldValue, this.inputValue);
  598. if (isSame) {
  599. return;
  600. }
  601. if (!this.isValueEmpty(this.oldValue) && !isSame && this.templateFillType === "actFill") {
  602. // 通过EventBus触发电子签名弹窗
  603. EventBus.$emit('showEditSignDialog', { uuid: this.uuid });
  604. } else {//如果是第一次填写,不需要密码验证
  605. this.handleUpdateRecord()
  606. }
  607. },
  608. //如果用户取消,那么回退到上一次的值
  609. resetRecord() {
  610. // 用户点击取消,还原数据
  611. this.inputValue = this.oldValue;
  612. this.$emit('input', this.inputValue); // 触发 v-model 更新
  613. // this.$emit("blur", this.oldValue);
  614. this.$emit("change", this.oldValue, "cancel");
  615. if (this.item.type === "clickable") {
  616. this.$emit("resetRecord");
  617. }
  618. },
  619. //处理更新记录
  620. handleUpdateRecord(data) {
  621. const baseInfo = this.getCommonRecordInfo();
  622. if (!this.oldValue && !this.inputValue) return;
  623. const record = {
  624. ...baseInfo,
  625. oldValue: this.oldValue,
  626. value: this.inputValue,
  627. title: this.oldValue ? "修改" : "提交",
  628. time: moment().format("YYYY-MM-DD HH:mm:ss"),
  629. }
  630. if (data) {
  631. record.reason = data.remark
  632. }
  633. const params = {
  634. type: "fieldChanged",
  635. newRecord: [record],
  636. resourceList: this.getZdxgjl(),
  637. }
  638. //用户输入密码并点击确定,保存修改
  639. this.oldValue = this.inputValue; // 更新旧值
  640. this.$emit("blur", this.inputValue);
  641. this.$emit('input', this.inputValue);
  642. this.$emit("change", this.inputValue, data ? "save" : "");
  643. if (this.item.type === "clickable") {//clickable的丢给父级去处理
  644. return;
  645. }
  646. if (this.templateFillType === "actFill") {//只有实际填报的时候才记录修改记录
  647. this.updateZdxgjl(record);
  648. }
  649. this.$nextTick(()=>{
  650. EventBus.$emit('onModifyRecord', params,)
  651. if (this.regentType.includes(this.item.type)) {
  652. this.$emit("onRegentSubmit", this.selectRegentInfo);
  653. }
  654. })
  655. },
  656. //判断两个值是否相等
  657. isEqual(oldValue, nowValue) {
  658. if (oldValue === null || nowValue === null) {
  659. return oldValue === nowValue;
  660. }
  661. if (typeof oldValue === 'object' && typeof nowValue === 'object') {
  662. return JSON.stringify(oldValue) === JSON.stringify(nowValue);
  663. }
  664. return oldValue === nowValue;
  665. },
  666. //获取公共记录信息
  667. getCommonRecordInfo() {
  668. const { nickName, name } = this.$store.getters;
  669. //locale:zh-CN 中文 en-US 英文
  670. const { label, parentLabel } = this.item;
  671. let fieldLabelCn = this.$i18n.t(label, "zh_CN"), fieldLabelEn = this.$i18n.t(label, "en_US");
  672. if (label === "template.common.other") {
  673. fieldLabelCn = this.$i18n.t(parentLabel, "zh_CN") + this.$i18n.t("template.common.otherInfo", "zh_CN");
  674. fieldLabelEn = this.$i18n.t(parentLabel, "en_US") + this.$i18n.t("template.common.otherInfo", "en_US");
  675. } else if (!label && parentLabel == "template.common.remark") {
  676. fieldLabelCn = this.$i18n.t(parentLabel, "zh_CN") + this.$i18n.t("template.common.unit", "zh_CN");
  677. fieldLabelEn = this.$i18n.t(parentLabel, "en_US") + this.$i18n.t("template.common.unit", "en_US");
  678. }
  679. const commonInfo = {
  680. userNameCn: nickName,
  681. userNameEn: name,
  682. key: this.fieldKey,
  683. fieldCn: `${this.$i18n.t(this.fieldItemLabel, "zh_CN")}` + (fieldLabelCn ? ("-" + fieldLabelCn) : ""),
  684. fieldEn: `${this.$i18n.t(this.fieldItemLabel, "en_US")}` + (fieldLabelEn ? ("-" + fieldLabelEn) : ""),
  685. }
  686. return commonInfo;
  687. },
  688. // 判断值是否为空
  689. isValueEmpty(value) {
  690. if (value === null || value === undefined || value === '') {
  691. return true;
  692. }
  693. if (typeof value === 'string' && value.trim() === '') {
  694. return true;
  695. }
  696. if (Array.isArray(value) && value.length === 0) {
  697. return true;
  698. }
  699. return false;
  700. },
  701. handleClickable(item, event) {
  702. if (this.templateFillType !== 'actFill') {
  703. return
  704. }
  705. this.$emit("clickable", item)
  706. },
  707. //判断是否禁用复选框
  708. getCheckboxDisabled() {
  709. //只有qc能操作checkbox,其他都只能看。
  710. return this.templateFillType !== 'qc'
  711. },
  712. //判断是否显示复选框图标
  713. getIsShowCheckboxIcon() {
  714. if (this.templateFillType === 'qc') {
  715. return true;
  716. }
  717. return this.getChecked();
  718. },
  719. //判断是否显示复制按钮
  720. getIsShowCopyIcon() {
  721. const { copyFrom } = this.item;
  722. return copyFrom && this.templateFillType === "actFill";
  723. },
  724. //判断是否显示操作按钮
  725. isShowHandle() {
  726. const { fillType } = this.item;
  727. //只有当模板状态不是预填时,才显示操作按钮
  728. return this.templateFillType !== "preFill" && fillType === "actFill"
  729. },
  730. //判断是否禁用
  731. getDisabled() {
  732. const { item } = this;
  733. const { fillType } = item;
  734. if (item.hasOwnProperty("disabled")) {
  735. return item.disabled
  736. } else {
  737. if (fillType === "actFill") {//当模板状态是实际填写时,只有当fillType是actFill时才能填写
  738. return this.templateFillType !== "actFill"
  739. } else if (fillType === "preFill") {//当模板状态是预填写时,只有当fillType是preFill才能填写
  740. return this.templateFillType !== "preFill"
  741. } else {
  742. return true
  743. }
  744. }
  745. },
  746. getPlaceholder() {
  747. const { placeholder, label } = this.item;
  748. const { type } = this;
  749. if (this.getDisabled()) {
  750. return ""
  751. }
  752. if (this.regentType.includes(type) || type === "clickable") {
  753. return this.$t("template.common.pleaseSelect")
  754. }
  755. let prex = "template.common.pleaseFillIn"
  756. if (type === "select" || type === "dateTime") {
  757. prex = "template.common.pleaseSelect"
  758. }
  759. return placeholder ? this.$t(placeholder) : (this.$t(prex) + this.$t(label))
  760. },
  761. async onCopy() {
  762. // 触发复制事件
  763. this.$emit("copy");
  764. // 等待复制操作完成后,调用保存记录方法
  765. this.$nextTick(async () => {
  766. await this.onCommonHandleSaveRecord(this.inputValue);
  767. });
  768. },
  769. //判断是否显示问题图标
  770. getIsShowQuestionIcon() {
  771. if (this.templateFillType === "qc") {//qc可以直接查看
  772. return true;
  773. }
  774. return this.getReplyRecords().length > 0;
  775. },
  776. //判断是否显示修改记录图标
  777. getIsShowRecordIcon() {
  778. return this.getModifyRecords().length > 0
  779. },
  780. //获取回复记录
  781. getReplyRecords() {
  782. const { fieldKey, getFhyjjl } = this;
  783. const records = getFhyjjl()?.filter(item => item.key === fieldKey) || [];
  784. return records;
  785. },
  786. //获取字段修改记录
  787. getModifyRecords() {
  788. const { fieldKey, getZdxgjl } = this;
  789. const records = getZdxgjl().filter(item => item.key === fieldKey);
  790. return records;
  791. },
  792. // 鼠标进入主容器
  793. async onMouseEnter(type, event) {
  794. this.currentRecordType = type;
  795. clearTimeout(this.modalTimer);
  796. let record = [];
  797. if (type === "fieldChanged") {
  798. record = this.getModifyRecords();
  799. } else if (type === "replyRecord") {
  800. record = this.getReplyRecords();
  801. }
  802. this.modificationRecords = record;
  803. // 先计算模态框位置,避免闪烁
  804. this.showModal = true;
  805. this.$nextTick(() => {
  806. if (this.$refs.modalRef) {
  807. const elementRect = event.target.getBoundingClientRect();
  808. const modalEl = this.$refs.modalRef;
  809. // 获取模态框的宽度和高度
  810. const modalWidth = modalEl.offsetWidth || 250; // 默认宽度
  811. const modalHeight = modalEl.offsetHeight || 300; // 默认高度
  812. const viewportWidth = window.innerWidth;
  813. const viewportHeight = window.innerHeight;
  814. // 计算模态框位置
  815. let leftPos, topPos;
  816. // 检查右侧空间是否足够
  817. if (elementRect.right + modalWidth + 5 <= viewportWidth) {
  818. // 右侧空间充足,显示在右侧
  819. leftPos = elementRect.right + 5 + 'px';
  820. } else if (elementRect.left - modalWidth - 5 >= 0) {
  821. // 左侧空间充足,显示在左侧
  822. leftPos = elementRect.left - modalWidth - 5 + 'px';
  823. } else {
  824. // 两侧空间都不足,选择空间更大的一边
  825. if (elementRect.left > viewportWidth - elementRect.right) {
  826. // 左侧空间更大,显示在左侧
  827. leftPos = Math.max(5, elementRect.left - modalWidth - 5) + 'px';
  828. } else {
  829. // 右侧空间更大,显示在右侧(可能会超出屏幕,但尽量靠近边缘)
  830. leftPos = Math.min(elementRect.right + 5, viewportWidth - 5) + 'px';
  831. }
  832. }
  833. // 计算顶部位置,确保不超出屏幕上下边界
  834. topPos = Math.max(5, Math.min(elementRect.top, viewportHeight - modalHeight - 5)) + 'px';
  835. // 设置模态框位置
  836. modalEl.style.left = leftPos;
  837. modalEl.style.top = topPos;
  838. }
  839. });
  840. },
  841. // 鼠标离开主容器
  842. onMouseLeave() {
  843. // this.currentRecordType = '';
  844. // this.modificationRecords = [];//清空数据源
  845. // 延迟隐藏模态框,让用户有机会移动到模态框上
  846. this.modalTimer = setTimeout(() => {
  847. if (!this.isHoveringModal) {
  848. this.showModal = false;
  849. }
  850. }, 100);
  851. },
  852. // 鼠标进入模态框
  853. onModalEnter() {
  854. this.isHoveringModal = true;
  855. clearTimeout(this.modalTimer);
  856. },
  857. // 鼠标离开模态框
  858. onModalLeave() {
  859. this.isHoveringModal = false;
  860. this.currentRecordType = "";
  861. this.modificationRecords = [];//清空数据源
  862. this.modalTimer = setTimeout(() => {
  863. this.showModal = false;
  864. }, 100);
  865. },
  866. },
  867. }
  868. </script>
  869. <style lang="scss">
  870. .flex {
  871. display: flex;
  872. align-items: center;
  873. }
  874. .flex1 {
  875. flex: 1;
  876. }
  877. .handle-row {
  878. margin-left: 5px;
  879. display: flex;
  880. align-items: center;
  881. cursor: pointer;
  882. }
  883. .w-100 {
  884. width: 100%;
  885. }
  886. .handle-icon {
  887. width: 18px;
  888. height: 18px;
  889. &:not(:last-child) {
  890. margin-right: 5px;
  891. }
  892. }
  893. .mr-5 {
  894. margin-right: 5px !important;
  895. }
  896. .orange {
  897. color: #f9c588;
  898. }
  899. .green {
  900. color: green;
  901. }
  902. .gray {
  903. color: #b2b2b2;
  904. }
  905. .orange-border {
  906. .el-input-group__prepend,
  907. input,
  908. textarea {
  909. border-color: #f9c588;
  910. &:focus {
  911. border-color: #f9c588;
  912. }
  913. &:hover {
  914. border-color: #f9c588;
  915. }
  916. &:disabled {
  917. border-color: #f9c588 !important;
  918. }
  919. }
  920. .el-checkbox__inner {
  921. border-color: #f9c588 !important;
  922. }
  923. }
  924. .el-button--primary {
  925. &.orange-border {
  926. background-color: #f79b31 !important;
  927. border-color: #f79b31 !important;
  928. &:hover {
  929. background-color: #f79b31 !important;
  930. }
  931. &:disabled {
  932. background-color: rgba(#f79b31, .8) !important;
  933. border-color: rgba(#f79b31, .8) !important;
  934. }
  935. &:active {
  936. background-color: rgba(#f79b31, .8) !important;
  937. border-color: rgba(#f79b31, .8) !important;
  938. }
  939. }
  940. &.blue-border {
  941. background-color: #4ea2ff !important;
  942. border-color: #4ea2ff !important;
  943. &:hover {
  944. background-color: #4ea2ff !important;
  945. }
  946. &:disabled {
  947. background-color: rgba(#4ea2ff, .8) !important;
  948. border-color: rgba(#4ea2ff, .8) !important;
  949. }
  950. &:active {
  951. background-color: rgba(#4ea2ff, .8) !important;
  952. border-color: rgba(#4ea2ff, .8) !important;
  953. }
  954. }
  955. }
  956. .green-border {
  957. .el-input-group__prepend,
  958. input,
  959. textarea {
  960. border-color: green;
  961. &:focus {
  962. border-color: green;
  963. }
  964. &:hover {
  965. border-color: green;
  966. }
  967. &:disabled {
  968. border-color: green !important;
  969. }
  970. }
  971. }
  972. .blue-border {
  973. .el-input-group__prepend,
  974. input,
  975. .el-checkbox__inner,
  976. textarea {
  977. border-color: #4ea2ff;
  978. &:focus {
  979. border-color: #4ea2ff;
  980. }
  981. &:hover {
  982. border-color: #4ea2ff;
  983. }
  984. &:disabled {
  985. border-color: #4ea2ff !important;
  986. }
  987. }
  988. }
  989. .error-border {
  990. .el-input-group__prepend,
  991. input,
  992. textarea,
  993. .el-select,
  994. .clickable,
  995. .el-date-editor {
  996. border-color: #ff5d5d;
  997. box-shadow: 0 0 6px #ffc3c3 !important;
  998. &:focus {
  999. border-color: #ff5d5d;
  1000. box-shadow: 0 0 6px #ffc3c3 !important;
  1001. }
  1002. &:hover {
  1003. border-color: #ff5d5d;
  1004. box-shadow: 0 0 6px #ffc3c3 !important;
  1005. }
  1006. }
  1007. // 为 el-select 和 el-date-picker 添加错误边框样式
  1008. .el-select .el-input__inner,
  1009. .el-date-editor .el-input__inner .el-checkbox__inner {
  1010. border-color: #ff5d5d;
  1011. box-shadow: 0 0 6px #ffc3c3 !important;
  1012. }
  1013. // 处理 DecimalInput 组件的错误边框样式
  1014. :deep(.el-input-number) {
  1015. .el-input__inner {
  1016. border-color: #ff5d5d;
  1017. box-shadow: 0 0 6px #ffc3c3 !important;
  1018. }
  1019. }
  1020. // 为点击式表单项添加错误边框样式
  1021. .clickable {
  1022. border-color: #ff5d5d;
  1023. box-shadow: 0 0 6px #ffc3c3 !important;
  1024. }
  1025. }
  1026. .orange-bg {
  1027. background-color: #FFF1F1 !important; // 橙色背景,透明度适中
  1028. input,
  1029. textarea,
  1030. .el-input__inner,
  1031. .el-textarea__inner {
  1032. background-color: #FFF1F1 !important;
  1033. }
  1034. }
  1035. .modification-modal {
  1036. position: fixed;
  1037. z-index: 9999;
  1038. background-color: rgba(0, 0, 0, 0.7);
  1039. border-radius: 4px;
  1040. padding: 10px;
  1041. color: white;
  1042. max-height: 300px;
  1043. min-width: 250px;
  1044. overflow: hidden;
  1045. pointer-events: auto;
  1046. opacity: 0;
  1047. transform: scale(0.9);
  1048. transition: opacity 0.2s ease, transform 0.2s ease;
  1049. }
  1050. .modification-modal.show {
  1051. opacity: 1;
  1052. transform: scale(1);
  1053. }
  1054. .modification-modal .modal-content {
  1055. max-height: 280px;
  1056. overflow-y: auto;
  1057. padding-right: 5px;
  1058. }
  1059. .modification-modal .modal-content h4 {
  1060. margin: 0 0 10px 0;
  1061. font-size: 14px;
  1062. border-bottom: 1px solid #ccc;
  1063. padding-bottom: 5px;
  1064. }
  1065. .modification-modal .records-list {
  1066. font-size: 12px;
  1067. }
  1068. .modification-modal .record-item p {
  1069. margin: 5px 0;
  1070. word-break: break-all;
  1071. }
  1072. .modification-modal .record-item hr {
  1073. border: 0;
  1074. border-top: 1px solid #555;
  1075. margin: 8px 0;
  1076. }
  1077. .modification-modal .no-records {
  1078. text-align: center;
  1079. color: #aaa;
  1080. font-style: italic;
  1081. }
  1082. .clickable {
  1083. cursor: pointer;
  1084. width: auto;
  1085. // margin-left: 10px;
  1086. min-height: 28px;
  1087. line-height: 28px;
  1088. word-break: break-all;
  1089. border-radius: 4px;
  1090. border: 1px solid #4ea2ff;
  1091. display: flex;
  1092. align-items: center;
  1093. padding: 0 15px;
  1094. font-size: 14px;
  1095. font-weight: normal;
  1096. color: #606266;
  1097. flex: 1;
  1098. &.disabled {
  1099. cursor: not-allowed;
  1100. color: #c0c4cc;
  1101. background-color: #f5f7fa;
  1102. }
  1103. &.error-border {
  1104. border-color: #ff5d5d !important;
  1105. box-shadow: 0 0 6px #ffc3c3 !important;
  1106. }
  1107. }
  1108. .dialog-footer {
  1109. display: flex;
  1110. justify-content: flex-end;
  1111. }
  1112. </style>