华西海圻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.

1734 lines
65 KiB

  1. <template>
  2. <div class="flex " :class="getFlexClass()">
  3. <div class="flex" :class="getFlexClass()">
  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="getDecimalDigits()" :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-radio-group v-else-if="type === 'radio'" v-model="inputValue"
  28. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" :disabled="getDisabled()"
  29. @change="onItemCheckboxChange">
  30. <el-radio v-for="option in item.options" :key="option.value" :label="option.value"
  31. :disabled="getDisabled()">
  32. {{ option.label }}
  33. </el-radio>
  34. </el-radio-group>
  35. <div v-else-if="type === 'checkboxList'" class="flex1 checkbox-list-container"
  36. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')">
  37. <el-checkbox-group v-model="inputValue" @change="onInputChange">
  38. <div v-for="option in item.options" :key="option.value" class="checkbox-item">
  39. <el-checkbox :label="option.value" :disabled="getDisabled()">
  40. {{ option.label }}
  41. </el-checkbox>
  42. <div v-if="option.otherCode && inputValue.includes(option.value)">
  43. <el-input v-model="otherValues[option.otherCode]"
  44. :placeholder="option.otherPlaceholder || '请输入'"
  45. :class="{ 'error-border': isOtherInputError(option.otherCode) }" @blur="onBlur"
  46. @input="onOtherInputChange(option.otherCode, $event)" />
  47. </div>
  48. </div>
  49. </el-checkbox-group>
  50. </div>
  51. <el-date-picker v-else-if="type === 'dateTime'" type="datetime" class="flex1"
  52. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" v-model="inputValue"
  53. :disabled="getDisabled()" format="yyyy/MM/dd HH:mm:ss" :placeholder="getPlaceholder()"
  54. @change="(val) => onDateChange(val, 'yyyy/MM/DD HH:mm:ss')">
  55. </el-date-picker>
  56. <el-date-picker v-else-if="type === 'datePicker'" class="flex1"
  57. :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')" v-model="inputValue"
  58. :disabled="getDisabled()" format="yyyy/MM/dd" :placeholder="getPlaceholder()"
  59. @change="(val) => onDateChange(val, 'yyyy/MM/DD')">
  60. </el-date-picker>
  61. <el-button v-else-if="type === 'button'" :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')"
  62. :disabled="getDisabled()" type="primary" @click="handleClickButton(item)">
  63. {{ $t(item.buttonName) }}
  64. <input type="hidden" v-model="inputValue">
  65. </el-button>
  66. <div class="clickable"
  67. :class="getFillTypeStyle() + (getDisabled() ? ' disabled' : '') + (orangeBg ? ' orange-bg' : '')"
  68. v-else-if="item.type === 'clickable'" @click="handleClickable(item, $event)">
  69. <span v-if="inputValue">{{ inputValue }}</span>
  70. <span v-else class="default-placeholder-text">{{ getPlaceholder() }}</span>
  71. </div>
  72. <div class="clickable"
  73. :class="getFillTypeStyle() + (getDisabled() ? ' disabled' : '') + (orangeBg ? ' orange-bg' : '')"
  74. v-else-if="regentType.includes(item.type)" @click="onCommonHandleRegent(item, item.type)">
  75. <span v-if="inputValue">{{ inputValue }}</span>
  76. <span v-else class="default-placeholder-text">{{ getPlaceholder() }}</span>
  77. </div>
  78. <template v-else-if="type === 'attachment'">
  79. <el-upload ref="uploadRef" class="upload-demo" :action="uploadFileUrl" :on-preview="handlePreview"
  80. :headers="headers" :before-remove="beforeRemove" :on-remove="handleRemove" multiple :limit="10"
  81. :on-success="handleSuccess" :on-change="handleChange" :on-exceed="handleExceed"
  82. :file-list="fileList" :auto-upload="false">
  83. <el-button :disabled="getDisabled()" :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')"
  84. size="small" type="primary">点击上传</el-button>
  85. <span v-if="error" class="atta-tips">请上传附件</span>
  86. <div slot="tip" class="el-upload__tip">支持扩展名.rar .zip .doc .docx .pdf .jpg文件大小不超过2MB</div>
  87. </el-upload>
  88. </template>
  89. <div v-else-if="type === 'checkboxTag'" class="flex1 checkbox-tag-wrapper" :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')">
  90. <div v-for="(tag, tagIndex) in checkboxTagList" :key="tagIndex" class="checkbox-tag-container">
  91. <div class="checkbox-tag-item">
  92. <el-checkbox v-model="tag.checked" :disabled="getDisabled()"
  93. @change="onCheckboxTagChange(tagIndex, $event)"></el-checkbox>
  94. <div class="tag-content blue-border">
  95. <el-input v-if="templateFillType === 'preFill'" v-model="tag.tagValue"
  96. :ref="'tagInput_' + tagIndex" :maxlength="item.maxlength || 20"
  97. @blur="onTagBlur(tagIndex)" @keyup.enter.native="onTagBlur(tagIndex)"
  98. placeholder="请输入" size="mini" class="tag-input" />
  99. <el-tag v-else :type="'info'" class="tag-display" :closable="false">
  100. {{ tag.tagValue }}
  101. </el-tag>
  102. <el-popconfirm confirm-button-text='确认' cancel-button-text='取消' icon="el-icon-info"
  103. icon-color="red" title="确认删除当前编号?" @confirm="onDeleteTag(tagIndex)">
  104. <i slot="reference" v-if="templateFillType === 'preFill'"
  105. class="el-icon-close delete-icon"></i>
  106. </el-popconfirm>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="handle-row" v-if="isShowHandle()">
  113. <el-checkbox v-model="checkboxValue" v-if="getIsShowCheckboxIcon()" :disabled="getCheckboxDisabled()"
  114. class="mr-5" @change="onCheckboxChange"></el-checkbox>
  115. <div class="handle-icon" v-if="getIsShowQuestionIcon()" @click="onClickQuestion"
  116. @mouseenter="(e) => onMouseEnter('replyRecord', e)" @mouseleave="onMouseLeave">
  117. <Question :class="getQuestionColor()" />
  118. </div>
  119. <img v-if="getIsShowCopyIcon()" @click="onCopy" src="@/assets/images/copy-icon.svg" class="handle-icon"
  120. alt="" />
  121. <img v-if="getIsShowRecordIcon()" @mouseenter="(e) => onMouseEnter('fieldChanged', e)"
  122. @mouseleave="onMouseLeave" src="@/assets/images/record-icon.svg" class="handle-icon" alt="" />
  123. </div>
  124. <!-- 修改记录模态框 -->
  125. <div v-if="showModal && modificationRecords.length > 0" ref="modalRef"
  126. :class="['modification-modal', { 'show': showModal }]" @mouseenter="onModalEnter"
  127. @mouseleave="onModalLeave">
  128. <div class="modal-content">
  129. <div class="records-list">
  130. <div v-for="(record, index) in modificationRecords" :key="index" class="record-item">
  131. <!-- 字段修改记录 -->
  132. <div class="record-row" v-if="currentRecordType === 'fieldChanged'">
  133. <div>
  134. <span>{{ index + 1 }}.</span>
  135. <span> {{ getUserName(record) }} </span>
  136. <span>{{ record.time }} </span>
  137. <span>{{ modificationRecords.length - 1 == index ? "提交" : "修改" }}</span>
  138. </div>
  139. <div v-if="modificationRecords.length - 1 !== index">
  140. <div>原值{{ record.oldValue }}</div>
  141. <div>修改值{{ record.value }}</div>
  142. <div v-if="record.reason">备注{{ record.reason }}</div>
  143. </div>
  144. </div>
  145. <!-- 回复记录 -->
  146. <div class="record-row" v-if="currentRecordType === 'replyRecord'">
  147. <div>
  148. <span> {{ getUserName(record) }} </span>
  149. <span>{{ record.time }} </span>
  150. </div>
  151. <div>
  152. <div v-if="record.content">复核意见{{ record.content }}</div>
  153. <div v-if="record.reply">回复意见{{ record.reply }}</div>
  154. </div>
  155. </div>
  156. <hr v-if="index < modificationRecords.length - 1">
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. <el-dialog :close-on-click-modal="false" append-to-body :title="templateFillType == 'actFill' ? '回复意见' : '复核意见'"
  162. :visible.sync="visible" width="30%">
  163. <el-input v-model="replyContent" type="textarea" show-word-limit resize="none" rows="8" placeholder="输入内容"
  164. maxlength="500" />
  165. <span slot="footer" class="dialog-footer">
  166. <el-button @click="visible = false"> </el-button>
  167. <el-button type="primary" @click="onReplyConfirm"> </el-button>
  168. </span>
  169. </el-dialog>
  170. </div>
  171. </template>
  172. <script>
  173. import Question from "./icons/Question.vue";
  174. import DecimalInput from "./DecimalInput.vue";
  175. import { EventBus } from "@/utils/eventBus";
  176. import moment from "moment";
  177. import { deepClone } from "@/utils/index";
  178. import { getuuid } from "@/utils/index.js";
  179. import { getToken } from "@/utils/auth"
  180. export default {
  181. inject: ['templateData', 'templateFillType', "getZdxgjl", "getFhyjjl", "updateZdxgjl", "replaceFhyjjl", "updateFhyjjl", "getFieldCheckObj", "updateFieldCheckObj"],
  182. components: {
  183. Question,
  184. DecimalInput,
  185. },
  186. props: {
  187. type: {//form类型 input/select等
  188. type: String,
  189. default: "input"
  190. },
  191. item: {
  192. type: Object,
  193. default: () => {
  194. return {
  195. placeholder: "",
  196. maxlength: 30,
  197. label: "",
  198. disabled: false,
  199. }
  200. }
  201. },
  202. // v-model 值
  203. value: {
  204. type: [String, Number, Array, Boolean, Object],
  205. default: ''
  206. },
  207. // 错误状态
  208. error: {
  209. type: Boolean,
  210. default: false
  211. },
  212. // 橙色背景状态
  213. orangeBg: {
  214. type: Boolean,
  215. default: false
  216. },
  217. fieldKey: {
  218. type: String,
  219. default: ""
  220. },
  221. fieldItemLabel: {
  222. type: String,
  223. default: "",
  224. },
  225. //是否记录修改
  226. isFieldsRecord: {
  227. type: Boolean,
  228. default: true,
  229. },
  230. sourceFrom: {
  231. type: String,
  232. default: ""
  233. },
  234. },
  235. data() {
  236. let initialValue = this.value;
  237. let initialOtherValues = {}, checkboxTagList = [];
  238. // 如果是checkboxList类型且value是对象格式
  239. if (this.type === 'checkboxList' && this.value && typeof this.value === 'object') {
  240. initialValue = this.value.checkboxValues || [];
  241. initialOtherValues = this.value.otherValues || {};
  242. } else if (this.type === 'checkboxList' && !Array.isArray(this.value)) {
  243. initialValue = [];
  244. } else if (this.type === 'checkboxTag' && Array.isArray(this.value)) {
  245. // checkboxTag类型,value是数组格式
  246. checkboxTagList = this.value.map(tag => ({
  247. checked: tag.checked,
  248. tagValue: tag.tagValue || ''
  249. }));
  250. }
  251. return {
  252. inputValue: initialValue,
  253. oldValue: initialValue, // 记录上一次的值
  254. otherValues: initialOtherValues, // 存储checkboxList中otherCode对应的输入值
  255. oldOtherValues: { ...initialOtherValues }, // 记录上一次的otherValues
  256. showModal: false, // 控制模态框显示
  257. modificationRecords: [], // 存储修改记录
  258. modalTimer: null, // 用于延迟隐藏模态框
  259. isHoveringModal: false, // 是否悬停在模态框上
  260. isHoveringMain: false, // 是否悬停在主元素上(这个实际上不需要,因为我们有事件处理)
  261. currentRecordType: '', // 当前悬停的记录类型(replyRecord 或 modifyRecord)
  262. replyContent: '', // 回复内容
  263. visible: false,//是否显示弹窗
  264. checkboxValue: this.getChecked(),//是否选中
  265. checkboxTagList: checkboxTagList, // checkboxTag类型的列表数据
  266. oldCheckboxTagList: JSON.parse(JSON.stringify(checkboxTagList)), // 记录上一次的checkboxTagList
  267. uuid: getuuid(), // 唯一标识符,用于EventBus事件匹配
  268. regentType: ['sj', 'gsp', 'mix', 'xj', 'xb', 'gyzj', 'mjy', 'yq', 'jcb', 'qxbd'], //试剂/仪器/供试品等类型
  269. selectRegentInfo: {},//选择的试剂/仪器/供试品等信息
  270. fileList: [],//上传的文件列表
  271. uploadFileUrl: process.env.VUE_APP_BASE_API + "/file/upload",
  272. headers: {
  273. Authorization: "Bearer " + getToken(),
  274. },
  275. pendingUploadFile: null, // 用于存储待上传的文件
  276. pendingRemoveFile: null, // 用于存储待删除的文件
  277. currentTagIndex:-1,//当前选中的checkboxTag索引
  278. }
  279. },
  280. watch: {
  281. value(newVal) {
  282. console.log(newVal, "newVal")
  283. if (this.type === 'checkboxList' && newVal && typeof newVal === 'object') {
  284. this.inputValue = newVal.checkboxValues || [];
  285. this.otherValues = newVal.otherValues || {};
  286. } else if (this.type === 'checkboxTag' && Array.isArray(newVal)) {
  287. // checkboxTag类型,value是数组格式
  288. this.checkboxTagList = newVal.map(tag => ({
  289. checked: tag.checked,
  290. tagValue: tag.tagValue || ''
  291. }));
  292. } else {
  293. this.inputValue = this.type === 'checkboxList' && !Array.isArray(newVal) ? [] : newVal;
  294. }
  295. }
  296. },
  297. filters: {
  298. },
  299. mounted() {
  300. if (this.item.type === 'attachment') {
  301. try {
  302. this.fileList = JSON.parse(this.value);
  303. } catch (e) {
  304. this.fileList = [];
  305. }
  306. }
  307. EventBus.$on('onExternalFieldUpdate', this.handleExternalFieldUpdate);
  308. EventBus.$on('onEditSignCancel', this.handleEditSignCancel);
  309. EventBus.$on('onEditSignCallback', this.handleEditSignCallback);
  310. //试剂
  311. EventBus.$on("onReagentSubmit", this.onReagentSubmit)
  312. //仪器
  313. EventBus.$on("onInstrumentSubmit", this.onMixReagentSubmit)
  314. //供试品/试剂/给药制剂等
  315. EventBus.$on("onMixReagentSubmit", this.onMixReagentSubmit)
  316. },
  317. unmounted() {
  318. EventBus.$off('onExternalFieldUpdate', this.handleExternalFieldUpdate);
  319. EventBus.$off('onEditSignCancel', this.handleEditSignCancel);
  320. EventBus.$off('onEditSignCallback', this.handleEditSignCallback);
  321. EventBus.$off("onReagentSubmit", this.onReagentSubmit)
  322. EventBus.$off("onInstrumentSubmit", this.onMixReagentSubmit)
  323. EventBus.$off("onMixReagentSubmit", this.onMixReagentSubmit)
  324. },
  325. methods: {
  326. getFlexClass() {
  327. const noFlexArr = ["radio", "checkboxTag"]
  328. return noFlexArr.includes(this.type) ? '' : 'flex1'
  329. },
  330. getDecimalDigits() {
  331. const { precision } = this.item;
  332. if (!isNaN(precision)) {
  333. return precision
  334. }
  335. return 6
  336. },
  337. onInstrumentSubmit(data) {
  338. if (data.uuid !== this.uuid) return;
  339. this.selectRegentInfo = data;
  340. },
  341. // 文件状态改变时的钩子,添加文件、上传成功、上传失败时都会被调用
  342. handleChange(file, fileList) {
  343. // 如果是新添加的文件(status为ready),进行验证
  344. if (file.status === 'ready') {
  345. const isAllowedType = ['image/jpeg', 'image/png', 'image/gif', 'application/pdf',
  346. 'application/x-rar-compressed', 'application/zip',
  347. 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'].includes(file.raw.type)
  348. const isLt2M = file.size / 1024 / 1024 < 2
  349. if (!isAllowedType) {
  350. this.$message.error(`文件 ${file.name} 格式不支持!只能上传 JPG/PNG/GIF/PDF/RAR/ZIP/DOC/DOCX 格式的文件`)
  351. // 从fileList中移除该文件
  352. const index = fileList.indexOf(file);
  353. if (index > -1) {
  354. fileList.splice(index, 1);
  355. }
  356. this.fileList = [...fileList];
  357. return
  358. }
  359. if (!isLt2M) {
  360. this.$message.error(`文件 ${file.name} 大小超过2MB!`)
  361. // 从fileList中移除该文件
  362. const index = fileList.indexOf(file);
  363. if (index > -1) {
  364. fileList.splice(index, 1);
  365. }
  366. this.fileList = [...fileList];
  367. return
  368. }
  369. // 如果已经有文件在列表中(不包括当前新添加的),需要验证电子签名
  370. const existingFiles = fileList.filter(f => f !== file && f.status === 'success');
  371. if (existingFiles.length > 0) {
  372. // 保存待上传的文件信息
  373. this.pendingUploadFile = file;
  374. // 从fileList中暂时移除新文件,等待签名验证
  375. const index = fileList.indexOf(file);
  376. if (index > -1) {
  377. fileList.splice(index, 1);
  378. }
  379. this.fileList = [...fileList];
  380. // 触发电子签名弹窗
  381. EventBus.$emit('showEditSignDialog', { uuid: this.uuid });
  382. return;
  383. }
  384. // 没有现有文件或验证通过,手动提交上传
  385. this.$nextTick(() => {
  386. // 找到对应的upload组件并提交
  387. const uploadComponent = this.$refs.uploadRef;
  388. if (uploadComponent) {
  389. uploadComponent.submit();
  390. }
  391. });
  392. }
  393. // 更新fileList
  394. this.fileList = fileList;
  395. },
  396. handleSuccess(res, file, fileList) {
  397. if (res.code == 200) {
  398. this.fileList = fileList;
  399. // 更新inputValue为文件路径列表,方便后续保存
  400. this.inputValue = JSON.stringify(this.getFileList(fileList));
  401. this.$emit("change", this.inputValue)
  402. this.onCommonHandleSaveRecord();
  403. this.$message.success('文件上传成功');
  404. } else {
  405. this.$message.error(res.message || '文件上传失败');
  406. // 上传失败,从列表中移除
  407. const index = fileList.indexOf(file);
  408. if (index > -1) {
  409. fileList.splice(index, 1);
  410. this.fileList = [...fileList];
  411. }
  412. }
  413. },
  414. getFileList(fileList) {
  415. const list = [];
  416. fileList.forEach(item => {
  417. const o = { name: item.name };
  418. if (item.url) {//回填的数据
  419. o.url = item.url
  420. } else {//新上传的
  421. o.url = item.response.data.url
  422. }
  423. list.push(o)
  424. })
  425. return list;
  426. },
  427. // 删除前验证电子签名
  428. beforeRemove(file) {
  429. // 所有删除操作都需要验证电子签名
  430. // 保存待删除的文件信息
  431. this.pendingRemoveFile = { file, fileList: this.fileList };
  432. // 触发电子签名弹窗
  433. EventBus.$emit('showEditSignDialog', { uuid: this.uuid });
  434. // 返回false阻止默认删除行为,等待签名验证通过后再删除
  435. return false;
  436. },
  437. handleRemove(file, fileList) {
  438. // on-remove事件在before-remove返回false时不会触发
  439. // 这个方法在签名验证通过后通过executeRemove调用
  440. // 这里不需要额外处理,因为executeRemove已经处理了删除逻辑
  441. },
  442. // 执行实际的文件删除操作
  443. executeRemove(file, fileList) {
  444. // 从el-upload的内部uploadFiles中移除文件
  445. const uploadComponent = this.$refs.uploadRef;
  446. if (uploadComponent && uploadComponent.uploadFiles) {
  447. const uploadFileIndex = uploadComponent.uploadFiles.indexOf(file);
  448. if (uploadFileIndex > -1) {
  449. uploadComponent.uploadFiles.splice(uploadFileIndex, 1);
  450. }
  451. }
  452. // 从fileList中移除文件
  453. const index = fileList.indexOf(file);
  454. if (index > -1) {
  455. fileList.splice(index, 1);
  456. }
  457. // 更新fileList
  458. this.fileList = [...fileList];
  459. // 更新inputValue为剩余文件路径列表
  460. this.inputValue = JSON.stringify(this.getFileList(fileList));
  461. this.$emit("change", this.inputValue);
  462. // 触发保存记录
  463. this.onCommonHandleSaveRecord();
  464. this.$message.success(`文件 ${file.name} 已移除`);
  465. },
  466. handlePreview(file) {
  467. console.log(file)
  468. const url = file.url || file.response?.data?.url;
  469. if (url) {
  470. window.open(process.env.VUE_APP_FILE_DOMAIN + url, '_blank');
  471. }
  472. },
  473. handleExceed(files, fileList) {
  474. this.$message.warning(`当前限制选择 10 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
  475. },
  476. //试剂弹窗提交
  477. onMixReagentSubmit(data) {
  478. if (data.uuid !== this.uuid) return;
  479. // 创建一个验证控制器,用于收集各级验证结果
  480. const validationController = {
  481. isPrevented: false,
  482. errorMsg: '',
  483. prevent(msg) {
  484. this.isPrevented = true;
  485. if (msg) this.errorMsg = msg;
  486. }
  487. };
  488. // 触发自定义验证事件,让父组件判断是否满足需求
  489. // 父组件可以通过validationController.prevent(msg)来阻止提交
  490. this.$emit('beforeReagentSubmit', data, validationController);
  491. // 检查是否被阻止
  492. if (validationController.isPrevented) {
  493. // 验证不通过,显示错误信息
  494. if (validationController.errorMsg) {
  495. this.$message.error(validationController.errorMsg);
  496. }
  497. return;
  498. }
  499. // 验证通过,继续执行
  500. this.executeReagentSubmit(data);
  501. },
  502. // 执行试剂提交的共同逻辑
  503. executeReagentSubmit(data) {
  504. this.inputValue = data.selectedId;
  505. const { filledCodes = [] } = this.item;
  506. console.log(filledCodes, "filledCodes")
  507. const { selectInfo, row } = data;
  508. if (filledCodes.length > 0) {
  509. this.inputValue = row[filledCodes[0]] + "(" + row[filledCodes[1]] + ")";
  510. }
  511. this.selectRegentInfo = data;
  512. EventBus.$emit("hideSelectMixReagentDialog");
  513. this.onCommonHandleSaveRecord(this.inputValue);
  514. },
  515. //统一处理试剂/供试品等弹窗
  516. onCommonHandleRegent(item, type) {
  517. if (this.templateFillType !== 'actFill') {
  518. return
  519. }
  520. let params = {
  521. studyFormId: this.templateData.id,
  522. uuid: this.uuid,
  523. sourceFrom: this.sourceFrom,
  524. }
  525. let eventName = "showSelectMixReagentDialog";
  526. if (type === "yq") {
  527. eventName = "showSelectInstrumentDialog";
  528. } else {
  529. const sjType = {
  530. sj: "1",//试剂
  531. gsp: "7",//供试品
  532. mix: "1",//试剂/供试品/试剂
  533. gyzj: "3",//给药制剂
  534. mjy: "5",//麻精药
  535. xj: "9",//细菌
  536. xb: "11",//细胞
  537. jcb: "13",//检测板
  538. qxbd: "15",//前序表单
  539. }
  540. params = {
  541. ...params,
  542. type: sjType[type]
  543. };
  544. if (type === "mix") {
  545. params.mixType = true;
  546. }
  547. }
  548. EventBus.$emit(eventName, params)
  549. // this.$emit('regent', item,type);
  550. },
  551. // 点击按钮
  552. handleClickButton(item) {
  553. this.inputValue = `button-${new Date().getTime()}`;
  554. this.onCommonHandleSaveRecord(this.inputValue);
  555. },
  556. onDateChange(val, format) {
  557. this.inputValue = moment(val).format(format);
  558. this.onCommonHandleSaveRecord(this.inputValue);
  559. },
  560. getUserName(record) {
  561. const locale = this.$i18n.locale;
  562. if (locale === 'zh_CN') {
  563. return record.userNameCn;
  564. }
  565. return record.userNameEn;
  566. },
  567. // 处理电子签名取消事件
  568. handleEditSignCancel(data) {
  569. if (data.uuid === this.uuid) {
  570. // 如果有待上传的文件,清空它
  571. if (this.pendingUploadFile) {
  572. this.pendingUploadFile = null;
  573. this.$message.info('已取消文件上传');
  574. } else if (this.pendingRemoveFile) {
  575. // 如果有待删除的文件,清空它
  576. this.pendingRemoveFile = null;
  577. this.$message.info('已取消文件删除');
  578. } else {
  579. this.resetRecord();
  580. }
  581. }
  582. },
  583. // 处理电子签名确认回调事件
  584. handleEditSignCallback(data) {
  585. if (data.uuid === this.uuid) {
  586. this.onEditSignSave(data.data);
  587. }
  588. },
  589. onEditSignSave(data) {
  590. // 检查是否有待上传的文件
  591. if (this.pendingUploadFile) {
  592. // 签名验证通过,将文件添加到列表并上传
  593. const file = this.pendingUploadFile;
  594. // 将文件添加到 fileList
  595. this.fileList.push(file);
  596. // 清空待上传文件标记
  597. this.pendingUploadFile = null;
  598. // 手动触发上传
  599. this.$nextTick(() => {
  600. const uploadComponent = this.$refs.uploadRef;
  601. if (uploadComponent) {
  602. uploadComponent.submit();
  603. }
  604. });
  605. } else if (this.pendingRemoveFile) {
  606. // 签名验证通过,执行文件删除
  607. const { file, fileList } = this.pendingRemoveFile;
  608. // 清空待删除文件标记
  609. this.pendingRemoveFile = null;
  610. // 执行删除操作
  611. this.executeRemove(file, fileList);
  612. } else {
  613. // 没有待上传/删除文件,执行正常的记录更新
  614. this.handleUpdateRecord(data);
  615. }
  616. },
  617. getChecked() {
  618. return !!this.getFieldCheckObj()[this.fieldKey]?.checked;
  619. },
  620. getFillTypeStyle(type) {
  621. const { fillType } = this.item;
  622. const typeObj = {
  623. actFill: "orange-border",//实际填写的边框颜色
  624. green: "green-border",
  625. preFill: "blue-border",//预填写的边框颜色
  626. }
  627. // 如果有错误状态,返回红色边框样式,覆盖原有的边框颜色
  628. if (this.error && this.type !== "attachment" && this.type !== "checkboxTag") {
  629. return "error-border";
  630. }
  631. return typeObj[fillType] || ""
  632. },
  633. //确认回复
  634. onReplyConfirm() {
  635. if (!this.replyContent) {
  636. this.$message({
  637. message: '请输入内容',
  638. type: 'error'
  639. });
  640. return;
  641. }
  642. const baseInfo = this.getCommonRecordInfo();
  643. const record = {
  644. ...baseInfo,
  645. title: this.templateFillType == 'actFill' ? "回复意见" : "复核意见",
  646. time: moment().format("YYYY-MM-DD HH:mm:ss"),
  647. }
  648. if (this.templateFillType == 'actFill') {
  649. record.reply = this.replyContent;
  650. const deepList = deepClone(this.getFhyjjl());//实际填报应该是修改指定的字段
  651. const item = deepList.find(o => o.key == record.key);
  652. if (item) {
  653. item.reply = this.replyContent;
  654. }
  655. this.replaceFhyjjl(deepList);//实际填报应该是修改指定的字段
  656. } else {
  657. const records = this.getReplyRecords();
  658. record.content = this.replyContent;
  659. if (records.length > 0) {
  660. const o = records[0];
  661. if (o.reply && o.content) {//如果填报人员已回复,那么就产生一条新的记录。
  662. this.updateFhyjjl(record);//qc直接插入数据源
  663. } else {//如果填报人员未填报,只更新当条记录的复核内容
  664. const deepList = deepClone(this.getFhyjjl());
  665. const item = deepList.find(it => it.key == record.key);
  666. if (item) {
  667. item.content = this.replyContent;
  668. }
  669. this.replaceFhyjjl(deepList);
  670. }
  671. } else {
  672. this.updateFhyjjl(record);//qc直接插入数据源
  673. }
  674. }
  675. const params = {
  676. //reply:回复,content:复核
  677. type: this.templateFillType == 'actFill' ? "reply" : "content",
  678. newRecord: [record],
  679. resourceList: this.getFhyjjl(),
  680. }
  681. // 触发回复记录事件
  682. EventBus.$emit('onModifyRecord', params);
  683. // 清空回复内容
  684. this.replyContent = '';
  685. // 隐藏弹窗
  686. this.visible = false;
  687. },
  688. //获取question图标颜色
  689. getQuestionColor() {
  690. const records = this.getReplyRecords();
  691. if (records.length > 0) {
  692. const o = records[0];
  693. if (o.reply && o.content) {//有回复意见和复核意见
  694. return "green"
  695. } else if (o.content && !o.reply) {//只有复核意见
  696. return "orange"
  697. } else {
  698. return "gray"
  699. }
  700. } else {//没有回复记录
  701. return "gray"
  702. }
  703. },
  704. // 复选框变化处理
  705. onCheckboxChange(val) {
  706. //有提出意见就不能勾选
  707. if (this.templateFillType == 'qc' && this.getQuestionColor() === "orange") {
  708. this.checkboxValue = false;
  709. this.$message({
  710. message: '该表单还有质疑项未处理,无法勾选',
  711. type: 'error'
  712. });
  713. return;
  714. }
  715. this.checkboxValue = val;
  716. // 触发修改记录事件
  717. EventBus.$emit('onModifyRecord', {
  718. type: "checkbox",
  719. fieldCheckObj: JSON.stringify({ ...this.getFieldCheckObj(), [this.fieldKey]: { checked: val } }),//复选框状态对象
  720. });
  721. this.updateFieldCheckObj({ [this.fieldKey]: { checked: val } });
  722. // this.$emit('input', val);
  723. // this.$emit('change', val);
  724. },
  725. onRemoveTag(e) {
  726. this.onCommonHandleSaveRecord(this.inputValue);
  727. },
  728. onItemCheckboxChange() {
  729. this.onCommonHandleSaveRecord(this.inputValue);
  730. },
  731. // 下拉框失去焦点处理
  732. onSelectBlur(visible) {
  733. if (!visible) {
  734. this.onCommonHandleSaveRecord(this.inputValue);
  735. }
  736. },
  737. // 统一处理输入变化
  738. onInputChange(val) {
  739. let value = val !== undefined ? val : this.inputValue;
  740. // 如果是checkboxList类型,需要同时发送checkboxValues和otherValues
  741. if (this.type === 'checkboxList') {
  742. // 检查是否有被取消选中的checkbox
  743. if (this.oldValue && Array.isArray(this.oldValue)) {
  744. const uncheckedValues = this.oldValue.filter(oldVal => !this.inputValue.includes(oldVal));
  745. // 清除被取消选中的checkbox对应的otherValues
  746. if (uncheckedValues.length > 0) {
  747. this.item.options.forEach(option => {
  748. if (uncheckedValues.includes(option.value) && option.otherCode) {
  749. this.$delete(this.otherValues, option.otherCode);
  750. }
  751. });
  752. }
  753. }
  754. value = {
  755. checkboxValues: this.inputValue,
  756. otherValues: this.otherValues
  757. };
  758. if (val) {
  759. this.onCommonHandleSaveRecord();
  760. }
  761. }
  762. this.$emit('input', value);
  763. this.$emit('change', value);
  764. // 根据输入值判断是否显示错误状态
  765. const isEmpty = this.isValueEmpty(value);
  766. if (this.error && !isEmpty) {
  767. this.$emit('update:error', false);
  768. } else if (!this.error && isEmpty) {
  769. this.$emit('update:error', true);
  770. }
  771. },
  772. // 处理checkboxList中otherCode对应的输入框变化
  773. onOtherInputChange(code, value) {
  774. this.otherValues[code] = value;
  775. this.onInputChange();
  776. },
  777. // checkboxTag的checkbox变化处理
  778. onCheckboxTagChange(tagIndex, e) {
  779. this.currentTagIndex = tagIndex;
  780. this.checkboxTagList[tagIndex].checked = e;
  781. this.emitCheckboxTagValue();
  782. this.onCommonHandleSaveRecord();
  783. },
  784. // tag输入框失去焦点
  785. onTagBlur(tagIndex) {
  786. this.currentTagIndex = tagIndex;
  787. const value = this.checkboxTagList[tagIndex].tagValue;
  788. this.emitCheckboxTagValue();
  789. this.onCommonHandleSaveRecord(value);
  790. },
  791. // 删除tag
  792. onDeleteTag(tagIndex) {
  793. this.currentTagIndex = tagIndex;
  794. // 从列表中删除指定索引的tag
  795. this.checkboxTagList.splice(tagIndex, 1);
  796. this.emitCheckboxTagValue();
  797. this.$emit("deleteTag", tagIndex);
  798. },
  799. // 发送checkboxTag的值
  800. emitCheckboxTagValue() {
  801. // 发送整个数组
  802. this.$emit('input', [...this.checkboxTagList]);
  803. this.$emit('change', [...this.checkboxTagList]);
  804. },
  805. // 统一处理失去焦点事件
  806. onBlur(e) {
  807. this.onCommonHandleSaveRecord(e.target.value);
  808. },
  809. // 点击question图标
  810. onClickQuestion() {
  811. const { templateFillType } = this;
  812. if (templateFillType == 'actFill' || templateFillType == 'qc') {
  813. if (templateFillType == 'qc') {
  814. const field = this.getFieldCheckObj()[this.fieldKey];
  815. if (field && field.checked) {
  816. this.$message({
  817. message: '该字段已勾选复核框,请先取消勾选后再进行提交疑问',
  818. type: 'error'
  819. });
  820. return;
  821. }
  822. }
  823. const records = this.getReplyRecords();
  824. let content = "";
  825. if (records.length > 0) {
  826. const o = records[0];
  827. if (!o.reply && templateFillType == 'qc') {//如果填报人员没有回复,qc点击的时候需要回填上次填报的信息
  828. content = o.content;
  829. } else if (templateFillType == 'actFill') {//如果qc没有复核,填报点击的时候需要回填上次填报的信息
  830. content = o.reply;
  831. }
  832. }
  833. this.replyContent = content;
  834. this.visible = true;
  835. }
  836. },
  837. async onCommonHandleSaveRecord(val) {
  838. const isEmpty = this.isValueEmpty(this.inputValue);
  839. if (this.error && !isEmpty) {
  840. this.$emit('update:error', false);
  841. } else if (!this.error && isEmpty) {
  842. this.$emit('update:error', true);
  843. }
  844. // 创建验证控制器,让父组件可以在保存前进行验证
  845. const validationController = {
  846. isPrevented: false,
  847. errorMsg: '',
  848. prevent(msg) {
  849. this.isPrevented = true;
  850. if (msg) this.errorMsg = msg;
  851. }
  852. };
  853. // 触发beforeSaveRecord事件,让父组件进行验证
  854. this.$emit('beforeSaveRecord', {
  855. value: this.inputValue,
  856. oldValue: this.oldValue,
  857. fieldKey: this.fieldKey
  858. }, validationController);
  859. // 检查是否被阻止
  860. if (validationController.isPrevented) {
  861. // 验证不通过,显示错误信息
  862. if (validationController.errorMsg) {
  863. this.$message.error(validationController.errorMsg);
  864. }
  865. // 回退到旧值
  866. this.inputValue = this.oldValue;
  867. this.$emit('input', this.inputValue);
  868. return;
  869. }
  870. if (!this.isFieldsRecord) {//是否需要记录修改记录
  871. this.$emit("blur", this.inputValue);
  872. this.$emit('input', this.inputValue);
  873. this.$emit("change", this.inputValue);
  874. return;
  875. }
  876. // 值发生了变化,需要弹出密码输入框
  877. let isSame = true, isOldValueEmpty = true;
  878. // 如果是checkboxList类型,需要同时比较otherValues
  879. if (this.type === 'checkboxList' && this.otherValues) {
  880. isSame = this.isEqual(this.oldOtherValues, this.otherValues);
  881. isOldValueEmpty = this.isValueEmpty(this.oldOtherValues);
  882. } else if (this.type === "checkboxTag") {
  883. // checkboxTag类型,只比较当前tagIndex的数据
  884. const currentTag = this.checkboxTagList[this.currentTagIndex];
  885. const oldTag = this.oldCheckboxTagList[this.currentTagIndex] || {};
  886. isSame = this.isEqual(oldTag.checked, currentTag.checked);
  887. isOldValueEmpty = this.isValueEmpty(oldTag.checked);
  888. }else{
  889. isSame = this.isEqual(this.oldValue, this.inputValue)
  890. isOldValueEmpty = this.isValueEmpty(this.oldValue);
  891. }
  892. if (isSame) {
  893. return;
  894. }
  895. if (!isOldValueEmpty && !(isSame) && this.templateFillType === "actFill") {
  896. // 通过EventBus触发电子签名弹窗
  897. EventBus.$emit('showEditSignDialog', { uuid: this.uuid });
  898. } else {//如果是第一次填写,不需要密码验证
  899. this.handleUpdateRecord()
  900. }
  901. },
  902. //如果用户取消,那么回退到上一次的值
  903. resetRecord() {
  904. // 用户点击取消,还原数据
  905. let oldValue = this.oldValue;
  906. if (this.type === 'checkboxList') {
  907. oldValue = {
  908. checkboxValues: oldValue.checkboxValues || oldValue,
  909. otherValues: this.oldOtherValues
  910. };
  911. } else if (this.type === "checkboxTag") {
  912. // checkboxTag类型,只回退当前tagIndex的数据
  913. if (this.currentTagIndex >= 0 && this.currentTagIndex < this.oldCheckboxTagList.length) {
  914. const oldTag = this.oldCheckboxTagList[this.currentTagIndex];
  915. this.checkboxTagList[this.currentTagIndex] = { ...oldTag };
  916. oldValue = [...this.checkboxTagList];
  917. } else {
  918. // 如果没有指定tagIndex,回退整个数组
  919. this.checkboxTagList = JSON.parse(JSON.stringify(this.oldCheckboxTagList));
  920. oldValue = [...this.checkboxTagList];
  921. }
  922. }
  923. this.inputValue = this.oldValue;
  924. this.$emit('input', oldValue); // 触发 v-model 更新
  925. // this.$emit("blur", this.oldValue);
  926. this.$emit("change", oldValue, "cancel");
  927. if (this.item.type === "clickable") {
  928. this.$emit("resetRecord");
  929. }
  930. },
  931. //处理更新记录
  932. handleUpdateRecord(data, recordData) {
  933. const baseInfo = this.getCommonRecordInfo();
  934. if (!this.oldValue && !this.inputValue) {
  935. return
  936. }
  937. if (recordData) {
  938. this.oldValue = recordData.oldValue;
  939. this.inputValue = recordData.inputValue;
  940. }
  941. let recordOldVlaue = this.oldValue, recordValue = this.inputValue, isModify = !!this.oldValue;
  942. if (this.type === "checkboxTag") {
  943. // checkboxTag类型,只记录当前tagIndex的数据变化
  944. const oldTag = this.oldCheckboxTagList[this.currentTagIndex] || {};
  945. const currentTag = this.checkboxTagList[this.currentTagIndex] || {};
  946. recordOldVlaue = `${oldTag.tagValue || ''}:${oldTag.checked ? '勾选' : '未勾选'}`;
  947. recordValue = `${currentTag.tagValue || ''}:${currentTag.checked ? '勾选' : '未勾选'}`;
  948. isModify = oldTag.checked !== undefined
  949. }
  950. const record = {
  951. ...baseInfo,
  952. oldValue: recordOldVlaue,
  953. value: recordValue,
  954. title: isModify ? "修改" : "提交",
  955. time: moment().format("YYYY-MM-DD HH:mm:ss"),
  956. }
  957. if (data) {
  958. record.reason = data.remark
  959. }
  960. const params = {
  961. type: "fieldChanged",
  962. newRecord: [record],
  963. resourceList: this.getZdxgjl(),
  964. }
  965. // 更新oldValue和oldOtherValues
  966. if (this.type === 'checkboxList') {
  967. this.oldValue = [...this.inputValue];
  968. this.oldOtherValues = { ...this.otherValues };
  969. } else if (this.type === "checkboxTag") {
  970. // checkboxTag类型,只更新当前tagIndex的数据
  971. if (this.currentTagIndex >= 0 && this.currentTagIndex < this.checkboxTagList.length) {
  972. this.oldCheckboxTagList[this.currentTagIndex] = { ...this.checkboxTagList[this.currentTagIndex] };
  973. } else {
  974. // 如果没有指定tagIndex,更新整个数组
  975. this.oldCheckboxTagList = JSON.parse(JSON.stringify(this.checkboxTagList));
  976. }
  977. }
  978. let value = this.inputValue;
  979. if (this.type === 'checkboxList') {
  980. value = {
  981. checkboxValues: this.inputValue,
  982. otherValues: this.otherValues
  983. };
  984. } else if (this.type === "checkboxTag") {
  985. value = [...this.checkboxTagList];
  986. }
  987. if (this.type === "button") {
  988. this.$emit('clickButton', this.item, this.inputValue, data);
  989. if (this.templateFillType === "preFill") {
  990. return;
  991. }
  992. }
  993. //用户输入密码并点击确定,保存修改
  994. this.oldValue = value; // 更新旧值
  995. this.$emit("blur", value);
  996. this.$emit('input', value);
  997. this.$emit("change", value, data ? "save" : "");
  998. if (this.item.type === "clickable") {//clickable的丢给父级去处理
  999. return;
  1000. }
  1001. if (this.templateFillType === "actFill") {//只有实际填报的时候才记录修改记录
  1002. this.updateZdxgjl(record);
  1003. }
  1004. this.$nextTick(() => {
  1005. EventBus.$emit('onModifyRecord', params,)
  1006. console.log(params, "onModifyRecord")
  1007. if (this.regentType.includes(this.item.type)) {
  1008. this.$emit("onRegentSubmit", this.selectRegentInfo, this.inputValue);
  1009. }
  1010. })
  1011. },
  1012. //判断两个值是否相等
  1013. isEqual(oldValue, nowValue) {
  1014. if (oldValue === null || nowValue === null) {
  1015. return oldValue === nowValue;
  1016. }
  1017. if (typeof oldValue === 'object' && typeof nowValue === 'object') {
  1018. return JSON.stringify(oldValue) === JSON.stringify(nowValue);
  1019. }
  1020. return oldValue === nowValue;
  1021. },
  1022. //获取公共记录信息
  1023. getCommonRecordInfo() {
  1024. const { nickName, name } = this.$store.getters;
  1025. //locale:zh-CN 中文 en-US 英文
  1026. const { label, parentLabel } = this.item;
  1027. let fieldLabelCn = this.$i18n.t(label, "zh_CN"), fieldLabelEn = this.$i18n.t(label, "en_US");
  1028. if (label === "template.common.other") {
  1029. fieldLabelCn = this.$i18n.t(parentLabel, "zh_CN") + this.$i18n.t("template.common.otherInfo", "zh_CN");
  1030. fieldLabelEn = this.$i18n.t(parentLabel, "en_US") + this.$i18n.t("template.common.otherInfo", "en_US");
  1031. } else if (!label && parentLabel == "template.common.remark") {
  1032. fieldLabelCn = this.$i18n.t(parentLabel, "zh_CN") + this.$i18n.t("template.common.unit", "zh_CN");
  1033. fieldLabelEn = this.$i18n.t(parentLabel, "en_US") + this.$i18n.t("template.common.unit", "en_US");
  1034. }
  1035. const commonInfo = {
  1036. userNameCn: nickName,
  1037. userNameEn: name,
  1038. key: this.fieldKey,
  1039. fieldCn: `${this.$i18n.t(this.fieldItemLabel, "zh_CN")}` + (fieldLabelCn ? ("-" + fieldLabelCn) : ""),
  1040. fieldEn: `${this.$i18n.t(this.fieldItemLabel, "en_US")}` + (fieldLabelEn ? ("-" + fieldLabelEn) : ""),
  1041. }
  1042. return commonInfo;
  1043. },
  1044. // 判断值是否为空
  1045. isValueEmpty(value) {
  1046. if (value === null || value === undefined || value === '') {
  1047. return true;
  1048. }
  1049. if (typeof value === 'string' && value.trim() === '') {
  1050. return true;
  1051. }
  1052. if (Array.isArray(value) && value.length === 0) {
  1053. return true;
  1054. }
  1055. return false;
  1056. },
  1057. // 判断checkboxList中特定otherCode输入框是否有错误
  1058. isOtherInputError(otherCode) {
  1059. if (!this.error) {
  1060. return false;
  1061. }
  1062. // 检查该otherCode对应的输入框是否为空
  1063. return this.isValueEmpty(this.otherValues[otherCode]);
  1064. },
  1065. handleClickable(item, event) {
  1066. if (this.templateFillType !== 'actFill') {
  1067. return
  1068. }
  1069. this.$emit("clickable", item)
  1070. },
  1071. //判断是否禁用复选框
  1072. getCheckboxDisabled() {
  1073. //只有qc能操作checkbox,其他都只能看。
  1074. return this.templateFillType !== 'qc'
  1075. },
  1076. //判断是否显示复选框图标
  1077. getIsShowCheckboxIcon() {
  1078. if (this.templateFillType === 'qc') {
  1079. return true;
  1080. }
  1081. return this.getChecked();
  1082. },
  1083. //判断是否显示复制按钮
  1084. getIsShowCopyIcon() {
  1085. const { copyFrom } = this.item;
  1086. return copyFrom && this.templateFillType === "actFill";
  1087. },
  1088. //判断是否显示操作按钮
  1089. isShowHandle() {
  1090. const { fillType } = this.item;
  1091. //只有当模板状态不是预填时,才显示操作按钮
  1092. return this.templateFillType !== "preFill" && fillType === "actFill" && this.type !== "button"
  1093. },
  1094. //判断是否禁用
  1095. getDisabled() {
  1096. const { item } = this;
  1097. const { fillType } = item;
  1098. if (item.hasOwnProperty("disabled")) {
  1099. return item.disabled
  1100. } else {
  1101. if (fillType === "actFill") {//当模板状态是实际填写时,只有当fillType是actFill时才能填写
  1102. return this.templateFillType !== "actFill"
  1103. } else if (fillType === "preFill") {//当模板状态是预填写时,只有当fillType是preFill才能填写
  1104. return this.templateFillType !== "preFill"
  1105. } else {
  1106. return true
  1107. }
  1108. }
  1109. },
  1110. getPlaceholder() {
  1111. const { placeholder, label } = this.item;
  1112. const { type } = this;
  1113. if (this.getDisabled()) {
  1114. return ""
  1115. }
  1116. if (this.regentType.includes(type) || type === "clickable") {
  1117. return this.$t("template.common.pleaseSelect")
  1118. }
  1119. let prex = "template.common.pleaseFillIn"
  1120. if (type === "select" || type === "dateTime") {
  1121. prex = "template.common.pleaseSelect"
  1122. }
  1123. return placeholder ? this.$t(placeholder) : (this.$t(prex) + this.$t(label))
  1124. },
  1125. async onCopy() {
  1126. // 触发复制事件
  1127. this.$emit("copy");
  1128. // 等待复制操作完成后,调用保存记录方法
  1129. this.$nextTick(async () => {
  1130. await this.onCommonHandleSaveRecord(this.inputValue);
  1131. });
  1132. },
  1133. //判断是否显示问题图标
  1134. getIsShowQuestionIcon() {
  1135. if (this.templateFillType === "qc") {//qc可以直接查看
  1136. return true;
  1137. }
  1138. return this.getReplyRecords().length > 0;
  1139. },
  1140. //判断是否显示修改记录图标
  1141. getIsShowRecordIcon() {
  1142. return this.getModifyRecords().length > 0
  1143. },
  1144. //获取回复记录
  1145. getReplyRecords() {
  1146. const { fieldKey, getFhyjjl } = this;
  1147. const records = getFhyjjl()?.filter(item => item.key === fieldKey) || [];
  1148. return records;
  1149. },
  1150. //获取字段修改记录
  1151. getModifyRecords() {
  1152. const { fieldKey, getZdxgjl } = this;
  1153. const records = getZdxgjl().filter(item => item.key === fieldKey);
  1154. return records;
  1155. },
  1156. // 鼠标进入主容器
  1157. async onMouseEnter(type, event) {
  1158. this.currentRecordType = type;
  1159. clearTimeout(this.modalTimer);
  1160. let record = [];
  1161. if (type === "fieldChanged") {
  1162. record = this.getModifyRecords();
  1163. } else if (type === "replyRecord") {
  1164. record = this.getReplyRecords();
  1165. }
  1166. this.modificationRecords = record;
  1167. // 先计算模态框位置,避免闪烁
  1168. this.showModal = true;
  1169. this.$nextTick(() => {
  1170. if (this.$refs.modalRef) {
  1171. const elementRect = event.target.getBoundingClientRect();
  1172. const modalEl = this.$refs.modalRef;
  1173. // 获取模态框的宽度和高度
  1174. const modalWidth = modalEl.offsetWidth || 250; // 默认宽度
  1175. const modalHeight = modalEl.offsetHeight || 300; // 默认高度
  1176. const viewportWidth = window.innerWidth;
  1177. const viewportHeight = window.innerHeight;
  1178. // 计算模态框位置
  1179. let leftPos, topPos;
  1180. // 检查右侧空间是否足够
  1181. if (elementRect.right + modalWidth + 5 <= viewportWidth) {
  1182. // 右侧空间充足,显示在右侧
  1183. leftPos = elementRect.right + 5 + 'px';
  1184. } else if (elementRect.left - modalWidth - 5 >= 0) {
  1185. // 左侧空间充足,显示在左侧
  1186. leftPos = elementRect.left - modalWidth - 5 + 'px';
  1187. } else {
  1188. // 两侧空间都不足,选择空间更大的一边
  1189. if (elementRect.left > viewportWidth - elementRect.right) {
  1190. // 左侧空间更大,显示在左侧
  1191. leftPos = Math.max(5, elementRect.left - modalWidth - 5) + 'px';
  1192. } else {
  1193. // 右侧空间更大,显示在右侧(可能会超出屏幕,但尽量靠近边缘)
  1194. leftPos = Math.min(elementRect.right + 5, viewportWidth - 5) + 'px';
  1195. }
  1196. }
  1197. // 计算顶部位置,确保不超出屏幕上下边界
  1198. topPos = Math.max(5, Math.min(elementRect.top, viewportHeight - modalHeight - 5)) + 'px';
  1199. // 设置模态框位置
  1200. modalEl.style.left = leftPos;
  1201. modalEl.style.top = topPos;
  1202. }
  1203. });
  1204. },
  1205. // 鼠标离开主容器
  1206. onMouseLeave() {
  1207. // this.currentRecordType = '';
  1208. // this.modificationRecords = [];//清空数据源
  1209. // 延迟隐藏模态框,让用户有机会移动到模态框上
  1210. this.modalTimer = setTimeout(() => {
  1211. if (!this.isHoveringModal) {
  1212. this.showModal = false;
  1213. }
  1214. }, 100);
  1215. },
  1216. // 鼠标进入模态框
  1217. onModalEnter() {
  1218. this.isHoveringModal = true;
  1219. clearTimeout(this.modalTimer);
  1220. },
  1221. // 鼠标离开模态框
  1222. onModalLeave() {
  1223. this.isHoveringModal = false;
  1224. this.currentRecordType = "";
  1225. this.modificationRecords = [];//清空数据源
  1226. this.modalTimer = setTimeout(() => {
  1227. this.showModal = false;
  1228. }, 100);
  1229. },
  1230. },
  1231. }
  1232. </script>
  1233. <style lang="scss">
  1234. .flex {
  1235. display: flex;
  1236. align-items: center;
  1237. }
  1238. .flex1 {
  1239. flex: 1;
  1240. }
  1241. .handle-row {
  1242. margin-left: 5px;
  1243. display: flex;
  1244. align-items: center;
  1245. cursor: pointer;
  1246. }
  1247. .w-100 {
  1248. width: 100%;
  1249. }
  1250. .handle-icon {
  1251. width: 18px;
  1252. height: 18px;
  1253. &:not(:last-child) {
  1254. margin-right: 5px;
  1255. }
  1256. }
  1257. .mr-5 {
  1258. margin-right: 5px !important;
  1259. }
  1260. .orange {
  1261. color: #f9c588;
  1262. }
  1263. .green {
  1264. color: green;
  1265. }
  1266. .gray {
  1267. color: #b2b2b2;
  1268. }
  1269. .orange-border {
  1270. .el-input-group__prepend,
  1271. input,
  1272. textarea {
  1273. border-color: #f9c588;
  1274. &:focus {
  1275. border-color: #f9c588;
  1276. }
  1277. &:hover {
  1278. border-color: #f9c588;
  1279. }
  1280. &:disabled {
  1281. border-color: #f9c588 !important;
  1282. }
  1283. }
  1284. .el-checkbox__inner {
  1285. border-color: #f9c588 !important;
  1286. }
  1287. }
  1288. .el-button--primary {
  1289. &.orange-border {
  1290. background-color: #f79b31 !important;
  1291. border-color: #f79b31 !important;
  1292. &:hover {
  1293. background-color: #f79b31 !important;
  1294. }
  1295. &:disabled {
  1296. background-color: rgba(#f79b31, .8) !important;
  1297. border-color: rgba(#f79b31, .8) !important;
  1298. }
  1299. &:active {
  1300. background-color: rgba(#f79b31, .8) !important;
  1301. border-color: rgba(#f79b31, .8) !important;
  1302. }
  1303. }
  1304. &.blue-border {
  1305. background-color: #4ea2ff !important;
  1306. border-color: #4ea2ff !important;
  1307. &:hover {
  1308. background-color: #4ea2ff !important;
  1309. }
  1310. &:disabled {
  1311. background-color: rgba(#4ea2ff, .8) !important;
  1312. border-color: rgba(#4ea2ff, .8) !important;
  1313. }
  1314. &:active {
  1315. background-color: rgba(#4ea2ff, .8) !important;
  1316. border-color: rgba(#4ea2ff, .8) !important;
  1317. }
  1318. }
  1319. }
  1320. .green-border {
  1321. .el-input-group__prepend,
  1322. input,
  1323. textarea {
  1324. border-color: green;
  1325. &:focus {
  1326. border-color: green;
  1327. }
  1328. &:hover {
  1329. border-color: green;
  1330. }
  1331. &:disabled {
  1332. border-color: green !important;
  1333. }
  1334. }
  1335. }
  1336. .blue-border {
  1337. .el-input-group__prepend,
  1338. input,
  1339. .el-checkbox__inner,
  1340. textarea {
  1341. border-color: #4ea2ff;
  1342. &:focus {
  1343. border-color: #4ea2ff;
  1344. }
  1345. &:hover {
  1346. border-color: #4ea2ff;
  1347. }
  1348. &:disabled {
  1349. border-color: #4ea2ff !important;
  1350. }
  1351. }
  1352. }
  1353. .error-border {
  1354. .el-input-group__prepend,
  1355. input,
  1356. textarea,
  1357. .el-select,
  1358. .clickable,
  1359. .el-date-editor {
  1360. border-color: #ff5d5d;
  1361. box-shadow: 0 0 6px #ffc3c3 !important;
  1362. &:focus {
  1363. border-color: #ff5d5d;
  1364. box-shadow: 0 0 6px #ffc3c3 !important;
  1365. }
  1366. &:hover {
  1367. border-color: #ff5d5d;
  1368. box-shadow: 0 0 6px #ffc3c3 !important;
  1369. }
  1370. }
  1371. // 为 el-select 和 el-date-picker 添加错误边框样式
  1372. .el-select .el-input__inner,
  1373. .el-date-editor .el-input__inner .el-checkbox__inner {
  1374. border-color: #ff5d5d;
  1375. box-shadow: 0 0 6px #ffc3c3 !important;
  1376. }
  1377. // 处理 DecimalInput 组件的错误边框样式
  1378. :deep(.el-input-number) {
  1379. .el-input__inner {
  1380. border-color: #ff5d5d;
  1381. box-shadow: 0 0 6px #ffc3c3 !important;
  1382. }
  1383. }
  1384. // 为点击式表单项添加错误边框样式
  1385. .clickable {
  1386. border-color: #ff5d5d;
  1387. box-shadow: 0 0 6px #ffc3c3 !important;
  1388. }
  1389. }
  1390. .orange-bg {
  1391. background-color: #FFF1F1 !important; // 橙色背景,透明度适中
  1392. input,
  1393. textarea,
  1394. .el-input__inner,
  1395. .el-textarea__inner {
  1396. background-color: #FFF1F1 !important;
  1397. }
  1398. }
  1399. .modification-modal {
  1400. position: fixed;
  1401. z-index: 9999;
  1402. background-color: rgba(0, 0, 0, 0.7);
  1403. border-radius: 4px;
  1404. padding: 10px;
  1405. color: white;
  1406. max-height: 300px;
  1407. min-width: 250px;
  1408. overflow: hidden;
  1409. pointer-events: auto;
  1410. opacity: 0;
  1411. transform: scale(0.9);
  1412. transition: opacity 0.2s ease, transform 0.2s ease;
  1413. }
  1414. .modification-modal.show {
  1415. opacity: 1;
  1416. transform: scale(1);
  1417. }
  1418. .modification-modal .modal-content {
  1419. max-height: 280px;
  1420. overflow-y: auto;
  1421. padding-right: 5px;
  1422. }
  1423. .modification-modal .modal-content h4 {
  1424. margin: 0 0 10px 0;
  1425. font-size: 14px;
  1426. border-bottom: 1px solid #ccc;
  1427. padding-bottom: 5px;
  1428. }
  1429. .modification-modal .records-list {
  1430. font-size: 12px;
  1431. }
  1432. .modification-modal .record-item p {
  1433. margin: 5px 0;
  1434. word-break: break-all;
  1435. }
  1436. .modification-modal .record-item hr {
  1437. border: 0;
  1438. border-top: 1px solid #555;
  1439. margin: 8px 0;
  1440. }
  1441. .modification-modal .no-records {
  1442. text-align: center;
  1443. color: #aaa;
  1444. font-style: italic;
  1445. }
  1446. .clickable {
  1447. cursor: pointer;
  1448. width: auto;
  1449. // margin-left: 10px;
  1450. min-height: 28px;
  1451. line-height: 28px;
  1452. word-break: break-all;
  1453. border-radius: 4px;
  1454. border: 1px solid #4ea2ff;
  1455. display: flex;
  1456. align-items: center;
  1457. padding: 0 15px;
  1458. font-size: 14px;
  1459. font-weight: normal;
  1460. color: #606266;
  1461. flex: 1;
  1462. &.disabled {
  1463. cursor: not-allowed;
  1464. color: #c0c4cc;
  1465. background-color: #f5f7fa;
  1466. }
  1467. &.error-border {
  1468. border-color: #ff5d5d !important;
  1469. box-shadow: 0 0 6px #ffc3c3 !important;
  1470. }
  1471. }
  1472. .dialog-footer {
  1473. display: flex;
  1474. justify-content: flex-end;
  1475. }
  1476. .atta-tips {
  1477. color: #ff5d5d;
  1478. font-size: 12px;
  1479. margin-left: 5px;
  1480. }
  1481. .checkbox-list-container {
  1482. padding: 12px;
  1483. border: 1px solid #dcdfe6;
  1484. border-radius: 4px;
  1485. transition: all 0.3s;
  1486. &.error-border {
  1487. border-color: #ff5d5d !important;
  1488. box-shadow: 0 0 6px #ffc3c3 !important;
  1489. }
  1490. .checkbox-item {
  1491. margin-right: 16px;
  1492. display: flex;
  1493. align-items: center;
  1494. &:not(:last-child) {
  1495. margin-bottom: 10px;
  1496. }
  1497. // display: inline-block;
  1498. .el-input {
  1499. width: 200px;
  1500. margin-left: 10px;
  1501. &.error-border {
  1502. .el-input__inner {
  1503. border-color: #ff5d5d !important;
  1504. box-shadow: 0 0 6px #ffc3c3 !important;
  1505. }
  1506. }
  1507. }
  1508. }
  1509. }
  1510. .orange-border {
  1511. .checkbox-list-container {
  1512. border-color: #f9c588;
  1513. &:hover {
  1514. border-color: #f79b31;
  1515. }
  1516. }
  1517. .el-checkbox {
  1518. &.is-checked {
  1519. .el-checkbox__label {
  1520. color: #606266;
  1521. }
  1522. .el-checkbox__inner {
  1523. background-color: #f9c588;
  1524. border-color: #f9c588;
  1525. }
  1526. }
  1527. }
  1528. .el-radio {
  1529. &.is-checked {
  1530. .el-radio__label {
  1531. color: #606266;
  1532. }
  1533. .el-radio__inner {
  1534. background-color: #f9c588;
  1535. border-color: #f9c588;
  1536. }
  1537. }
  1538. }
  1539. }
  1540. .orange-bg {
  1541. .checkbox-list-container {
  1542. background-color: #FFF1F1 !important;
  1543. border-color: #f9c588;
  1544. }
  1545. }
  1546. // checkboxTag样式
  1547. .checkbox-tag-wrapper {
  1548. display: flex;
  1549. flex-wrap: wrap;
  1550. gap: 10px;
  1551. padding: 8px;
  1552. }
  1553. .checkbox-tag-container {
  1554. border-radius: 4px;
  1555. .checkbox-tag-item {
  1556. display: flex;
  1557. align-items: center;
  1558. gap: 8px;
  1559. .tag-content {
  1560. cursor: pointer;
  1561. position: relative;
  1562. .tag-input {
  1563. width: 100px;
  1564. }
  1565. .tag-display {
  1566. cursor: pointer;
  1567. user-select: none;
  1568. }
  1569. }
  1570. .delete-icon {
  1571. cursor: pointer;
  1572. color: #909399;
  1573. font-size: 12px;
  1574. padding: 2px;
  1575. border-radius: 50%;
  1576. position: absolute;
  1577. top: 6px;
  1578. right: 5px;
  1579. color: red;
  1580. background-color: #f5f5f5;
  1581. }
  1582. }
  1583. }
  1584. </style>