zdyModelPop.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <div class="dialog">
  3. <el-dialog
  4. title="自定义模型"
  5. :visible.sync="dialogVisible"
  6. width="40%"
  7. :before-close="close"
  8. :modal-append-to-body="false"
  9. :close-on-click-modal="false"
  10. >
  11. <div class="modelTitle">
  12. <div class="siteCon">
  13. <span>分析模型名称:</span>
  14. </div>
  15. <el-input
  16. v-model="fxmxmc"
  17. size="mini"
  18. placeholder="请输入项目名称"
  19. ></el-input>
  20. </div>
  21. <el-row>
  22. <el-col :span="11">
  23. <div class="yztitle">请选择分析数据</div>
  24. <el-scrollbar class="left-tree">
  25. <el-input placeholder="输入查询内容" v-model="filterText" clearable>
  26. </el-input>
  27. <el-tree
  28. :data="options"
  29. :props="defaultProps"
  30. highlight-current
  31. show-checkbox
  32. node-key="id"
  33. ref="tree"
  34. :default-checked-keys="defaultArr"
  35. :filter-node-method="filterNode"
  36. ></el-tree>
  37. </el-scrollbar>
  38. </el-col>
  39. <el-col :span="2">
  40. <div class="grid-content bg_purple">
  41. <el-button
  42. icon="el-icon-d-arrow-right"
  43. @click="turnLeftToRight"
  44. ></el-button>
  45. <el-button
  46. icon="el-icon-d-arrow-left"
  47. @click="turnRightToLeft"
  48. ></el-button>
  49. </div>
  50. </el-col>
  51. <el-col :span="11">
  52. <div class="yztitle">已选数据</div>
  53. <el-table
  54. ref="multipleTable"
  55. :data="dialogData"
  56. border
  57. class="right-table scroll-style"
  58. size="small"
  59. style="width: 100%"
  60. @selection-change="handleSelectionChange"
  61. >
  62. <el-table-column type="selection" width="55" align="center">
  63. </el-table-column>
  64. <el-table-column prop="name" label="数据名称"> </el-table-column>
  65. </el-table>
  66. </el-col>
  67. </el-row>
  68. <span slot="footer" class="dialog-footer">
  69. <el-button @click="reset">重置</el-button>
  70. <el-button type="primary" @click="submit">确 定</el-button>
  71. </span>
  72. </el-dialog>
  73. </div>
  74. </template>
  75. <script>
  76. import { GetFactorList } from "../../../api/ghss/gdbh.js";
  77. export default {
  78. components: {},
  79. props: {
  80. tableData: {
  81. type: Array,
  82. },
  83. editData: {
  84. //editData用来存储编辑的数据,用bsm判断是否为编辑,全部存储是为了防止以后新增需求
  85. type: Object,
  86. },
  87. },
  88. data() {
  89. return {
  90. fxmxmc: "", //分析模型名称
  91. filterText: "", //树结构搜索关键字
  92. defaultProps: {
  93. children: "children",
  94. label: "name",
  95. },
  96. dialogVisible: false,
  97. options: [],
  98. kxyzList: [],
  99. tempList: [],
  100. optionsTemp: [],
  101. selectdialogData: [],
  102. dialogData: [],
  103. defaultArr: [], //用地类型选中后可选因子默认勾选的值
  104. yzTableData: [], //用地类型选中后影响因子对应的值
  105. };
  106. },
  107. computed: {},
  108. mounted() {
  109. this.GetFactorList();
  110. },
  111. methods: {
  112. //树结构过滤
  113. filterNode(value, data) {
  114. if (!value) return true;
  115. return data.name.indexOf(value) !== -1;
  116. },
  117. reset() {
  118. console.log(898888);
  119. this.$parent.templateYZ = [];
  120. this.filterText = ""; //还原分析数据搜索框
  121. this.fxmxmc = ""; //清空分析模型名称输入框
  122. this.yzTableData = [];
  123. this.GetFactorList(); //重新获取分析数据
  124. this.dialogData = []; //清空已选数据表单
  125. console.log(this.dialogData, "到货时间肯定会撒");
  126. },
  127. testInput(val) {
  128. val = Number(val);
  129. },
  130. close() {
  131. this.dialogVisible = false;
  132. this.reset();
  133. },
  134. GetFactorList() {
  135. GetFactorList().then((res) => {
  136. this.kxyzList = res.data;
  137. this.tempList = JSON.parse(JSON.stringify(res.data));
  138. this.getTreeList();
  139. });
  140. },
  141. getTreeList() {
  142. function arrayToTreeLoop(nodes) {
  143. const map = {};
  144. const tree = [];
  145. for (const node of nodes) {
  146. map[node.id] = { ...node, children: [] };
  147. }
  148. for (const node of Object.values(map)) {
  149. if (node.parentId == "") {
  150. tree.push(node);
  151. } else {
  152. map[node.parentId].children.push(node);
  153. map[node.parentId].parentNode = true;
  154. }
  155. }
  156. return tree;
  157. }
  158. this.options = arrayToTreeLoop(this.kxyzList);
  159. this.optionsTemp = JSON.parse(JSON.stringify(this.options));
  160. },
  161. setTable(selectdata) {
  162. let tableList = [];
  163. selectdata.forEach((item) => {
  164. tableList.push({
  165. id: item.id,
  166. name: item.name,
  167. bsm: item.bsm,
  168. // conditionInfo: JSONItem,
  169. });
  170. });
  171. tableList.forEach((item) => {
  172. this.resetTree(this.options, item);
  173. });
  174. this.removeChildrenZero(this.options);
  175. return tableList;
  176. },
  177. resetTree(data, item1) {
  178. data.forEach((item, index) => {
  179. if (item.id == item1.id) {
  180. data.splice(index, 1);
  181. }
  182. if (item.children != undefined && item.children.length != 0) {
  183. this.resetTree(item.children, item1);
  184. }
  185. });
  186. },
  187. removeChildrenZero(data) {
  188. data.forEach((item, index) => {
  189. if (item.children != undefined && item.children.length == 0) {
  190. if (item.parentNode) {
  191. item.disabled = true;
  192. if (this.$refs.tree) {
  193. //用地类型绑定后易出现找不到tree的情况
  194. this.$refs.tree.setCheckedKeys([]);
  195. }
  196. }
  197. }
  198. if (item.children != undefined && item.children.length > 0) {
  199. this.removeChildrenZero(item.children);
  200. }
  201. });
  202. },
  203. turnLeftToRight() {
  204. if (this.$refs.tree.getCheckedNodes().length == 0) {
  205. this.$message.warning("请勾选可选因子");
  206. return false;
  207. }
  208. let list = this.$refs.tree.getCheckedNodes().filter((item) => {
  209. return item.children == undefined || item.children.length == 0;
  210. });
  211. list = this.setTable(list);
  212. this.dialogData = [...this.dialogData, ...list];
  213. },
  214. turnRightToLeft() {
  215. if (this.selectdialogData.length == 0) {
  216. this.$message.warning("请勾选已选因子");
  217. return false;
  218. }
  219. let list = this.dialogData;
  220. this.selectdialogData.forEach((item) => {
  221. list = list.filter((item1) => {
  222. return item.id != item1.id;
  223. });
  224. });
  225. this.dialogData = list; //去掉勾选元素
  226. this.options = JSON.parse(JSON.stringify(this.optionsTemp));
  227. list.forEach((item) => {
  228. this.resetTree(this.options, item);
  229. });
  230. if (this.$refs.tree) this.$refs.tree.setCheckedKeys([]);
  231. },
  232. handleSelectionChange(val) {
  233. this.selectdialogData = val;
  234. },
  235. submit() {
  236. let saveData = {
  237. bsm: new Date().getTime(),
  238. bsmmc: this.fxmxmc,
  239. gdbhMxYzRet: this.dialogData,
  240. };
  241. if (this.editData.bsm) {
  242. //判断是否为编辑状态
  243. this.$parent.anaModels.forEach((item) => {
  244. if (item.bsm == this.editData.bsm) {
  245. this.$parent.anaModels[item] = saveData; //替换数据
  246. }
  247. });
  248. this.dialogVisible = false;
  249. } else {
  250. this.$parent.anaModels.push(saveData);
  251. this.dialogVisible = false;
  252. }
  253. this.$refs.multipleTable.clearSelection();//清空勾选
  254. },
  255. setData(data) {
  256. data.filter((item) => {
  257. this.clearitem(item);
  258. });
  259. },
  260. clearitem(item) {
  261. this.options[0].children = this.options[0].children.filter((item1) => {
  262. return item.id != "";
  263. });
  264. this.options[1].children = this.options[1].children.filter((item1) => {
  265. return item.id != ""; //item1.defaultValue
  266. });
  267. this.options[0].children.length == 0
  268. ? (this.options[0].disabled = true)
  269. : (this.options[0].disabled = false);
  270. this.options[1].children.length == 0
  271. ? (this.options[1].disabled = true)
  272. : (this.options[1].disabled = false);
  273. },
  274. resetDialogData() {
  275. if (!this.tableData.length) {
  276. // 重置时,树的数据恢复
  277. this.dialogData = [];
  278. this.options = JSON.parse(JSON.stringify(this.optionsTemp));
  279. this.selectdialogData = [];
  280. } else {
  281. // 选择模板时,生成新的树
  282. this.dialogData = JSON.parse(JSON.stringify(this.tableData));
  283. this.options = JSON.parse(JSON.stringify(this.optionsTemp));
  284. }
  285. this.dialogData.forEach((item) => {
  286. this.resetTree(this.options, item);
  287. });
  288. this.removeChildrenZero(this.options);
  289. return this.dialogData;
  290. },
  291. },
  292. watch: {
  293. //监听树结构过滤的关键字
  294. filterText(val) {
  295. this.$refs.tree.filter(val);
  296. },
  297. // dialogVisible(oldVal, newVal) {
  298. // if (newVal) this.resetDialogData();
  299. // },
  300. yzTableData(oldVal, newVal) {
  301. let idArr = [];
  302. this.yzTableData.forEach((item) => {
  303. idArr.push(item.id);
  304. });
  305. this.defaultArr = idArr;
  306. this.resetDialogData();
  307. },
  308. },
  309. };
  310. </script>
  311. <style lang="scss" scoped>
  312. .hgxsc {
  313. height: 100%;
  314. }
  315. .yztitle {
  316. color: #fff !important;
  317. }
  318. .dialog {
  319. /deep/.el-dialog__body {
  320. color: #fff !important;
  321. }
  322. .left-tree {
  323. height: 400px;
  324. overflow-y: auto;
  325. margin-top: 10px;
  326. border: 1px solid #ddd;
  327. .el-tree {
  328. margin-top: 10px;
  329. .el-tree-node__content {
  330. height: 35px;
  331. line-height: 35px;
  332. }
  333. }
  334. }
  335. /deep/.el-dialog__body {
  336. padding: 10px 30px;
  337. }
  338. .bg_purple {
  339. display: flex;
  340. flex-direction: column;
  341. align-items: center;
  342. justify-content: center;
  343. height: 400px;
  344. .el-button + .el-button {
  345. margin-left: 0;
  346. margin-top: 20px;
  347. }
  348. }
  349. .right-table {
  350. margin-top: 10px;
  351. height: 400px;
  352. overflow: hidden;
  353. overflow-y: auto;
  354. /deep/ .el-table__inner-wrapper {
  355. height: 100%;
  356. }
  357. /deep/.el-table__header-wrapper,
  358. .el-table__header {
  359. height: 40px;
  360. }
  361. /deep/.el-table__body-wrapper {
  362. height: calc(100% - 40px);
  363. overflow-y: auto;
  364. }
  365. }
  366. }
  367. /deep/.el-dialog__body {
  368. color: #fff !important;
  369. }
  370. /* 去除Element UI中el-input数字类型的样式 */
  371. /deep/ .el-input__inner[type="number"] {
  372. -webkit-appearance: none;
  373. /* 移除系统默认的外观样式 */
  374. }
  375. /* 去除增加/减少数字按钮的样式 */
  376. /deep/ .el-input__inner[type="number"]::-webkit-inner-spin-button,
  377. .el-input__inner[type="number"]::-webkit-outer-spin-button {
  378. -webkit-appearance: none;
  379. /* 移除输入框两侧的上下箭头 */
  380. margin: 0;
  381. /* 移除上下箭头与文本之间的间隔 */
  382. }
  383. /* 去除Firefox浏览器中的一些特定样式 */
  384. /deep/ .el-input__inner[type="number"]::-moz-inner-spin-button {
  385. -moz-appearance: none;
  386. /* 移除Firefox中的上下箭头 */
  387. }
  388. .clearBtn {
  389. padding: 12px 20px;
  390. border-radius: 4px;
  391. cursor: pointer;
  392. width: 30%;
  393. background-color: #3f94f53f;
  394. border: 1px solid #3f93f5;
  395. color: #b6e0ff;
  396. &:hover {
  397. font-weight: bold;
  398. }
  399. }
  400. .modelTitle {
  401. color: #fff;
  402. /deep/ .el-input__inner {
  403. max-width: 100%;
  404. color: #fff;
  405. background: #041c3273 !important;
  406. border: 1px dashed #0f7ac8 !important;
  407. }
  408. width: 100%;
  409. height: 40px;
  410. color: #fff;
  411. font-weight: 400;
  412. font-size: 16px;
  413. display: flex;
  414. justify-content: space-between;
  415. .siteCon {
  416. width: 140px;
  417. display: flex;
  418. justify-content: flex-start;
  419. span {
  420. display: inline-block;
  421. }
  422. }
  423. }
  424. </style>