yxyzPop.vue 13 KB

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