index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <div class="app-container">
  3. <!--工具栏-->
  4. <div class="head-container">
  5. <div v-if="crud.props.searchToggle">
  6. <el-input
  7. v-model="query.code"
  8. clearable
  9. size="small"
  10. placeholder="输入高后果区编号"
  11. style="width: 160px"
  12. class="filter-item"
  13. @keyup.enter.native="crud.toQuery"
  14. />
  15. <el-input
  16. v-model="query.name"
  17. clearable
  18. size="small"
  19. placeholder="输入高后果区名称"
  20. style="width: 160px"
  21. class="filter-item"
  22. @keyup.enter.native="crud.toQuery"
  23. />
  24. <treeselect
  25. v-model="query.networkId"
  26. :load-options="loadNetworkChildren"
  27. :options="networkOptions"
  28. style="width: 160px"
  29. placeholder="请选择隶属管网"
  30. />
  31. <rrOperation />
  32. </div>
  33. <crudOperation :permission="permission" />
  34. </div>
  35. <!-- 表单组件 -->
  36. <el-dialog
  37. append-to-body
  38. :close-on-click-modal="false"
  39. :before-close="crud.cancelCU"
  40. :visible.sync="crudCU"
  41. :title="crud.status.title"
  42. width="1200px"
  43. >
  44. <el-row :gutter="40">
  45. <el-col :span="8">
  46. <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
  47. <el-form-item label="编号" prop="code">
  48. <el-input v-model="form.code" size="small" class="filter-item" style="width: 280px" />
  49. </el-form-item>
  50. <el-form-item label="名称" prop="name">
  51. <el-input v-model="form.name" size="small" class="filter-item" style="width: 280px" />
  52. </el-form-item>
  53. <el-form-item label="隶属管网" prop="networkId">
  54. <treeselect
  55. v-model="form.networkId"
  56. :load-options="loadNetworkChildren"
  57. :options="networkOptions"
  58. style="width: 280px; font-size: 12px"
  59. placeholder="请选择隶属管网"
  60. @input="handleChangeNetworkId"
  61. />
  62. </el-form-item>
  63. <el-form-item label="备注" prop="remark">
  64. <el-input
  65. v-model="form.remark"
  66. type="textarea"
  67. autosize
  68. clearable
  69. style="width: 280px"
  70. />
  71. </el-form-item>
  72. <el-table :data="form.points" style="width: 100%">
  73. <el-table-column prop="longitude" label="经度" align="center">
  74. <template slot-scope="scope">
  75. <el-form-item
  76. label-width="0px"
  77. :prop="`points[${scope.$index}].longitude`"
  78. :rules="{ required: true, trigger: 'blur' }"
  79. style="margin-bottom: 0px"
  80. >
  81. <el-input-number
  82. v-model="scope.row.longitude"
  83. size="small"
  84. :min="-180"
  85. :max="180"
  86. :step="0.0001"
  87. controls-position="right"
  88. style="width: 100%"
  89. />
  90. </el-form-item>
  91. </template>
  92. </el-table-column>
  93. <el-table-column prop="latitude" label="纬度" align="center">
  94. <template slot-scope="scope">
  95. <el-form-item
  96. label-width="0px"
  97. :prop="`points[${scope.$index}].latitude`"
  98. :rules="{ required: true, trigger: 'blur' }"
  99. style="margin-bottom: 0px"
  100. >
  101. <el-input-number
  102. v-model="scope.row.latitude"
  103. size="small"
  104. :min="-180"
  105. :max="180"
  106. :step="0.0001"
  107. controls-position="right"
  108. style="width: 100%"
  109. />
  110. </el-form-item>
  111. </template>
  112. </el-table-column>
  113. <el-table-column prop="operation" label="删除" align="center" width="60px">
  114. <template slot-scope="scope">
  115. <el-popconfirm title="确定删除此数据吗?" @confirm="handleDelPoint(scope)">
  116. <el-button size="mini" type="danger" icon="el-icon-delete" slot="reference" />
  117. </el-popconfirm>
  118. </template>
  119. </el-table-column>
  120. <template slot="append">
  121. <el-button
  122. size="small"
  123. type="primary"
  124. icon="el-icon-circle-plus-outline"
  125. @click="handleAddPoint()"
  126. style="width: 100%"
  127. />
  128. </template>
  129. </el-table>
  130. </el-form>
  131. </el-col>
  132. <el-col :span="16">
  133. <gps-map
  134. v-if="crudCU"
  135. ref="GPSMap"
  136. v-model="mapData"
  137. drawShow
  138. drawMode="Polygon"
  139. :background="mapBackground"
  140. />
  141. </el-col>
  142. </el-row>
  143. <div slot="footer" class="dialog-footer">
  144. <el-button type="text" @click="crud.cancelCU"> 取消 </el-button>
  145. <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">
  146. 确认
  147. </el-button>
  148. </div>
  149. </el-dialog>
  150. <!--表格渲染-->
  151. <el-table
  152. ref="table"
  153. v-loading="crud.loading"
  154. :data="crud.data"
  155. style="width: 100%"
  156. @selection-change="crud.selectionChangeHandler"
  157. >
  158. <el-table-column type="selection" width="55" />
  159. <el-table-column
  160. v-for="item in hcaTableOptions"
  161. :key="item.prop"
  162. :label="item.label"
  163. :prop="item.prop"
  164. :width="item.width"
  165. :align="item.align"
  166. :fixed="item.fixed"
  167. :sortable="item.sortable"
  168. >
  169. <template slot-scope="scope">
  170. <img
  171. style="width: 32px; height: 32px"
  172. v-if="item.prop === 'typeIconPath'"
  173. v-show="scope.row.typeIconPath"
  174. :src="VUE_APP_BASE_API + scope.row.typeIconPath"
  175. alt=""
  176. />
  177. <span v-else>{{ scope.row[item.prop] }}</span>
  178. </template>
  179. </el-table-column>
  180. <!-- 编辑与删除 -->
  181. <el-table-column
  182. v-if="checkPer(['admin', 'pipe:hca:edit', 'pipe:hca:del'])"
  183. label="操作"
  184. width="130px"
  185. align="center"
  186. fixed="right"
  187. >
  188. <template slot-scope="scope">
  189. <udOperation :data="scope.row" :permission="permission" />
  190. </template>
  191. </el-table-column>
  192. </el-table>
  193. <!--分页组件-->
  194. <pagination />
  195. </div>
  196. </template>
  197. <script>
  198. import permission from '@/directive/permission'
  199. import crudHca from '@/api/pipe/hca'
  200. import crudNetwork from '@/api/pipe/network'
  201. import { getOptions } from '@/api/pipe/public'
  202. import CRUD, { presenter, header, form, crud } from '@crud/crud'
  203. // import { crudOperation, rrOperation, udOperation, pagination } from '@crud'
  204. import crudComps from '@crud'
  205. import DateRangePicker from '@/components/DateRangePicker'
  206. import { hcaTableOptions } from '../tableConfig'
  207. import { initData } from '@/api/data'
  208. // vue-treeselect
  209. import Treeselect from '@riophae/vue-treeselect'
  210. import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
  211. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  212. import GpsMap from '@/components/GpsMap'
  213. const defaultForm = {
  214. id: '0',
  215. code: '', //编号
  216. name: '', //名称
  217. networkId: undefined, //隶属管网
  218. points: [], //多边形点
  219. remark: null, //备注
  220. }
  221. export default {
  222. name: 'PipeHca',
  223. directives: { permission },
  224. mixins: [presenter(), header(), form(defaultForm), crud()],
  225. components: { ...crudComps, DateRangePicker, Treeselect, GpsMap },
  226. cruds() {
  227. return CRUD({
  228. title: '高后果区',
  229. url: 'pipe/hca/getList',
  230. listOrder: [],
  231. crudMethod: { ...crudHca },
  232. optShow: { add: true, edit: true, del: true, reset: true, import: false, export: false },
  233. })
  234. },
  235. computed: {
  236. crudCU() {
  237. return this.crud.status.cu > 0
  238. },
  239. VUE_APP_BASE_API() {
  240. return process.env.VUE_APP_BASE_API
  241. },
  242. mapData: {
  243. get: function () {
  244. let data = null
  245. if (this.form.id && this.form.id > 0 && this.form.points && this.form.points.length > 2) {
  246. data = [
  247. {
  248. geometries: [
  249. {
  250. type: 'Polygon',
  251. points: this.form.points.map((p) => {
  252. return { x: p.longitude, y: p.latitude }
  253. }),
  254. },
  255. ],
  256. },
  257. ]
  258. }
  259. return data
  260. },
  261. set: function (newValue) {
  262. if (newValue) {
  263. const ps = newValue[0].geometries[newValue[0].geometries.length - 1].points
  264. .map((p) => {
  265. return { longitude: p.x, latitude: p.y }
  266. })
  267. ps.pop()
  268. this.form.points = ps
  269. }
  270. },
  271. },
  272. },
  273. watch: {
  274. },
  275. data() {
  276. return {
  277. hcaTableOptions,
  278. permission: {
  279. add: ['admin', 'pipe:hca:add'],
  280. edit: ['admin', 'pipe:hca:edit'],
  281. del: ['admin', 'pipe:hca:del'],
  282. },
  283. rules: {
  284. code: [{ required: true, message: '请输入编号', trigger: 'blur' }],
  285. name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
  286. networkId: [{ required: true, message: '请选择隶属管网', trigger: 'blur' }],
  287. },
  288. optionsObj: {
  289. LineType: [],
  290. ControlpointType: [],
  291. Controlpoint: [],
  292. },
  293. networkOptions: [],
  294. mapBackground: null,
  295. }
  296. },
  297. created() {
  298. //this.getOptions()
  299. this.loadNetworkRoot()
  300. },
  301. methods: {
  302. // 新增与编辑前做的操作
  303. [CRUD.HOOK.afterToCU](crud, form) {
  304. if (form.parentId == '0') {
  305. form.parentId = null
  306. }
  307. crudNetwork.getParentTree({ id: form.network }).then((res) => {
  308. this.networkOptions = res.data.content
  309. })
  310. this.refreshBackground(this.form.networkId)
  311. },
  312. //验证前处理
  313. [CRUD.HOOK.beforeValidateCU]() {
  314. if (!this.form.points || this.form.points.length < 3) {
  315. this.$message.error('请绘制正确的多边形')
  316. return false
  317. }
  318. },
  319. refreshBackground(networkId) {
  320. console.log(networkId)
  321. if (networkId && networkId > 0) {
  322. this.mapBackground = []
  323. initData('pipe/controlpoint/getListFromCache', { network: networkId }).then((res) => {
  324. console.log(res)
  325. if (res.code == 20000 && res.data.content && res.data.content.length > 0) {
  326. const point = []
  327. const line = []
  328. res.data.content.forEach((p) => {
  329. point.push({
  330. type: 'Point',
  331. points: [{ x: p.longitude, y: p.latitude }],
  332. symbol: {
  333. markerFile: p.typeIconPath ? this.VUE_APP_BASE_API + p.typeIconPath : null,
  334. markerWidth: 20,
  335. markerHeight: 20,
  336. markerDx: 0,
  337. markerDy: 10,
  338. textName: p.name,
  339. textDx: 0,
  340. textDy: 20,
  341. textFill : '#e0e0e0',
  342. },
  343. })
  344. if (
  345. p.inPipeLineStartLocation_Latitude &&
  346. p.inPipeLineStartLocation_Longitude &&
  347. p.inPipeLineTypeColor &&
  348. p.latitude &&
  349. p.longitude
  350. ) {
  351. line.push({
  352. type: 'LineString',
  353. points: [
  354. {
  355. x: p.inPipeLineStartLocation_Longitude,
  356. y: p.inPipeLineStartLocation_Latitude,
  357. },
  358. { x: p.longitude, y: p.latitude },
  359. ],
  360. symbol: {
  361. lineColor: p.inPipeLineTypeColor,
  362. lineWidth: 1,
  363. lineOpacity: 1,
  364. },
  365. })
  366. }
  367. })
  368. this.mapBackground.push({ geometries: line }, { geometries: point })
  369. } else {
  370. this.mapBackground = null
  371. }
  372. })
  373. }
  374. },
  375. loadNetworkRoot() {
  376. crudNetwork.getChildren({ id: 0 }).then((res) => {
  377. this.networkOptions = res.data.content
  378. })
  379. },
  380. loadNetworkChildren({ action, parentNode, callback }) {
  381. if (action === LOAD_CHILDREN_OPTIONS) {
  382. crudNetwork.getChildren({ id: parentNode.id }).then((res) => {
  383. parentNode.children = res.data.content
  384. setTimeout(() => {
  385. callback()
  386. }, 100)
  387. })
  388. }
  389. },
  390. getOptions() {
  391. Object.keys(this.optionsObj).forEach(async (key) => {
  392. try {
  393. let res = await getOptions(key)
  394. if (res.code === 20000) this.optionsObj[key] = res.data.content
  395. } catch (error) {
  396. console.log(error)
  397. }
  398. })
  399. },
  400. handleDelPoint(scope) {
  401. this.form.points.splice(scope.$index, 1)
  402. },
  403. handleAddPoint() {
  404. this.form.points.push({
  405. longitude: 0,
  406. latitude: 0,
  407. })
  408. },
  409. handleChangeNetworkId(nid) {
  410. //console.log(nid)
  411. this.refreshBackground(nid)
  412. }
  413. },
  414. }
  415. </script>
  416. <style rel="stylesheet/scss" lang="scss" scoped>
  417. ::v-deep .vue-treeselect {
  418. font-size: 13px;
  419. display: inline-block;
  420. vertical-align: middle;
  421. margin: 0 10px 10px 0;
  422. }
  423. ::v-deep .vue-treeselect .vue-treeselect__control {
  424. height: 30.5px;
  425. }
  426. </style>