_AddNewRule.vue 17 KB

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