AddNewRule.vue 21 KB

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