AddNewRule.vue 20 KB

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