pathDialog.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <el-dialog title="选择轨迹" :visible.sync="open" width="25%" :before-close="onClose" :modal="false"
  3. :close-on-click-modal="false">
  4. <el-form ref="form" :model="selectRecord" label-width="100px" size="mini">
  5. <el-form-item label="选择轨迹">
  6. <el-select v-model="dataParams.pathId" @change="switchTrack">
  7. <el-option v-for="item in trackList" :key="item.id" :label="getPathName(item.pathSort)"
  8. :value="item.id">
  9. </el-option>
  10. </el-select>
  11. </el-form-item>
  12. <el-form-item label="轨迹起点">
  13. <el-select v-model="dataParams.pathStartJson" value-key="name" @change="switchStartPoint">
  14. <el-option v-for="(item, index) in selectTrack.startPoints" :key="index" :label="item.name"
  15. :value="item" :disabled="checkOption(selectTrack.id, item.name, 'start')">
  16. </el-option>
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item label="轨迹终点">
  20. <el-select v-model="dataParams.pathEndJson" value-key="name" @change="switchEndPoint">
  21. <el-option v-for="(item, index) in selectTrack.endPoints" :key="index" :label="item.name"
  22. :value="item" :disabled="checkOption(selectTrack.id, item.name, 'end')">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="车辆朝向">
  27. <el-input v-model="dataParams.pathStartJson.h" disabled></el-input>
  28. </el-form-item>
  29. </el-form>
  30. <span slot="footer" class="dialog-footer">
  31. <el-button @click="onClose">取 消</el-button>
  32. <el-button type="primary" @click="onSubmit">确 定</el-button>
  33. </span>
  34. </el-dialog>
  35. </template>
  36. <script>
  37. export default {
  38. name: "PathDialog",
  39. components: {
  40. // vueQr,
  41. // glHome,
  42. },
  43. data() {
  44. return {
  45. selectRecord: {
  46. pathStartJson: {
  47. }
  48. },
  49. trackList: [],
  50. selectTrack: {},
  51. dataParams: {
  52. pathId: "",
  53. pathStartJson: {},
  54. pathEndJson: {}
  55. },
  56. preStartPointName: "",
  57. preEndPointName: ""
  58. };
  59. },
  60. props: {
  61. open: {
  62. type: Boolean,
  63. default: _ => false
  64. },
  65. params: {
  66. type: Object,
  67. default: _ => {}
  68. }
  69. },
  70. computed: {
  71. getPathName() {
  72. return id => "轨迹" + id;
  73. }
  74. },
  75. methods: {
  76. checkOption(pathId, pointName, type) {
  77. if (!this.dataParams.selectedPoints[pathId]) {
  78. return false;
  79. }
  80. if (!this.dataParams.selectedPoints[pathId][type]) {
  81. return false;
  82. }
  83. return this.dataParams.selectedPoints[pathId][type].includes(pointName);
  84. },
  85. isEmptyJson(obj) {
  86. return Object.keys(obj).length === 0;
  87. },
  88. getMapDetails(mapId) {
  89. this.$axios({
  90. method: "post",
  91. url: this.$api.workManagement.mapDetails,
  92. data: {
  93. mapId
  94. }
  95. }).then((res) => {
  96. if (res.code == 200 && res.info) {
  97. console.log(res.info.path)
  98. this.trackList = res.info.path;
  99. this.switchTrack(this.params.pathId);
  100. }
  101. })
  102. },
  103. switchTrack(id) {
  104. let isFirst = this.isEmptyJson(this.selectTrack);
  105. this.trackList.forEach((elem, index) => {
  106. if (elem.id == id) {
  107. this.selectTrack = elem;
  108. }
  109. });
  110. if (!isFirst) {
  111. this.dataParams.pathStartJson = {};
  112. this.dataParams.pathEndJson = {};
  113. }
  114. this.changeMap();
  115. },
  116. switchStartPoint(newVal) {
  117. console.log(this.selectTrack)
  118. let pointNames = this.dataParams.selectedPoints[this.selectTrack.id]["start"];
  119. let searchIndex = pointNames.indexOf(this.preStartPointName);
  120. if (searchIndex != -1) {
  121. pointNames.splice(searchIndex, 1);
  122. }
  123. pointNames.push(newVal.name)
  124. this.preStartPointName = newVal.name;
  125. this.changeMap();
  126. },
  127. switchEndPoint(newVal) {
  128. let pointNames = this.dataParams.selectedPoints[this.selectTrack.id]["end"];
  129. let searchIndex = pointNames.indexOf(this.preEndPointName);
  130. if (searchIndex != -1) {
  131. pointNames.splice(searchIndex, 1);
  132. }
  133. pointNames.push(newVal.name)
  134. this.preEndPointName = newVal.name;
  135. this.changeMap();
  136. },
  137. changeMap() {
  138. let data = Object.assign({}, this.dataParams, {
  139. sections: this.selectTrack.sections
  140. })
  141. data.pathStartJson.type = "start";
  142. data.pathEndJson.type = "end";
  143. this.$emit("change", data);
  144. },
  145. onClose() {
  146. this.$emit("onClose");
  147. },
  148. onSubmit() {
  149. this.$emit("onSubmit", Object.assign({}, this.dataParams, {
  150. sections: this.selectTrack.sections,
  151. pathSort: this.selectTrack.pathSort
  152. }));
  153. }
  154. },
  155. watch: {
  156. params: {
  157. handler(newVal, oldVal) {
  158. this.selectTrack = {},
  159. this.dataParams = JSON.parse(JSON.stringify(newVal));
  160. this.preStartPointName = this.dataParams.pathStartJson.name;
  161. this.preEndPointName = this.dataParams.pathEndJson.name;
  162. this.getMapDetails(newVal.mapId);
  163. }
  164. }
  165. }
  166. }
  167. </script>
  168. <style>
  169. </style>