AddNewRule.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <style lang="less" scoped>
  2. @import "../../less/admin.less";
  3. .AddRuleContent {
  4. width: 100%;
  5. min-width: 1000px;
  6. padding: 20px;
  7. padding-top: 50px;
  8. box-sizing: border-box;
  9. .table_form {
  10. width: 100%;
  11. box-sizing: border-box;
  12. background: #fff;
  13. padding: 20px;
  14. }
  15. /deep/ .el-input--mini .el-input__inner,
  16. .el-select {
  17. width: 100%;
  18. }
  19. .tip_text {
  20. // margin-top: -8px;
  21. font-size: 12px;
  22. color: red;
  23. line-height: 16px;
  24. // transform: scale(.8, .8);
  25. }
  26. .form_btn {
  27. width: 100%;
  28. background: #fff;
  29. padding: 20px 0;
  30. text-align: center;
  31. }
  32. }
  33. </style>
  34. <template>
  35. <div>
  36. <crumbs
  37. :title="title"
  38. :param="$route.params"
  39. linkTo="ZskRuleManager"
  40. ></crumbs>
  41. <div class="AddRuleContent">
  42. <el-form size="mini" :model="form" ref="ruleForm">
  43. <!-- <div class="table_form"> -->
  44. <el-row class="table_form">
  45. <el-col :span="6">
  46. <!-- 规则名称 -->
  47. <el-form-item
  48. label-width="130px"
  49. label="规则名称:"
  50. :rules="rules.parDescription"
  51. prop="parDescription"
  52. >
  53. <el-input
  54. style="width: 100%"
  55. v-model.trim="form.parDescription"
  56. />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="6">
  60. <!-- 规则类型 -->
  61. <el-form-item
  62. label-width="130px"
  63. label="规则类型:"
  64. :rules="rules.parRuleType"
  65. prop="parRuleType"
  66. >
  67. <el-select
  68. v-model="form.parRuleType"
  69. placeholder="请选择"
  70. @change="ruleTypeChange"
  71. >
  72. <el-option
  73. v-for="item in ruleTypeList"
  74. :key="item.id"
  75. :label="item.name"
  76. :value="item.id"
  77. >
  78. </el-option>
  79. </el-select>
  80. <div class="tip_text">
  81. 注:更改规则类型,将会清空已填写的规则内容~
  82. </div>
  83. </el-form-item>
  84. </el-col>
  85. <el-col :span="6">
  86. <!-- 规则术语类型: -->
  87. <el-form-item
  88. label-width="130px"
  89. label="规则术语类型:"
  90. :rules="rules.parLenCode"
  91. prop="parLenCode"
  92. >
  93. <el-select
  94. v-model="form.parLenCode"
  95. placeholder="请选择"
  96. @change="ruleTermChange"
  97. >
  98. <el-option
  99. v-for="item in ruleTermTypeList"
  100. :key="item.id"
  101. :label="item.name"
  102. :value="item.code"
  103. >
  104. </el-option>
  105. </el-select>
  106. <div class="tip_text">
  107. 注:更改规则术语类型,将会清空已填写的规则内容~
  108. </div>
  109. </el-form-item>
  110. </el-col>
  111. <el-col :span="6">
  112. <el-form-item
  113. label-width="130px"
  114. label="医学标准术语:"
  115. style="margin-bottom:50px"
  116. :rules="rules.parConceptId"
  117. prop="parConceptId"
  118. >
  119. <el-select
  120. clearable
  121. filterable
  122. remote
  123. :remote-method="searchConcept"
  124. v-model.trim="form.parConceptId"
  125. @change="parConceptIdChange"
  126. >
  127. <el-option
  128. v-for="item in conceptList"
  129. :key="item.conceptId"
  130. :label="item.conceptName"
  131. :value="item.conceptId"
  132. >
  133. </el-option>
  134. </el-select>
  135. </el-form-item>
  136. </el-col>
  137. <el-col :span="6">
  138. <el-form-item
  139. label-width="130px"
  140. v-if="showHasSub"
  141. label="有无子条件:"
  142. :rules="rules.parHasSub"
  143. prop="parHasSub"
  144. >
  145. <el-select
  146. v-model="form.parHasSub"
  147. placeholder="请选择"
  148. @change="hasSubChange"
  149. >
  150. <el-option label="有" :value="1"></el-option>
  151. <el-option label="无" :value="0"></el-option>
  152. </el-select>
  153. </el-form-item>
  154. </el-col>
  155. <el-col :span="12">
  156. <el-form-item
  157. style="flex: 1; minwidth: 500px"
  158. label-width="130px"
  159. v-if="showMsg"
  160. label="附加信息:"
  161. :rules="rules.parMsg"
  162. prop="parMsg"
  163. >
  164. <el-input
  165. type="textarea"
  166. :rows="1"
  167. placeholder="请输入附加信息"
  168. v-model.trim="form.parMsg"
  169. ></el-input>
  170. </el-form-item>
  171. </el-col>
  172. <!-- 医学标准术语 -->
  173. </el-row>
  174. <!-- </div> -->
  175. <!-- 表格 -->
  176. <AddNewRuleTable
  177. v-if="form.parHasSub"
  178. :klRuleByIdSub="form.klRuleByIdSub"
  179. :maxNum="subRuleMaxNum"
  180. @subTypeChange="subTypeChange"
  181. @searchConcept="searchConcept"
  182. @addGroup="addGroup"
  183. @delGroup="delGroup"
  184. @delGroupChild="delGroupChild"
  185. @setFormData="setFormData"
  186. />
  187. <el-form-item>
  188. <div class="form_btn">
  189. <el-button
  190. type="primary"
  191. size="medium "
  192. @click="submitForm('ruleForm')"
  193. >确定</el-button
  194. >
  195. </div>
  196. </el-form-item>
  197. </el-form>
  198. </div>
  199. </div>
  200. </template>
  201. <script type="text/javascript">
  202. import api from "@api/knowledgeLib.js";
  203. import { formRules } from "./rules";
  204. import AddNewRuleTable from "./AddNewRuleTable";
  205. export default {
  206. name: "AddRule",
  207. data() {
  208. return {
  209. title: "规则维护-添加规则",
  210. ruleTypeList: [], //规则类型列表 1
  211. ruleTermTypeList: [], //规则术语类型列表 2
  212. conceptList: [], //医学标准术语列表 3
  213. baseTypeList: [], //基础规则类型列表 4
  214. baseTermTypeList: [], //基础规则术语类型 5
  215. subRuleMaxNum: null, //规则内容中规则的限制个数
  216. isCopy: false,
  217. parId: null,
  218. msgDict: "", //显示附加信息的类型
  219. firstPlace: null,
  220. form: {
  221. parDescription: "",
  222. parRuleType: "",
  223. parConceptId: "",
  224. parlibName: "",
  225. parLenName: "",
  226. parHasSub: undefined,
  227. parLenCode: "",
  228. parMsg: "",
  229. klRuleByIdSub: []
  230. },
  231. rules: formRules
  232. };
  233. },
  234. created() {
  235. this.getTypeList();
  236. this.setDict();
  237. const param = this.$route.params;
  238. let info = param.data;
  239. if (info) {
  240. this.parId = info.parId;
  241. this.isCopy = param.copy;
  242. this.title = "规则维护-" + (this.isCopy ? "复制" : "修改") + "规则";
  243. this.form = JSON.parse(JSON.stringify(info));
  244. // 编辑初始化选择框
  245. this.initEdidData();
  246. }
  247. },
  248. methods: {
  249. // 编辑初始化
  250. async initEdidData() {
  251. // 规则术语类型初始化
  252. const newruleTermTypeList = await this.ruleTypeList.find(
  253. (it) => it.id == this.form.parRuleType
  254. );
  255. this.ruleTermTypeList = await newruleTermTypeList.subMenuList;
  256. // 基础规则类型初始化
  257. const obj = await this.ruleTermTypeList.find(
  258. (it1) => it1.code == this.form.parLenCode
  259. );
  260. this.baseTypeList = obj.subMenuList;
  261. this.subRuleMaxNum = obj.number;
  262. this.conceptList = [
  263. { conceptName: this.form.parlibName, conceptId: this.form.parConceptId }
  264. ];
  265. if (this.form.parConceptId && this.checkFirstPlace && this.conceptList) {
  266. this.firstPlace = this.conceptList.find(
  267. (it) => it.conceptId === this.form.parConceptId
  268. );
  269. if (this.firstPlace) {
  270. this.firstPlace["checkedType"] = this.ruleTermCodeStr;
  271. }
  272. } else if (!this.form.parConceptId) {
  273. this.setInitGroupData();
  274. this.firstPlace = null;
  275. } else {
  276. this.firstPlace = null;
  277. }
  278. await this.form.klRuleByIdSub.forEach((item, i, arr) => {
  279. item.groupId = "groupId" + item.groupType;
  280. item.groupChildId = "child" + item.subId;
  281. //TODO => 赋值时一定要注意set更新页面
  282. this.$set(item, "baseTypes", [...this.baseTypeList]);
  283. this.$set(
  284. item,
  285. "baseTermTypeList",
  286. item.baseTypes.find((it2) => it2.type === item.subType).subMenuList
  287. );
  288. this.$set(item, "conceptList", [
  289. {
  290. conceptName: item.subLibName || item.subConceptName,
  291. conceptId: item.subConceptId
  292. }
  293. ]);
  294. if (item.subMaxOperator || item.subMinOperator) {
  295. item.dataType = "1";
  296. } else if (item.subEqValue) {
  297. item.dataType = "2";
  298. }
  299. // disable
  300. if (this.form.parHasSub && this.firstPlace) {
  301. if (arr[i - 1] && arr[i - 1].groupId == item.groupId) {
  302. this.$set(item, "disabled", false);
  303. } else {
  304. this.$set(item, "disabled", true);
  305. }
  306. }
  307. });
  308. },
  309. // 提交
  310. submitForm(formName) {
  311. this.$refs[formName].validate((valid) => {
  312. if (valid) {
  313. let params = JSON.parse(JSON.stringify(this.form));
  314. params.klRuleInfoSaveSub = params.klRuleByIdSub;
  315. delete params.klRuleByIdSub;
  316. params.klRuleInfoSaveSub.forEach((item, i, arr) => {
  317. if (i === 0) {
  318. item.groupType = 1;
  319. } else {
  320. if (item.groupId == arr[i - 1].groupId) {
  321. item.groupType = arr[i - 1].groupType;
  322. } else {
  323. item.groupType = arr[i - 1].groupType + 1;
  324. }
  325. }
  326. });
  327. params.klRuleInfoSaveSub.forEach((ite) => {
  328. delete ite.groupId;
  329. delete ite.groupChildId;
  330. delete ite.rowIndex;
  331. delete ite.baseTypes;
  332. delete ite.baseTermTypeList;
  333. delete ite.conceptList;
  334. });
  335. if (this.parId) {
  336. params.parId = this.isCopy ? undefined : this.parId;
  337. params.parStatus = this.isCopy ? 1 : this.form.parStatus;
  338. }
  339. this.saveRule(params);
  340. } else {
  341. return false;
  342. }
  343. });
  344. },
  345. // 子集修改父级的数组
  346. setFormData(index, data) {
  347. this.form.klRuleByIdSub[index].conceptList = data;
  348. },
  349. // table_form 规则类型选中
  350. ruleTypeChange(val) {
  351. this.form.parLenCode = "";
  352. this.form.parMsg = "";
  353. const obj = this.ruleTypeList.find((it) => it.id === val);
  354. this.ruleTermTypeList = obj.subMenuList;
  355. this.subRuleMaxNum = undefined;
  356. this.setInitGroupData();
  357. },
  358. // table_form 规则术语类型选中
  359. ruleTermChange(val) {
  360. this.form.parMsg = "";
  361. const obj = this.ruleTermTypeList.find((it) => it.code === val);
  362. this.form.parLenName = obj.name;
  363. this.baseTypeList = obj.subMenuList;
  364. this.subRuleMaxNum = obj.number;
  365. this.form.parHasSub = obj.subMenuList.length ? 1 : 0;
  366. this.setInitGroupData();
  367. },
  368. // 医学标准术语
  369. parConceptIdChange(val) {
  370. this.$nextTick(() => {
  371. if (val && this.checkFirstPlace && this.conceptList) {
  372. this.firstPlace = this.conceptList.find((it) => it.conceptId === val);
  373. if (this.firstPlace) {
  374. this.firstPlace["checkedType"] = this.ruleTermCodeStr;
  375. }
  376. } else if (!val) {
  377. this.setInitGroupData();
  378. this.firstPlace = null;
  379. } else {
  380. this.firstPlace = null;
  381. }
  382. if (this.form.parHasSub && this.firstPlace) {
  383. const dict =
  384. localStorage
  385. .getItem("zskDicts")
  386. .match(new RegExp(this.firstPlace.checkedType + "-\\d+", "g")) ||
  387. [];
  388. const types = dict[0].split("-");
  389. let obj = this.form.klRuleByIdSub;
  390. obj.forEach((item, i, arr) => {
  391. if (arr[i - 1] && arr[i - 1].groupId == item.groupId) {
  392. this.$set(item, "disabled", false);
  393. } else {
  394. this.$set(item, "disabled", true);
  395. this.$set(item, "subType", parseInt(types[2]));
  396. const subobj = this.baseTypeList.find(
  397. (it) => it.type == types[2]
  398. );
  399. this.$set(item, "baseTermTypeList", subobj.subMenuList);
  400. this.$set(item, "subLenCode", types[1]);
  401. this.$set(item, "subDescription", this.firstPlace.conceptName);
  402. this.$set(item, "subConceptId", this.firstPlace.conceptId);
  403. this.$set(item, "subConceptName", this.firstPlace.conceptName);
  404. this.$set(item, "conceptList", [this.firstPlace]);
  405. }
  406. });
  407. this.$set(this.form, "klRuleByIdSub", obj);
  408. }
  409. });
  410. },
  411. // 初始化表格
  412. setInitGroupData(init) {
  413. const date = new Date().valueOf();
  414. this.$set(this.form, "klRuleByIdSub", [
  415. {
  416. groupId: date,
  417. groupChildId: "child" + new Date().valueOf(),
  418. baseTypes: this.baseTypeList,
  419. baseTermTypeList: [],
  420. conceptList: [],
  421. subDescription: "",
  422. parRuleType: "",
  423. subConceptId: "",
  424. subType: "",
  425. subMaxOperator: "",
  426. subMaxUnit: "",
  427. subMaxValue: "",
  428. subMinOperator: "",
  429. subMinUnit: "",
  430. subMinValue: "",
  431. subEqValue: "",
  432. subLenCode: "",
  433. dataType: ""
  434. }
  435. ]);
  436. if (!init) {
  437. this.form.parConceptId = ""; //医学标准术语清空
  438. this.conceptList = []; //下拉列表清空
  439. }
  440. },
  441. // 有无子条件切换
  442. hasSubChange(val) {
  443. if (val) {
  444. this.setInitGroupData(true);
  445. } else {
  446. this.form.klRuleByIdSub = [];
  447. }
  448. },
  449. // 基础规则类型切换
  450. subTypeChange(val, index) {
  451. // index
  452. const obj = this.baseTypeList.find((it) => it.type === val);
  453. this.form.klRuleByIdSub[index].baseTermTypeList = obj.subMenuList;
  454. this.form.klRuleByIdSub[index].subLenCode = "";
  455. this.form.klRuleByIdSub[index].dataType = "";
  456. this.clearConcept(index);
  457. this.clearNumText(index);
  458. },
  459. clearConcept(index) {
  460. this.form.klRuleByIdSub[index].subConceptId = "";
  461. this.conceptList = [];
  462. },
  463. clearNumText(index) {
  464. this.form.klRuleByIdSub[index].subMaxOperator = "";
  465. this.form.klRuleByIdSub[index].subMaxValue = "";
  466. this.form.klRuleByIdSub[index].subMaxUnit = "";
  467. this.form.klRuleByIdSub[index].subMinOperator = "";
  468. this.form.klRuleByIdSub[index].subMinValue = "";
  469. this.form.klRuleByIdSub[index].subMinUnit = "";
  470. this.form.klRuleByIdSub[index].subEqValue = "";
  471. this.form.klRuleByIdSub[index].subEqOperator = "";
  472. },
  473. // 添加分组 || 规则
  474. addGroup(date, arg = { index: null, groupId: null }) {
  475. /**
  476. * @params
  477. * date:存在则添加规则 不存在则添加分组
  478. * arg:{index:添加规则用索引,groupId:添加分组用确切id}
  479. */
  480. !date && (date = new Date().valueOf());
  481. const obj = {
  482. groupId: date,
  483. groupChildId: "child" + new Date().valueOf(),
  484. baseTypes: this.baseTypeList,
  485. baseTermTypeList: [],
  486. conceptList: [],
  487. subDescription: "",
  488. parRuleType: "",
  489. subConceptId: "",
  490. subType: "",
  491. subMaxOperator: "",
  492. subMaxUnit: "",
  493. subMaxValue: "",
  494. subMinOperator: "",
  495. subMinUnit: "",
  496. subMinValue: "",
  497. subEqValue: "",
  498. subLenCode: "",
  499. dataType: ""
  500. };
  501. if (typeof arg.index == "number") {
  502. // 添加规则 直接在当前位置之后添加
  503. this.form.klRuleByIdSub.splice(arg.index + 1, 0, obj);
  504. } else {
  505. // 添加分组 在列表中相同groupId之后添加
  506. // 添加分组时判断是否需要加disabled和添加默认值
  507. if (this.form.parHasSub && this.firstPlace) {
  508. obj.disabled = true;
  509. const dict =
  510. localStorage
  511. .getItem("zskDicts")
  512. .match(new RegExp(this.firstPlace.checkedType + "-\\d+", "g")) ||
  513. [];
  514. const types = dict[0].split("-");
  515. this.$set(obj, "disabled", true);
  516. this.$set(obj, "subType", parseInt(types[2]));
  517. const subobj = this.baseTypeList.find((it) => it.type == types[2]);
  518. this.$set(obj, "baseTermTypeList", subobj.subMenuList);
  519. this.$set(obj, "subLenCode", types[1]);
  520. this.$set(obj, "subDescription", this.firstPlace.conceptName);
  521. this.$set(obj, "subConceptId", this.firstPlace.conceptId);
  522. this.$set(obj, "subConceptName", this.firstPlace.conceptName);
  523. this.$set(obj, "conceptList", [this.firstPlace]);
  524. }
  525. var i = -1;
  526. this.form.klRuleByIdSub.forEach((item, inx) => {
  527. if (item.groupId === arg.groupId) {
  528. i = inx;
  529. }
  530. });
  531. this.form.klRuleByIdSub.splice(i + 1, 0, obj);
  532. }
  533. },
  534. // 删除分组
  535. delGroup(groupId) {
  536. const list = this.form.klRuleByIdSub.filter(
  537. (item) => item.groupId != groupId
  538. );
  539. this.form.klRuleByIdSub = list;
  540. },
  541. // 删除规则
  542. delGroupChild(groupChildId) {
  543. const newGroupList = this.form.klRuleByIdSub.filter(
  544. (item) => item.groupChildId != groupChildId
  545. );
  546. this.form.klRuleByIdSub = newGroupList;
  547. },
  548. setDict() {
  549. this.dict = localStorage.getItem("zskDicts");
  550. this.msgDict = localStorage.getItem("zskMsgDict");
  551. this.subDict = localStorage.getItem("zskSubDict");
  552. },
  553. showConfirmDialog(msg, resolve) {
  554. this.$alert(msg, "提示", {
  555. confirmButtonText: "确定",
  556. type: "warning"
  557. })
  558. .then(() => {
  559. resolve();
  560. })
  561. .catch(() => {});
  562. },
  563. searchConcept(val) {
  564. const param = {
  565. excludedConceptIds: [this.form.parRuleType],
  566. libType: this.form.parLenCode,
  567. name: val
  568. };
  569. api
  570. .searchConcept(param)
  571. .then((res) => {
  572. if (res.data.code == "0") {
  573. const data = res.data.data;
  574. this.conceptList = data;
  575. }
  576. })
  577. .catch((error) => {
  578. console.log(error);
  579. });
  580. },
  581. getTypeList() {
  582. this.ruleTypeList = JSON.parse(localStorage.getItem("zskTypesList"));
  583. },
  584. saveRule(params) {
  585. api.saveRule(params).then((res) => {
  586. if (res.data.code == 0) {
  587. this.$message({
  588. message: "操作成功",
  589. type: "success"
  590. });
  591. this.$router.push({
  592. name: "ZskRuleManager",
  593. params: Object.assign({}, this.$route.params, { currentPage: 1 })
  594. });
  595. } else {
  596. this.$message({
  597. message: res.data.msg,
  598. type: "warning"
  599. });
  600. }
  601. });
  602. }
  603. },
  604. watch: {
  605. "form.klRuleByIdSub": {
  606. handler(val) {
  607. this.form.klRuleByIdSub.forEach((item, i, arr) => {
  608. if (i == 0) {
  609. item.rowIndex = 1;
  610. } else if (item.groupId == arr[i - 1].groupId) {
  611. item.rowIndex = arr[i - 1].rowIndex;
  612. } else {
  613. item.rowIndex = arr[i - 1].rowIndex + 1;
  614. }
  615. });
  616. },
  617. deep: true
  618. },
  619. "form.parHasSub"(val) {
  620. if (!val || val == 0) {
  621. this.form.klRuleByIdSub = [];
  622. }
  623. }
  624. },
  625. computed: {
  626. disable: function () {
  627. return Object.keys(this.firstPlace || {}).length > 0;
  628. },
  629. ruleTermCodeStr: function () {
  630. return this.form.parRuleType + "-" + this.form.parLenCode;
  631. },
  632. showMsg: function () {
  633. return (
  634. this.ruleTermCodeStr.length > 1 &&
  635. this.msgDict.indexOf(this.ruleTermCodeStr) > -1
  636. );
  637. },
  638. showHasSub() {
  639. return this.subDict.indexOf(this.ruleTermCodeStr) > -1;
  640. },
  641. checkFirstPlace: function () {
  642. return this.dict.indexOf(this.ruleTermCodeStr) > -1;
  643. }
  644. },
  645. components: { AddNewRuleTable }
  646. };
  647. </script>