yxyzPop.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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="value"
  21. ref="tree"
  22. ></el-tree>
  23. </el-scrollbar>
  24. </el-col>
  25. <el-col :span="2">
  26. <div class="grid-content bg_purple">
  27. <el-button
  28. icon="el-icon-d-arrow-right"
  29. @click="turnLeftToRight"
  30. ></el-button>
  31. <el-button
  32. icon="el-icon-d-arrow-left"
  33. @click="turnRightToLeft"
  34. ></el-button>
  35. </div>
  36. </el-col>
  37. <el-col :span="16">
  38. <div class="yztitle">已选因子</div>
  39. <el-table
  40. :data="dialogData"
  41. border
  42. class="right-table scroll-style"
  43. size="small"
  44. style="width: 100%"
  45. @selection-change="handleSelectionChange"
  46. >
  47. <el-table-column type="selection" width="55" align="center">
  48. </el-table-column>
  49. <el-table-column prop="yxyzmc" label="因子名称"> </el-table-column>
  50. <el-table-column prop="spatial_type" label="条件" width="150">
  51. <template slot-scope="scope">
  52. <el-select
  53. v-model="scope.row.spatial_type"
  54. placeholder="请选择"
  55. class="input-style"
  56. v-if="
  57. scope.row.spatial_type == 'identity' ||
  58. scope.row.spatial_type == 'n_identity'
  59. "
  60. >
  61. <el-option
  62. v-for="item in conditionList1"
  63. :key="item.value"
  64. :label="item.label"
  65. :value="item.value"
  66. >
  67. </el-option>
  68. </el-select>
  69. <el-select
  70. v-model="scope.row.spatial_type"
  71. placeholder="请选择"
  72. class="input-style"
  73. v-if="
  74. scope.row.spatial_type == 'contain' ||
  75. scope.row.spatial_type == 'n_contain'
  76. "
  77. >
  78. <el-option
  79. v-for="item in conditionList2"
  80. :key="item.value"
  81. :label="item.label"
  82. :value="item.value"
  83. >
  84. </el-option>
  85. </el-select>
  86. </template>
  87. </el-table-column>
  88. <el-table-column prop="yxz" label="约束值(m)" width="120">
  89. <template slot-scope="scope">
  90. <el-input
  91. Onkeyup="this.value=this.value.replace(/[^\d^\.]+/g,'').replace(/^0+(\d)/,'$1').replace(/^\./,'0.').match(/\d+.?\d{0,2}/);this.dispatchEvent(new Event('input'))"
  92. v-model="scope.row.yxz"
  93. placeholder="距离"
  94. class="input-style font-14"
  95. ></el-input>
  96. <!-- :disabled="scope.row.condition == 'F'" -->
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. </el-col>
  101. </el-row>
  102. <span slot="footer" class="dialog-footer">
  103. <el-button @click="close">取 消</el-button>
  104. <el-button type="primary" @click="submit">确 定</el-button>
  105. </span>
  106. </el-dialog>
  107. </div>
  108. </template>
  109. <script>
  110. import { GetFxyzList } from "../../../api/ghss/ghxz.js";
  111. export default {
  112. components: {},
  113. props: {
  114. tableData: {
  115. type: Array,
  116. },
  117. },
  118. data() {
  119. return {
  120. defaultProps: {
  121. children: "children",
  122. label: "yxyzmc",
  123. },
  124. dialogVisible: false,
  125. options: [],
  126. kxyzList: [],
  127. tempList: [],
  128. optionsTemp: [],
  129. selectdialogData: [],
  130. dialogData: [],
  131. conditionList1: [
  132. { label: "范围内", value: "identity" },
  133. { label: "范围外", value: "n_identity" },
  134. ],
  135. conditionList2: [
  136. { label: "距离包含", value: "contain" },
  137. { label: "距离不包含", value: "n_contain" },
  138. ],
  139. };
  140. },
  141. computed: {
  142. conditionList(val) {
  143. if (val == "identity") {
  144. return this.conditionList1;
  145. } else {
  146. return this.conditionList2;
  147. }
  148. },
  149. },
  150. mounted() {
  151. this.GetFxyzList();
  152. },
  153. methods: {
  154. close() {
  155. this.dialogVisible = false;
  156. },
  157. GetFxyzList() {
  158. GetFxyzList().then((res) => {
  159. this.kxyzList = res.data;
  160. this.tempList = JSON.parse(JSON.stringify(res.data));
  161. this.getTreeList();
  162. });
  163. },
  164. getTreeList() {
  165. function arrayToTreeLoop(nodes) {
  166. const map = {};
  167. const tree = [];
  168. for (const node of nodes) {
  169. map[node.bsm] = { ...node, children: [] };
  170. }
  171. for (const node of Object.values(map)) {
  172. if (node.parent_bsm === null) {
  173. tree.push(node);
  174. } else {
  175. map[node.parent_bsm].children.push(node);
  176. }
  177. }
  178. return tree;
  179. }
  180. this.options = arrayToTreeLoop(this.kxyzList);
  181. this.optionsTemp = JSON.parse(JSON.stringify(this.options));
  182. },
  183. getList() {
  184. // yzlist().then((res) => {
  185. // if (res.success) {
  186. this.tempList.forEach((item) => {
  187. var num = item.lx == "FZXZ01" ? 0 : item.lx == "FZXZ02" ? 1 : 2;
  188. this.options[num].children.push({
  189. type: num,
  190. value: item.bsm,
  191. label: item.yxyzmc,
  192. sjlx: item.sjlx,
  193. yztj: item.yztj,
  194. sjy: item.sjy,
  195. });
  196. });
  197. this.optionsTemp = JSON.parse(JSON.stringify(this.options));
  198. // }
  199. // });
  200. },
  201. setTable(selectdata) {
  202. let tableList = [];
  203. selectdata.forEach((item) => {
  204. console.log(item, "item----");
  205. tableList.push({
  206. // id: item.bsm,
  207. // name: item.yxyzmc,
  208. // condition: item.spatial_type,
  209. // value: "",
  210. // sjy: item.has_yxz,
  211. // sjlx: item.spatial_type,
  212. yzbsm: item.bsm,
  213. yxyzmc: item.yxyzmc,
  214. spatial_type: item.spatial_type,
  215. yxz: "",
  216. });
  217. });
  218. tableList.forEach((item) => {
  219. this.resetTree(this.options, item);
  220. });
  221. this.removeChildrenZero(this.options);
  222. return tableList;
  223. },
  224. resetTree(data, item1) {
  225. data.forEach((item, index) => {
  226. if (item.bsm == item1.id) {
  227. data.splice(index, 1);
  228. }
  229. if (item.children != undefined && item.children.length != 0) {
  230. this.resetTree(item.children, item1);
  231. }
  232. });
  233. },
  234. removeChildrenZero(data) {
  235. data.forEach((item, index) => {
  236. if (item.children != undefined && item.children.length == 0) {
  237. if (item.disabled != undefined) {
  238. item.disabled = true;
  239. }
  240. }
  241. if (item.children != undefined && item.children.length > 0) {
  242. this.removeChildrenZero(item.children);
  243. }
  244. });
  245. },
  246. turnLeftToRight() {
  247. if (this.$refs.tree.getCheckedNodes().length == 0) {
  248. this.$message.warning("请勾选可选因子");
  249. return false;
  250. }
  251. let list = this.$refs.tree.getCheckedNodes().filter((item) => {
  252. return item.children == undefined || item.children.length == 0;
  253. });
  254. list = this.setTable(list);
  255. this.dialogData = [...this.dialogData, ...list];
  256. },
  257. turnRightToLeft() {
  258. if (this.selectdialogData.length == 0) {
  259. this.$message.warning("请勾选已选因子");
  260. return false;
  261. }
  262. let list = this.dialogData;
  263. this.selectdialogData.forEach((item) => {
  264. list = list.filter((item1) => {
  265. return item.id != item1.id;
  266. });
  267. });
  268. this.dialogData = list;
  269. this.options = JSON.parse(JSON.stringify(this.optionsTemp));
  270. list.forEach((item) => {
  271. this.resetTree(this.options, item);
  272. });
  273. },
  274. handleSelectionChange(val) {
  275. this.selectdialogData = val;
  276. },
  277. submit() {
  278. var sign = true;
  279. this.dialogData.forEach((item) => {
  280. item.type && item.value == "" && (sign = false);
  281. });
  282. if (sign) {
  283. // parent.emit("update:tableData", this.dialogData);
  284. // parent.emit("update:dialogVisible", false);
  285. this.$parent.tableData = this.dialogData;
  286. this.dialogVisible = false;
  287. } else {
  288. this.$message.warning("请将信息补充完整!");
  289. }
  290. },
  291. setData(data) {
  292. data.filter((item) => {
  293. this.clearitem(item);
  294. });
  295. },
  296. clearitem(item) {
  297. this.options[0].children = this.options[0].children.filter((item1) => {
  298. return item.id != item1.value;
  299. });
  300. this.options[1].children = this.options[1].children.filter((item1) => {
  301. return item.id != item1.value;
  302. });
  303. this.options[0].children.length == 0
  304. ? (this.options[0].disabled = true)
  305. : (this.options[0].disabled = false);
  306. this.options[1].children.length == 0
  307. ? (this.options[1].disabled = true)
  308. : (this.options[1].disabled = false);
  309. },
  310. },
  311. watch: {
  312. dialogVisible(oldVal, newVal) {
  313. if (this.tableData.length == []) {
  314. // 重置时,树的数据恢复
  315. this.dialogData = [];
  316. this.options = JSON.parse(JSON.stringify(this.optionsTemp));
  317. this.selectdialogData = [];
  318. } else {
  319. // 选择模板时,生成新的树
  320. this.dialogData = JSON.parse(JSON.stringify(this.tableData));
  321. this.setData(this.dialogData);
  322. }
  323. },
  324. },
  325. };
  326. </script>
  327. <style lang="scss" scoped>
  328. .hgxsc {
  329. height: 100%;
  330. }
  331. .yztitle {
  332. color: #fff !important;
  333. }
  334. .dialog {
  335. /deep/.el-dialog__body {
  336. color: #fff !important;
  337. }
  338. .left-tree {
  339. height: 400px;
  340. overflow-y: auto;
  341. margin-top: 10px;
  342. border: 1px solid #ddd;
  343. .el-tree {
  344. margin-top: 10px;
  345. .el-tree-node__content {
  346. height: 35px;
  347. line-height: 35px;
  348. }
  349. }
  350. }
  351. /deep/.el-dialog__body {
  352. padding: 10px 30px;
  353. }
  354. .bg_purple {
  355. display: flex;
  356. flex-direction: column;
  357. align-items: center;
  358. justify-content: center;
  359. height: 400px;
  360. .el-button + .el-button {
  361. margin-left: 0;
  362. margin-top: 20px;
  363. }
  364. }
  365. .right-table {
  366. margin-top: 10px;
  367. height: 400px;
  368. /deep/ .el-table__inner-wrapper {
  369. height: 100%;
  370. }
  371. /deep/.el-table__header-wrapper,
  372. .el-table__header {
  373. height: 40px;
  374. }
  375. /deep/.el-table__body-wrapper {
  376. height: calc(100% - 40px);
  377. overflow-y: auto;
  378. }
  379. }
  380. }
  381. /deep/.el-dialog__body {
  382. color: #fff !important;
  383. }
  384. </style>