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

348 lines
15 KiB

  1. <template>
  2. <div>
  3. <div v-for="(item, index) in formConfig" :key="index" class="step-form-package">
  4. <div v-for="(sItem, key) in item.config" class="step-item" :key="key">
  5. <template v-if="sItem.type === 'input'">
  6. <HandleFormItem class="step-row" :field-item-label="fieldItemLabel" @blur="onBlur(key, $event)"
  7. :item="sItem" v-model="formFields[key]" :field-key="prefixKey + '_' + key"
  8. @copy="onCopy(sItem, key)" :error="errors[key]" @update:error="errors[key] = false"
  9. :orange-bg="orangeBgFields[key]" />
  10. </template>
  11. <template v-else-if="sItem.type === 'inputNumber'">
  12. <HandleFormItem class="step-row" :field-item-label="fieldItemLabel" :field-key="prefixKey + '_' + key"
  13. type="inputNumber" @blur="onBlur(key, $event)" :item="sItem"
  14. @input="onInputNumberChange(key, $event)" v-model="formFields[key]" @copy="onCopy(sItem, key)"
  15. :error="errors[key]" @update:error="errors[key] = false" :orange-bg="orangeBgFields[key]" />
  16. </template>
  17. <template v-else-if="sItem.type === 'select'">
  18. <HandleFormItem class="step-row" :field-item-label="fieldItemLabel" :field-key="prefixKey + '_' + key"
  19. type="select" @blur="onBlur(key, $event)" :item="sItem" v-model="formFields[key]"
  20. @change="onSelectChange(key, $event, sItem.type)"
  21. @copy="onCopy(sItem, key)" :error="errors[key]" @update:error="errors[key] = false"
  22. :orange-bg="orangeBgFields[key]" />
  23. </template>
  24. <template v-else-if="sItem.type === 'checkbox'">
  25. <HandleFormItem class="step-row" :field-item-label="fieldItemLabel" :field-key="prefixKey + '_' + key"
  26. type="checkbox" :item="sItem" v-model="formFields[key]"
  27. @change="onSelectChange(key, $event, sItem.type)"
  28. @copy="onCopy(sItem, key)" :error="errors[key]" @update:error="errors[key] = false"
  29. :orange-bg="orangeBgFields[key]" />
  30. </template>
  31. <template v-else-if="sItem.type === 'button'">
  32. <HandleFormItem
  33. type="button"
  34. :item="getButtonItem(sItem)"
  35. @clickButton="(e)=>handleClickButton(e,item)" />
  36. </template>
  37. <!-- 仪器instrumentsj(药剂) gsp(供试品) mix药剂/供试品/给药制剂 -->
  38. <template v-else-if="isRegent(sItem)">
  39. <HandleFormItem class="step-row" :field-item-label="fieldItemLabel" :field-key="prefixKey + '_' + key"
  40. :type="sItem.type" :error="errors[key]"
  41. @onRegentSubmit="(data)=>onRegentSubmit(data,key,sItem)"
  42. @update:error="errors[key] = false" :item="getRegentItem(sItem)"
  43. :value="formFields[key]" />
  44. </template>
  45. <template v-else-if="sItem.type === 'text'">
  46. <span>{{ sItem.label }}</span>
  47. </template>
  48. <template v-else-if="sItem.type === 'span'">
  49. <span>{{ formFields[key] }}</span>
  50. </template>
  51. <template v-else-if="sItem.type === 'zlfz'">
  52. {{ key }}
  53. <ZLSubPackage @update="(data)=>onSubPackageUpdate(data,key)" :subData = "formFields[key]" :ref="'zlSubPackageRef_'+key" />
  54. </template>
  55. <div v-show="isShowOther(formFields[key])" class="flex flex1">
  56. <div class="other-title">{{sItem.otherLabel ? $t(sItem.otherLabel) : $t("template.common.other") }}</div>
  57. <HandleFormItem sourceFrom = "step" class="step-row" :field-item-label="fieldItemLabel" :field-key="prefixKey+'_'+sItem.otherCode" @blur="onBlur(key, $event)" :item="getOtherItem(sItem)"
  58. v-model="formFields[sItem.otherCode]" @copy="onCopy(sItem, key)"
  59. :error="errors[sItem.otherCode]" @update:error="errors[sItem.otherCode] = false"
  60. :orange-bg="orangeBgFields[sItem.otherCode]" />
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import HandleFormItem from '@/components/Template/HandleFormItem.vue'
  68. import formPackageMixins from '@/components/Template/mixins/formPackageMixins.js'
  69. import ZLSubPackage from '@/components/Template/StepComponents/ZLSubPackage.vue'
  70. import { isShowOther } from "@/utils/formPackageCommon.js";
  71. import { EventBus } from "@/utils/eventBus";
  72. import { getuuid,isRegent} from "@/utils/index.js";
  73. import moment from 'moment'
  74. export default {
  75. inject: ['templateFillType','templateData'],
  76. components: {
  77. HandleFormItem,
  78. ZLSubPackage
  79. },
  80. mixins: [formPackageMixins],
  81. props: {
  82. formConfig: {
  83. type: Array,
  84. default: []
  85. },
  86. formData: {
  87. type: Object,
  88. value: () => ({})
  89. },
  90. //主要标识当前表单属于哪个模块,用于传给后端
  91. fieldItemLabel: {
  92. type: String,
  93. default: "",
  94. },
  95. prefixKey: {
  96. type: String,
  97. default: ""
  98. }
  99. },
  100. mounted() {
  101. EventBus.$on("onReagentSubmit",this.onReagentSubmit)
  102. // EventBus.$on("onInstrumentSubmit",this.onInstrumentSubmit)
  103. // EventBus.$on("onMixReagentSubmit",this.onMixReagentSubmit)
  104. },
  105. unmounted() {
  106. EventBus.$off("onReagentSubmit",this.onReagentSubmit)
  107. // EventBus.$off("onInstrumentSubmit",this.onInstrumentSubmit)
  108. // EventBus.$off("onMixReagentSubmit",this.onMixReagentSubmit)
  109. },
  110. data() {
  111. return {
  112. formFields: {},//表单绑定字段
  113. allFieldsConfig: {},//包含config的所有字段,主要用于校验表单是否填写
  114. errors: {},//存储表单错误信息,用于标红提示
  115. orangeBgFields: {},// 存储需要橙色背景的字段
  116. isShowOther,
  117. currentClickKey: "",//当前点击的字段key
  118. uuid:getuuid(),
  119. isRegent,
  120. }
  121. },
  122. methods: {
  123. // //试剂/仪器等弹窗提交
  124. onRegentSubmit(data,key,item){
  125. this.updateFormData(key,data.selectedId);
  126. console.log(data.selectedId,key,"data.selectedId")
  127. if(data.selectType){
  128. this.allFieldsConfig[key].sjSelectType = data.selectType;
  129. }
  130. this.formFields[`selectInfo_${key}`] = data.selectInfo;
  131. console.log(this.formFields,"mmm")
  132. // this.$emit("onRegentSubmit", {selectInfo:data,key,config:item});
  133. },
  134. getRegentItem(item,fieldCode="type"){
  135. const type = item[fieldCode] ;
  136. return {
  137. label: "",
  138. type,
  139. fillType: item.subFillType || item.fillType,
  140. parentLabel: item.label,
  141. }
  142. },
  143. updateZlfzData(key,data){
  144. const ref = this.$refs[`zlSubPackageRef_${key}`][0];
  145. if(ref){
  146. ref.updateFormData(data);
  147. }
  148. },
  149. // 子组件数据更新处理方法
  150. onSubPackageUpdate(data,key){
  151. this.formFields[key] = data;
  152. },
  153. // 重写子组件校验钩子方法,检查ZLSubPackage的表单验证
  154. validateSubComponents() {
  155. const refs = [];
  156. // 遍历formConfig,找到所有type为zlfz的项
  157. for (const item of this.formConfig) {
  158. if (item.config) {
  159. for (const key in item.config) {
  160. const sItem = item.config[key];
  161. if (sItem.type === 'zlfz') {//质量分装
  162. // 根据key构建ref名称
  163. const refName = `zlSubPackageRef_${key}`;
  164. const zlSubPackageRef = this.$refs[refName];
  165. // 检查ZLSubPackage组件的表单验证
  166. if (zlSubPackageRef) {
  167. refs.push(zlSubPackageRef);
  168. }
  169. }
  170. }
  171. }
  172. }
  173. if(refs.length === 0){
  174. return {valid: true, error: ''};
  175. }else{//目前一个步骤只会有一个质量分装,所以不考虑多个的情况
  176. return refs[0][0].validateFormData();
  177. }
  178. },
  179. getSjResource(){
  180. const {allFieldsConfig,formFields} = this;
  181. const sjResource = [],yqResource = [];
  182. for(const key in allFieldsConfig){
  183. const item = allFieldsConfig[key];
  184. if(item.type === "xb" || item.type === "sj" || item.type === "gsp" || item.type === "mix"){
  185. if(formFields[key]){
  186. let o = {
  187. ...formFields[`selectInfo_${key}`],
  188. value:formFields[key],
  189. }
  190. if(item.ylCode){
  191. o.syl = formFields[item.ylCode];//用量
  192. }
  193. if(item.dwCode){
  194. o.syldw = formFields[item.dwCode];//单位
  195. }
  196. sjResource.push(o);
  197. }
  198. }else if(item.type === "yq"){
  199. if(formFields[key]){
  200. yqResource.push({
  201. type:item.type,
  202. value:formFields[key],
  203. ...formFields[`selectInfo_${key}`],
  204. });
  205. }
  206. }
  207. }
  208. console.log(sjResource,yqResource,"sjResource,yqResource")
  209. return {
  210. sjResource,
  211. yqResource,
  212. }
  213. },
  214. // 点击按钮
  215. handleClickButton(e,item){
  216. const {buttonName = ""} = e;
  217. const {config} = item;
  218. if(buttonName === '开始' && config.hasOwnProperty("startDate")){
  219. this.updateFormData("startDate",moment().format('YYYY-MM-DD HH:mm'))
  220. }else if(buttonName === '结束' && config.hasOwnProperty("endDate")){
  221. this.updateFormData("endDate",moment().format('YYYY-MM-DD HH:mm'))
  222. }
  223. this.$emit("clickButton",e,item)
  224. },
  225. // 获取按钮项
  226. getButtonItem(sItem) {
  227. return {
  228. ...sItem,
  229. fillType:sItem.fillType || "actFill",
  230. }
  231. },
  232. // 处理选择试剂/供试品/给药制剂提交
  233. onMixReagentSubmit(data){
  234. if(data.uuid !== this.uuid) return;
  235. this.updateFormData(this.currentClickKey,data.selectedId)
  236. if(data.selectType){
  237. this.allFieldsConfig[this.currentClickKey].sjSelectType = data.selectType;
  238. this.formFields[`selectInfo_${this.currentClickKey}`] = data.selectInfo;
  239. }
  240. this.$emit("onDialogSubmit",data,this.currentClickKey)
  241. },
  242. // 处理选择试剂提交
  243. onReagentSubmit(data){
  244. if(data.uuid !== this.uuid) return;
  245. this.updateFormData(this.currentClickKey,data.selectedId)
  246. },
  247. // 处理选择仪器提交,不确定后续还会不会有其他操作,所以和选择试剂提交区分开。
  248. onInstrumentSubmit(data){
  249. if(data.uuid !== this.uuid) return;
  250. this.updateFormData(this.currentClickKey,data.selectedId)
  251. // this.formFields[this.currentClickKey] = data.selectedId;
  252. this.formFields[`selectInfo_${this.currentClickKey}`] = data.selectInfo;
  253. },
  254. getClickableItem(sItem) {
  255. return {
  256. ...sItem,
  257. type:sItem.type,
  258. }
  259. },
  260. handleClickInstrument(key,type) {
  261. this.currentClickKey = key;
  262. if(type === 'sj'){//试剂
  263. EventBus.$emit("showSelectMixReagentDialog",{
  264. studyFormId:this.templateData.id,
  265. uuid:this.uuid,
  266. sourceFrom:'step',
  267. type:"1"
  268. })
  269. }else if(type === 'gyzj'){//给药制剂
  270. EventBus.$emit("showSelectMixReagentDialog",{
  271. studyFormId:this.templateData.id,
  272. uuid:this.uuid,
  273. sourceFrom:'step',
  274. type:"3"
  275. })
  276. }else if(type === 'mjy'){//麻精药
  277. EventBus.$emit("showSelectMixReagentDialog",{
  278. studyFormId:this.templateData.id,
  279. uuid:this.uuid,
  280. sourceFrom:'step',
  281. type:"5"
  282. })
  283. }else if(type === 'gsp'){//供试品
  284. EventBus.$emit("showSelectMixReagentDialog",{
  285. studyFormId:this.templateData.id,
  286. uuid:this.uuid,
  287. sourceFrom:'step',
  288. type:"7"
  289. })
  290. }else if(type === 'mix'){
  291. EventBus.$emit("showSelectMixReagentDialog",{
  292. studyFormId:this.templateData.id,
  293. uuid:this.uuid,
  294. sourceFrom:'step',
  295. type:"1",
  296. mixType:true,
  297. })
  298. }else if(type === 'xj'){//细菌
  299. EventBus.$emit("showSelectMixReagentDialog",{
  300. studyFormId:this.templateData.id,
  301. uuid:this.uuid,
  302. sourceFrom:'step',
  303. type:"9",
  304. })
  305. }else if(type === 'xb'){//细胞
  306. EventBus.$emit("showSelectMixReagentDialog",{
  307. studyFormId:this.templateData.id,
  308. uuid:this.uuid,
  309. sourceFrom:'step',
  310. type:"11",
  311. })
  312. }else if(type === 'yq'){
  313. EventBus.$emit("showSelectInstrumentDialog",{
  314. studyFormId:this.templateData.id,
  315. uuid:this.uuid,
  316. })
  317. }
  318. },
  319. }
  320. }
  321. </script>
  322. <style lang="scss" scoped>
  323. .step-form-package {
  324. display: flex;
  325. align-items: center;
  326. font-size: 14px;
  327. flex-wrap: wrap;
  328. }
  329. .step-row {
  330. min-width: 180px;
  331. }
  332. .step-item {
  333. display: flex;
  334. align-items: center;
  335. margin-left: 5px;
  336. margin-bottom: 10px;
  337. min-height: 28px;
  338. }
  339. </style>