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

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