trap.vue 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. <!-- -->
  2. <template>
  3. <div class="cbdbox">
  4. <div class="cbdboxs_search">
  5. <el-input
  6. v-model="idinput"
  7. placeholder="请输入诱捕器编号"
  8. size="mini"
  9. ></el-input>
  10. <el-select
  11. v-model="trapvalue"
  12. placeholder="请选择所在监测点"
  13. clearable
  14. @change="search"
  15. size="mini"
  16. >
  17. <el-option
  18. v-for="item in traponsoptions"
  19. :key="item.point_id"
  20. :label="item.point_name"
  21. :value="item.point_id"
  22. >
  23. </el-option>
  24. </el-select>
  25. <el-select
  26. v-model="versionsvalue2"
  27. placeholder="请选择隶属海关"
  28. size="mini"
  29. clearable
  30. @change="search"
  31. >
  32. <el-option
  33. v-for="item in versionsoptions2"
  34. :key="item.org_id"
  35. :label="item.org_name"
  36. :value="item.org_id"
  37. >
  38. </el-option>
  39. </el-select>
  40. <!-- <el-cascader
  41. :change-on-select="true"
  42. :options="versionsoptions"
  43. v-model="versionsvalue"
  44. :props="defaultParams"
  45. :clearable="true"
  46. @change="cascaderchange"
  47. size="mini"
  48. placeholder="请选择隶属海关"
  49. ></el-cascader> -->
  50. <el-select
  51. v-model="inoffvalue"
  52. placeholder="请选择诱捕器状态"
  53. size="mini"
  54. clearable
  55. @change="search"
  56. >
  57. <el-option
  58. v-for="item in inoffoptions"
  59. :key="item.value"
  60. :label="item.label"
  61. :value="item.value"
  62. >
  63. </el-option>
  64. </el-select>
  65. <el-button type="info" @click="search" size="mini">搜索</el-button>
  66. <el-button size="mini" @click="reset">重置</el-button>
  67. <el-button type="info" @click="openadd" size="mini">添加诱捕器</el-button>
  68. <el-button type="info" @click="downloadtf = true" size="mini"
  69. >批量导入诱捕器</el-button
  70. >
  71. <el-button type="info" size="mini" @click="deriveVisible = true"
  72. >导出数据</el-button
  73. >
  74. </div>
  75. <el-card class="box-card" style="margin-top: 15px">
  76. <div class="cbdboxs_table" v-loading="loading">
  77. <el-table
  78. :data="tableData"
  79. style="width: 100%; overflow-y: auto"
  80. :stripe="true"
  81. :height="48 * 13"
  82. >
  83. <el-table-column
  84. prop="index"
  85. label="序号"
  86. width="60px"
  87. ></el-table-column>
  88. <el-table-column prop="trap_number" label="编号"></el-table-column>
  89. <el-table-column prop="lng" label="经度">
  90. <template slot-scope="scope">
  91. <span>{{ ToDegrees(scope.row.lng, "lng") }}</span>
  92. </template>
  93. </el-table-column>
  94. <el-table-column prop="lat" label="纬度">
  95. <template slot-scope="scope">
  96. <span>{{ ToDegrees(scope.row.lat, "lat") }}</span>
  97. </template>
  98. </el-table-column>
  99. <el-table-column prop="org_list" label="组织">
  100. <template slot-scope="scope">
  101. <span v-if="scope.row.org_list.length == 1">{{
  102. scope.row.org_list[0].org_name
  103. }}</span>
  104. <el-popover
  105. ref="popover"
  106. placement="right"
  107. title=""
  108. width="150"
  109. trigger="hover"
  110. v-else
  111. >
  112. <div class="popover-content" v-html="content"></div>
  113. <span @mouseover="orglisthover(scope.row)" slot="reference"
  114. >{{ scope.row.org_list[0].org_name }}...</span
  115. >
  116. </el-popover>
  117. </template>
  118. </el-table-column>
  119. <el-table-column prop="point_name" label="监测点"> </el-table-column>
  120. <el-table-column prop="inducer_name" label="诱剂"> </el-table-column>
  121. <el-table-column prop="create_time" label="添加时间" width="200">
  122. </el-table-column>
  123. <el-table-column prop="is_online" label="状态">
  124. <template slot-scope="scope">
  125. <div class="state">
  126. <p
  127. :style="{
  128. color: scope.row.trap_status == '1' ? '#30A031 ' : 'red',
  129. }"
  130. >
  131. ·
  132. </p>
  133. <p
  134. :style="{
  135. color: scope.row.trap_status == '1' ? '#30A031 ' : 'red',
  136. }"
  137. >
  138. {{ scope.row.trap_status == "1" ? "正常" : "停用" }}
  139. </p>
  140. </div>
  141. </template>
  142. </el-table-column>
  143. <el-table-column label="操作" width="200">
  144. <template slot-scope="scope">
  145. <span
  146. style="color: #409eff; margin-right: 5px; cursor: pointer"
  147. @click="addtrap(scope.row)"
  148. >编辑</span
  149. >
  150. <span
  151. style="color: #409eff; margin-right: 5px; cursor: pointer"
  152. @click="deletes(scope.row)"
  153. >删除</span
  154. >
  155. </template>
  156. </el-table-column>
  157. </el-table>
  158. </div>
  159. <el-pagination
  160. background
  161. layout="prev, pager, next,jumper"
  162. :total="total"
  163. :page-size="20"
  164. @current-change="pageChange"
  165. :current-page="queryInfo.page"
  166. >
  167. </el-pagination>
  168. </el-card>
  169. <el-dialog
  170. :title="addtitle"
  171. :visible.sync="addtraptf"
  172. width="580px"
  173. @close="resetForm('ruleForm')"
  174. :close-on-click-modal="false"
  175. >
  176. <div>
  177. <el-form
  178. :model="ruleForm"
  179. :rules="rules"
  180. ref="ruleForm"
  181. label-width="100px"
  182. class="demo-ruleForm"
  183. >
  184. <el-form-item label="诱捕器编号" prop="trap_number">
  185. <el-input v-model="ruleForm.trap_number"></el-input>
  186. </el-form-item>
  187. <div class="addtrapbox">
  188. <el-form-item label="所在纬度" prop="lng">
  189. <el-input v-model="ruleForm.lng" @blur="latblur"></el-input>
  190. <p style="height: 24px; padding-left: 16px">
  191. {{ ToDegrees(ruleForm.lng, "lng") }}
  192. </p>
  193. </el-form-item>
  194. <el-form-item label="所在纬度" prop="lat">
  195. <el-input v-model="ruleForm.lat" @blur="latblur"></el-input>
  196. <p style="height: 24px; padding-left: 16px">
  197. {{ ToDegrees(ruleForm.lat, "lat") }}
  198. </p>
  199. </el-form-item>
  200. </div>
  201. <div class="buttonbox">
  202. <el-button type="info" size="mini" @click="dingwei"
  203. >地图选点</el-button
  204. >
  205. </div>
  206. <el-form-item label="所在城市" prop="basecity">
  207. <el-input
  208. v-model="ruleForm.basecity"
  209. disabled
  210. style="width: 217px"
  211. ></el-input>
  212. </el-form-item>
  213. <el-form-item label="隶属海关" prop="org_id">
  214. <!-- <el-select v-model="ruleForm.org_id" placeholder="请选择隶属海关">
  215. <el-option
  216. v-for="item in versionsoptions"
  217. :label="item.org_name"
  218. :value="item.org_id"
  219. :key="item.org_id"
  220. ></el-option>
  221. </el-select> -->
  222. <el-cascader
  223. :change-on-select="true"
  224. v-model="ruleForm.org_id"
  225. :options="versionsoptions"
  226. :props="defaultParams"
  227. :clearable="true"
  228. placeholder="请选择隶属海关"
  229. filterable
  230. ></el-cascader>
  231. </el-form-item>
  232. <el-form-item label="所在监测点" prop="point_id">
  233. <el-select
  234. v-model="ruleForm.point_id"
  235. placeholder="请选择所在监测点"
  236. >
  237. <el-option
  238. v-for="item in traponsoptions"
  239. :label="item.point_name"
  240. :value="item.point_id"
  241. :key="item.point_id"
  242. ></el-option>
  243. </el-select>
  244. </el-form-item>
  245. <el-form-item label="诱剂名称" prop="inducer_id">
  246. <el-select
  247. v-model="ruleForm.inducer_id"
  248. placeholder="请选择诱剂名称"
  249. >
  250. <el-option
  251. v-for="item in inducer_data"
  252. :label="item.inducer_name"
  253. :value="item.inducer"
  254. :key="item.inducer"
  255. ></el-option>
  256. </el-select>
  257. </el-form-item>
  258. <el-form-item label="设备状态" prop="trap_status">
  259. <el-radio-group
  260. v-model="ruleForm.trap_status"
  261. placeholder="请选择设备状态"
  262. >
  263. <el-radio label="1">正常</el-radio>
  264. <el-radio label="0">停用</el-radio>
  265. </el-radio-group>
  266. </el-form-item>
  267. </el-form>
  268. </div>
  269. <span slot="footer" class="dialog-footer">
  270. <el-button @click="resetForm('ruleForm')" size="mini">取 消</el-button>
  271. <el-button
  272. type="primary"
  273. @click="submitForm('ruleForm')"
  274. size="mini"
  275. :disabled="releaseTF"
  276. >{{ releaseTF == true ? "发布中..." : "确 定" }}</el-button
  277. >
  278. </span>
  279. </el-dialog>
  280. <el-dialog
  281. title="导入诱捕器"
  282. :visible.sync="downloadtf"
  283. width="500px"
  284. :close-on-click-modal="false"
  285. >
  286. <div class="downloadbox">
  287. <div class="downloadbox_item">
  288. <p class="title">导入诱捕器</p>
  289. <!-- <el-input placeholder="请输入内容" v-model="input1">
  290. <template slot="prepend">Http://</template>
  291. </el-input> -->
  292. <el-upload
  293. action=""
  294. :auto-upload="false"
  295. accept=".xlsx, .xls"
  296. :show-file-list="false"
  297. :on-change="handle"
  298. >
  299. <el-button type="success" size="mini">点击上传</el-button>
  300. </el-upload>
  301. <el-input
  302. v-model="downloadinput"
  303. placeholder="请输入内容"
  304. :disabled="true"
  305. size="mini"
  306. ></el-input>
  307. </div>
  308. <p class="tishi">
  309. <span>注:请先下模板,在模板中填入数据上传</span
  310. ><span @click="download">下载模板</span>
  311. </p>
  312. </div>
  313. <!-- <span slot="footer" class="dialog-footer">
  314. <el-button @click="downloadtf = false">取 消</el-button>
  315. <el-button type="primary" @click="downloadtf = false">确 定</el-button>
  316. </span> -->
  317. </el-dialog>
  318. <el-dialog
  319. title="导出数据"
  320. :visible.sync="deriveVisible"
  321. width="500px"
  322. :close-on-click-modal="false"
  323. >
  324. <div class="derivebox">
  325. <p><span>*</span>文件名称:</p>
  326. <el-input
  327. v-model="derivefilename"
  328. placeholder="请输入文件名称"
  329. size="mini"
  330. ></el-input>
  331. </div>
  332. <span slot="footer" class="dialog-footer">
  333. <el-button @click="deriveVisible = false" size="mini">取 消</el-button>
  334. <el-button
  335. type="primary"
  336. @click="deriveclick"
  337. size="mini"
  338. :disabled="deriveTF"
  339. >{{ deriveTF ? "导出中..." : "确 定" }}</el-button
  340. >
  341. </span>
  342. </el-dialog>
  343. <el-dialog
  344. class="map_dialog"
  345. title="地图选点"
  346. :visible.sync="addLocationDialogVisible"
  347. width="820px"
  348. @closed="addLocationDialogClosed"
  349. :close-on-click-modal="false"
  350. >
  351. <el-form
  352. :inline="true"
  353. :model="locationForm"
  354. class="demo-form-inline"
  355. size="mini"
  356. >
  357. <el-form-item label="经度">
  358. <el-input clearable v-model="locationForm.lng"></el-input>
  359. </el-form-item>
  360. <el-form-item label="纬度">
  361. <el-input clearable v-model="locationForm.lat"></el-input>
  362. </el-form-item>
  363. <el-form-item>
  364. <el-button type="primary" size="mini" @click="locationSearch"
  365. >定位</el-button
  366. >
  367. </el-form-item>
  368. <el-form-item label="">
  369. <el-input
  370. placeholder="请输入地区检索"
  371. v-model="addr"
  372. clearable
  373. @change="addrChange()"
  374. ></el-input>
  375. </el-form-item>
  376. </el-form>
  377. <div class="amap-demo" id="mapContainer2" style="height: 400px"></div>
  378. <span slot="footer" class="dialog-footer">
  379. <el-button @click="addLocationDialogVisible = false" size="mini"
  380. >取 消</el-button
  381. >
  382. <el-button type="primary" @click="addLocationSubm" size="mini"
  383. >确 定</el-button
  384. >
  385. </span>
  386. </el-dialog>
  387. </div>
  388. </template>
  389. <script>
  390. import { isArray } from "highcharts";
  391. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  392. export default {
  393. //import引入的组件需要注入到对象中才能使用
  394. components: {},
  395. data() {
  396. //这里存放数据
  397. var checkname = (rule, value, callback) => {
  398. if (/^[A-Za-z0-9\u4e00-\u9fa5]+$/.test(value)) {
  399. callback();
  400. } else {
  401. callback(new Error("请输入非中文格式"));
  402. }
  403. };
  404. var checklnglat = (rule, value, callback) => {
  405. if (isNaN(value)) {
  406. callback(new Error("请输入数字"));
  407. } else {
  408. callback();
  409. }
  410. };
  411. return {
  412. idinput: "",
  413. inoffvalue: "",
  414. inoffoptions: [
  415. { label: "停用", value: "0" },
  416. { label: "正常", value: "1" },
  417. ],
  418. versionsvalue: "",
  419. versionsvalue1: "", //组织id
  420. versionsoptions: [], //组织
  421. versionsvalue2: "", //组织id 用于搜索
  422. versionsoptions2: [], //组织 用于搜索
  423. defaultParams: {
  424. label: "org_name",
  425. value: "id",
  426. children: "childrens",
  427. multiple: true,
  428. checkStrictly: true,
  429. },
  430. trapvalue: "",
  431. traponsoptions: [], //监测点
  432. inducer_data: [],
  433. queryInfo: {
  434. page: 1,
  435. point_id: "", //监测点id
  436. trap_number: "", //设备id
  437. org_id: "", //组织id
  438. trap_status: "", //状态
  439. },
  440. tableData: [],
  441. device_id: "",
  442. total: 10,
  443. loading: false,
  444. addtraptf: false, //增加诱捕器弹框
  445. ruleForm: {
  446. trap_id: "", //诱捕器id 修改时用到
  447. trap_number: "", //诱捕器编号
  448. lat: "", // 必传(string) 纬度
  449. lng: "", // 必传(string) 经度
  450. org_id: [], // 必传(string) 所属海关id
  451. inducer_id: "", // 必传(string) 诱剂id
  452. point_id: "", // 必传(string) 所属监测点id
  453. trap_status: "", // 必传(string) 设备状态0停用 1正常
  454. basecity: "",
  455. },
  456. rules: {
  457. trap_number: [
  458. { required: true, message: "请输入诱捕器编号", trigger: "blur" },
  459. { validator: checkname, trigger: "blur" },
  460. ],
  461. lng: [
  462. { required: true, message: "请输入经度", trigger: "blur" },
  463. // { validator: checklnglat, trigger: "blur" },
  464. ],
  465. lat: [
  466. { required: true, message: "请输入纬度", trigger: "blur" },
  467. // { validator: checklnglat, trigger: "blur" },
  468. ],
  469. org_id: [
  470. { required: true, message: "请选择隶属海关", trigger: "change" },
  471. ],
  472. point_id: [
  473. { required: true, message: "请选择所在监测点", trigger: "change" },
  474. ],
  475. inducer_id: [
  476. { required: true, message: "请选择诱剂名称", trigger: "change" },
  477. ],
  478. trap_status: [
  479. { required: true, message: "请选择设备状态", trigger: "change" },
  480. ],
  481. },
  482. parameter: "",
  483. addtitle: "新增诱捕器",
  484. downloadtf: false,
  485. downloadinput: "", //上传的文件名
  486. deriveVisible: false, //导出弹框
  487. derivefilename: "", //导出文件名称
  488. //地图属性
  489. addLocationDialogVisible: false,
  490. locationForm: {
  491. lng: "",
  492. lat: "",
  493. },
  494. addr: "", //搜索栏地址
  495. address: "", //地图上标签地址
  496. center: [114.05, 22.55],
  497. content: "", //设备列表组织列表
  498. releaseTF: false,
  499. deriveTF: false,
  500. };
  501. },
  502. //监听属性 类似于data概念
  503. computed: {},
  504. //监控data中的数据变化
  505. watch: {
  506. parameter: function (e) {
  507. // console.log(e);
  508. if (e == "add") {
  509. // console.log(this.$data.addtitle)
  510. this.$data.addtitle = "新增诱捕器";
  511. } else if (e == "modify") {
  512. this.$data.addtitle = "修改诱捕器";
  513. }
  514. },
  515. },
  516. //方法集合
  517. methods: {
  518. getcbdlist() {
  519. //获取设备列表
  520. this.loading = true;
  521. this.$axios({
  522. method: "POST",
  523. url: "/api/api_gateway?method=monitor_manage.trap_manage.trap_list",
  524. data: this.qs.stringify({
  525. page_size: 20,
  526. page: this.queryInfo.page,
  527. trap_number: this.queryInfo.trap_number,
  528. point_id: this.queryInfo.point_id,
  529. org_id: this.queryInfo.org_id,
  530. trap_status: this.queryInfo.trap_status,
  531. }),
  532. }).then((res) => {
  533. this.loading = false;
  534. console.log(res.data.data);
  535. this.total = res.data.data.total_item;
  536. this.tableData = res.data.data.page_list;
  537. for (var i = 0; i < this.tableData.length; i++) {
  538. this.tableData[i]["index"] = i + 1;
  539. }
  540. });
  541. },
  542. getmon() {
  543. //获取监测点列表 组织列表
  544. this.$axios({
  545. method: "POST",
  546. url: "/api/api_gateway?method=sysmenage.usermanager.org_list",
  547. data: this.qs.stringify({
  548. page_item: "100000000",
  549. }),
  550. }).then((res) => {
  551. console.log(res.data.data);
  552. this.versionsoptions = res.data.data.page_list; //组织
  553. this.traponsoptions = res.data.data.point_data;
  554. this.inducer_data = res.data.data.inducer_data;
  555. });
  556. },
  557. getmon2() {
  558. this.$axios({
  559. method: "POST",
  560. url: "/api/api_gateway?method=monitor_manage.trap_manage.trap_org",
  561. data: this.qs.stringify({
  562. page_item: "10000000",
  563. }),
  564. }).then((res) => {
  565. console.log(res.data.data);
  566. this.versionsoptions2 = res.data.data.org_data; //组织
  567. // this.inoffoptions = res.data.data.point_data;
  568. });
  569. },
  570. cascaderchange(e) {
  571. // console.log(this.versionsvalue, e);
  572. console.log(e[e.length - 1]);
  573. this.versionsvalue1 = e[e.length - 1];
  574. },
  575. search() {
  576. this.queryInfo.page = 1;
  577. this.queryInfo.point_id = this.trapvalue;
  578. this.queryInfo.trap_number = this.idinput;
  579. this.queryInfo.org_id = this.versionsvalue2;
  580. this.queryInfo.trap_status = this.inoffvalue;
  581. // console.log(this.inoffvalue, this.versionsvalue, this.inoffvalue);
  582. this.getcbdlist();
  583. },
  584. pageChange(e) {
  585. // console.log(e)
  586. this.queryInfo.page = e;
  587. this.getcbdlist();
  588. },
  589. submitForm(formName) {
  590. console.log(this.ruleForm);
  591. // var org_id = [];
  592. // if (Array.isArray(this.ruleForm.org_id)) {
  593. // for (var i = 0; i < this.ruleForm.org_id.length; i++) {
  594. // org_id.push(
  595. // this.ruleForm.org_id[i][this.ruleForm.org_id[i].length - 1]
  596. // );
  597. // }
  598. // } else {
  599. // org_id = this.ruleForm.org_id;
  600. // }
  601. // if (org_id.length > 0) {
  602. // org_id = org_id.join("/");
  603. // }
  604. // console.log(org_id);
  605. // this.releaseTF = true;
  606. this.$refs[formName].validate((valid) => {
  607. if (valid) {
  608. var org_id = [];
  609. if (Array.isArray(this.ruleForm.org_id)) {
  610. for (var i = 0; i < this.ruleForm.org_id.length; i++) {
  611. org_id.push(
  612. this.ruleForm.org_id[i][this.ruleForm.org_id[i].length - 1]
  613. );
  614. }
  615. } else {
  616. org_id = this.ruleForm.org_id;
  617. }
  618. if (org_id.length > 0) {
  619. org_id = org_id.join("/");
  620. }
  621. console.log(org_id);
  622. this.releaseTF = true;
  623. this.$axios({
  624. method: "POST",
  625. url: "/api/api_gateway?method=monitor_manage.trap_manage.add_trap",
  626. data: this.qs.stringify({
  627. trap_id: this.ruleForm.trap_id, // 非必传(num) 诱捕器id 修改项
  628. trap_number: this.ruleForm.trap_number, // 必传(string) 设备编号
  629. lat: this.ToDigital(this.ruleForm.lat), // 必传(string) 纬度
  630. lng: this.ToDigital(this.ruleForm.lng), // 必传(string) 经度
  631. org_id: org_id, // 必传(string) 所属海关id
  632. inducer_id: this.ruleForm.inducer_id, // 必传(string) 诱剂id
  633. point_id: this.ruleForm.point_id, // 必传(string) 所属监测点id
  634. trap_status: this.ruleForm.trap_status, // 必传(string) 设备状态0停用 1正常
  635. parameter: this.parameter,
  636. city: this.ruleForm.basecity,
  637. }),
  638. }).then((res) => {
  639. console.log(res);
  640. if (res.data.data) {
  641. var message = "";
  642. if (this.parameter == "add") {
  643. // console.log(this.$data.addtitle)
  644. message = "添加成功!";
  645. } else if (this.parameter == "modify") {
  646. message = "修改成功!";
  647. }
  648. if (document.getElementsByClassName("el-message").length == 0) {
  649. this.$message({
  650. showClose: true,
  651. message: message,
  652. type: "success",
  653. });
  654. }
  655. this.addtraptf = false;
  656. this.getcbdlist();
  657. } else {
  658. if (document.getElementsByClassName("el-message").length == 0) {
  659. this.$message({
  660. showClose: true,
  661. message: "添加失败" + res.data.message,
  662. type: "warning",
  663. });
  664. }
  665. }
  666. this.releaseTF = false;
  667. });
  668. } else {
  669. if (document.getElementsByClassName("el-message").length == 0) {
  670. this.$message({
  671. message: "请将信息填写完全",
  672. type: "warning",
  673. });
  674. }
  675. return false;
  676. }
  677. });
  678. },
  679. resetForm(formName) {
  680. this.addtraptf = false;
  681. this.releaseTF = false;
  682. this.$refs[formName].resetFields();
  683. for (var key in this.ruleForm) {
  684. this.ruleForm[key] = "";
  685. }
  686. },
  687. openadd() {
  688. this.addtraptf = true;
  689. this.parameter = "add";
  690. // console.log(this.ruleForm)
  691. },
  692. addtrap(e) {
  693. //增加诱捕器
  694. console.log(e);
  695. // this.
  696. for (var key in this.ruleForm) {
  697. this.ruleForm[key] = e[key];
  698. }
  699. // console.log(this.ruleForm.org_id);
  700. this.ruleForm.trap_status = this.ruleForm.trap_status.toString();
  701. this.parameter = "modify";
  702. this.ruleForm.org_id = [];
  703. console.log(this.ruleForm);
  704. this.city(e.lat, e.lng);
  705. this.getmon3(e);
  706. },
  707. getmon3(e) {
  708. this.$axios({
  709. method: "POST",
  710. url: "/api/api_gateway?method=sysmenage.usermanager.get_parent_org_list",
  711. data: this.qs.stringify({
  712. device_id: e.trap_id,
  713. }),
  714. }).then((res) => {
  715. // console.log(res.data.data);
  716. var orgdatas = res.data.data;
  717. for (var i = 0; i < e.org_list.length; i++) {
  718. var arr = [e.org_list[i].org_id];
  719. this.ruleForm.org_id.push(arr);
  720. }
  721. if (orgdatas.length != 0) {
  722. for (var i = 0; i < orgdatas.length; i++) {
  723. if (orgdatas[i].length != 0) {
  724. for (var j = 0; j < orgdatas[i].length; j++) {
  725. this.ruleForm.org_id[i].unshift(orgdatas[i][j].org_id);
  726. }
  727. }
  728. }
  729. }
  730. console.log(this.ruleForm.org_id);
  731. this.addtraptf = true;
  732. });
  733. },
  734. deletes(events) {
  735. //删除诱捕器
  736. console.log(events);
  737. var str = "您确定删除编号为<" + events.trap_number + ">的诱捕器吗?";
  738. this.$confirm(str, "删除诱捕器", {
  739. confirmButtonText: "确定",
  740. cancelButtonText: "取消",
  741. })
  742. .then(() => {
  743. this.$axios({
  744. method: "POST",
  745. url: "/api/api_gateway?method=monitor_manage.trap_manage.add_trap",
  746. data: this.qs.stringify({
  747. trap_id: events.trap_id,
  748. parameter: "del",
  749. }),
  750. }).then((res) => {
  751. console.log(res);
  752. if (res.data.data) {
  753. if (document.getElementsByClassName("el-message").length == 0) {
  754. this.$message({
  755. showClose: true,
  756. message: "删除成功!",
  757. type: "success",
  758. });
  759. }
  760. this.getcbdlist();
  761. } else {
  762. if (document.getElementsByClassName("el-message").length == 0) {
  763. this.$message({
  764. showClose: true,
  765. message: "删除失败," + res.data.message,
  766. type: "warning",
  767. });
  768. }
  769. }
  770. });
  771. })
  772. .catch(() => {
  773. if (document.getElementsByClassName("el-message").length == 0) {
  774. this.$message({
  775. type: "info",
  776. message: "已取消删除",
  777. });
  778. }
  779. });
  780. },
  781. handle(ev) {
  782. this.downloadinput = ev.name;
  783. var datas = new FormData();
  784. var username = localStorage.getItem("username");
  785. datas.append("username", username);
  786. datas.append("file", ev.raw);
  787. this.$axios({
  788. method: "POST",
  789. url: "/api/trap_export",
  790. data: datas,
  791. responseType: "blob",
  792. }).then((res) => {
  793. console.log(res);
  794. this.downloadFile(res, "allot_result.xls");
  795. });
  796. },
  797. download() {
  798. //下载模板
  799. console.log(22222);
  800. window.location.href =
  801. // this.$deriveData +
  802. // "http://192.168.1.77:12345/api/trap_export";1
  803. this.$deriveData + "/api/trap_export";
  804. },
  805. downloadFile(res, name) {
  806. let link = document.createElement("a");
  807. link.href = window.URL.createObjectURL(new Blob([res.data]));
  808. link.target = "_blank";
  809. //文件名和格式
  810. link.download = name;
  811. document.body.appendChild(link);
  812. link.click();
  813. document.body.removeChild(link);
  814. this.deriveTF = false;
  815. },
  816. deriveclick() {
  817. // this.deriveVisible = false;
  818. if (this.derivefilename == "") {
  819. if (document.getElementsByClassName("el-message").length == 0) {
  820. this.$message({
  821. showClose: true,
  822. message: "请输入文件名称",
  823. type: "warning",
  824. });
  825. }
  826. } else {
  827. this.deriveTF = true;
  828. this.$axios({
  829. method: "POST",
  830. url: "api/trap_list_export",
  831. data: this.qs.stringify({
  832. trap_number: this.ruleForm.trap_number,
  833. point_id: this.ruleForm.point_id,
  834. org_id: this.ruleForm.org_id,
  835. trap_status: this.ruleForm.trap_status,
  836. file_name: this.derivefilename,
  837. user: localStorage.getItem("username"),
  838. }),
  839. responseType: "blob",
  840. }).then((res) => {
  841. console.log(res);
  842. this.downloadFile(res, this.derivefilename + ".xls");
  843. });
  844. }
  845. },
  846. reset() {
  847. //重置
  848. this.idinput = "";
  849. this.trapvalue = "";
  850. this.inoffvalue = "";
  851. this.queryInfo.trap_number = "";
  852. this.queryInfo.point_id = "";
  853. this.queryInfo.org_id = "";
  854. this.queryInfo.trap_status = "";
  855. this.versionsvalue2 = "";
  856. this.versionsvalue = [];
  857. this.queryInfo.page = 1;
  858. this.getcbdlist();
  859. },
  860. init() {
  861. console.log(document.getElementById("mapContainer2"));
  862. var map = new AMap.Map("mapContainer2", {
  863. center: this.center,
  864. resizeEnable: true,
  865. zoom: 10,
  866. lang: "en",
  867. });
  868. AMap.plugin(["AMap.ToolBar", "AMap.Geocoder"], () => {
  869. map.addControl(new AMap.ToolBar());
  870. this.geocoder = new AMap.Geocoder({
  871. city: "全国",
  872. radius: 1000,
  873. });
  874. });
  875. setTimeout(() => {
  876. var marker = new AMap.Marker({
  877. position: this.center,
  878. });
  879. console.log(this.center);
  880. marker.setMap(map);
  881. }, 1000);
  882. this.map = map;
  883. this.testevent();
  884. },
  885. addrChange() {
  886. //位置搜索
  887. var marker = new AMap.Marker();
  888. this.geocoder.getLocation(this.addr, (status, result) => {
  889. if (status === "complete" && result.geocodes.length) {
  890. var lnglat = result.geocodes[0].location;
  891. marker.setPosition(lnglat);
  892. this.map.add(marker);
  893. this.map.setFitView(marker);
  894. this.locationForm = {
  895. lat: lnglat.lat,
  896. lng: lnglat.lng,
  897. };
  898. } else {
  899. if (document.getElementsByClassName("el-message").length == 0) {
  900. this.$message.error("根据地址查询位置失败");
  901. }
  902. }
  903. });
  904. },
  905. // 地图点击事件
  906. testevent() {
  907. this.map.on("click", (ev) => {
  908. var lnglat = [ev.lnglat.lng, ev.lnglat.lat];
  909. this.locationForm = { lng: lnglat[0], lat: lnglat[1] };
  910. this.map.clearMap();
  911. var marker = new AMap.Marker({
  912. position: lnglat,
  913. });
  914. marker.setMap(this.map);
  915. this.getAddress(lnglat);
  916. setTimeout(() => {
  917. new AMap.InfoWindow({
  918. content: "<h5>" + "当前选中地址" + "</h5>" + this.address,
  919. offset: new AMap.Pixel(0, -32),
  920. }).open(this.map, lnglat);
  921. }, 100);
  922. });
  923. },
  924. getAddress(lnglat) {
  925. AMap.plugin("AMap.Geocoder", () => {
  926. this.geocoder.getAddress(lnglat, (status, result) => {
  927. if (status === "complete" && result.info === "OK") {
  928. this.address = result.regeocode.formattedAddress;
  929. }
  930. });
  931. });
  932. },
  933. addLocationSubm() {
  934. //点击确定
  935. this.ruleForm.lng = this.locationForm.lng;
  936. this.ruleForm.lat = this.locationForm.lat;
  937. this.addLocationDialogVisible = false;
  938. this.city(this.ruleForm.lat, this.ruleForm.lng);
  939. },
  940. addLocationDialogClosed() {
  941. //弹框关闭时
  942. // this.locationForm = { lat: "", lng: "" };
  943. this.center = [114.05, 22.55];
  944. this.map = null;
  945. },
  946. locationSearch() {
  947. if (this.locationForm.lat && this.locationForm.lng) {
  948. let lnglat = [this.locationForm.lng, this.locationForm.lat];
  949. var marker = new AMap.Marker({
  950. position: lnglat,
  951. });
  952. marker.setMap(this.map);
  953. } else {
  954. if (document.getElementsByClassName("el-message").length == 0) {
  955. this.$message.warning("请输入经纬度!");
  956. }
  957. // return fasle;
  958. }
  959. },
  960. dingwei() {
  961. console.log(this.ruleForm);
  962. if (this.ruleForm.lng != "" && this.ruleForm.lng != 0) {
  963. this.center[0] = this.ruleForm.lng;
  964. } else {
  965. this.center = [114.05, 22.55];
  966. }
  967. if (this.ruleForm.lat != "" && this.ruleForm.lat != 0) {
  968. this.center[1] = this.ruleForm.lat;
  969. } else {
  970. this.center = [114.05, 22.55];
  971. }
  972. this.addLocationDialogVisible = true;
  973. setTimeout(() => {
  974. this.init();
  975. }, 500);
  976. },
  977. //度转度°分′秒″
  978. ToDegrees(val, type) {
  979. if (typeof val == "undefined" || val == "" || isNaN(val)) {
  980. return val;
  981. }
  982. val = val.toString();
  983. var A = "";
  984. if (type == "lng") {
  985. A = val > 0 ? "E" : "W";
  986. } else if (type == "lat") {
  987. A = val > 0 ? "N" : "S";
  988. }
  989. var i = val.indexOf(".");
  990. var strDu = i < 0 ? val : val.substring(0, i); //获取度
  991. var strFen = 0;
  992. var strMiao = 0;
  993. if (i > 0) {
  994. var strFen = "0" + val.substring(i);
  995. strFen = strFen * 60 + "";
  996. i = strFen.indexOf(".");
  997. if (i > 0) {
  998. strMiao = "0" + strFen.substring(i);
  999. strFen = strFen.substring(0, i); //获取分
  1000. strMiao = strMiao * 60 + "";
  1001. i = strMiao.indexOf(".");
  1002. strMiao = strMiao.substring(0, i + 4); //取到小数点后面三位
  1003. strMiao = parseFloat(strMiao).toFixed(2); //精确小数点后面两位
  1004. }
  1005. }
  1006. // console.log(strDu, strFen, strMiao);
  1007. return strDu + "°" + strFen + "′" + strMiao + "″" + A;
  1008. },
  1009. //度°分′秒″转度
  1010. ToDigital(lnglat) {
  1011. if (!isNaN(lnglat)) {
  1012. return lnglat;
  1013. }
  1014. console.log(lnglat);
  1015. lnglat = lnglat.toString();
  1016. var strDu, strFen, strMiao;
  1017. var duindex = lnglat.indexOf("°"); //字符度的下标
  1018. var fenindex = lnglat.indexOf("′"); //字符分的下标
  1019. var miaoindex = lnglat.indexOf("″"); //字符秒的下标
  1020. strDu = lnglat.slice(0, duindex);
  1021. strFen = lnglat.slice(duindex + 1, fenindex);
  1022. strMiao = lnglat.slice(fenindex + 1, miaoindex);
  1023. // len = len > 6 || typeof len == "undefined" ? 6 : len; //精确到小数点后最多六位
  1024. strDu =
  1025. typeof strDu == "undefined" || strDu == "" ? 0 : parseFloat(strDu);
  1026. strFen =
  1027. typeof strFen == "undefined" || strFen == ""
  1028. ? 0
  1029. : parseFloat(strFen) / 60;
  1030. strMiao =
  1031. typeof strMiao == "undefined" || strMiao == ""
  1032. ? 0
  1033. : parseFloat(strMiao) / 3600;
  1034. var digital = strDu + strFen + strMiao;
  1035. if (digital == 0) {
  1036. return "";
  1037. } else {
  1038. return digital.toFixed(6);
  1039. }
  1040. },
  1041. orglisthover(e) {
  1042. console.log(e);
  1043. var str = ``;
  1044. for (var i = 0; i < e.org_list.length; i++) {
  1045. str += `<p>` + e.org_list[i].org_name + `</p>`;
  1046. }
  1047. this.content = str;
  1048. },
  1049. city(lat, lng) {
  1050. $.ajax({
  1051. url: "https://restapi.amap.com/v3/geocode/regeo",
  1052. type: "get",
  1053. dataType: "jsonp",
  1054. data: this.qs.stringify({
  1055. location: lng + "," + lat,
  1056. key: "78ce288400f4fc6d9458989875c833c2",
  1057. extensions: "base",
  1058. }),
  1059. success: (res) => {
  1060. console.log(res);
  1061. this.ruleForm.basecity = res.regeocode.addressComponent.city;
  1062. console.log(this.ruleForm);
  1063. },
  1064. error: function (err) {
  1065. alert("服务端错误,请刷新浏览器后重试");
  1066. },
  1067. });
  1068. // return arr;
  1069. },
  1070. latblur() {
  1071. if (this.ruleForm.lat != "" && this.ruleForm.lng != "") {
  1072. this.city(this.ruleForm.lat, this.ruleForm.lng);
  1073. }
  1074. },
  1075. },
  1076. beforeCreate() {}, //生命周期 - 创建之前
  1077. //生命周期 - 创建完成(可以访问当前this实例)
  1078. created() {},
  1079. beforeMount() {}, //生命周期 - 挂载之前
  1080. //生命周期 - 挂载完成(可以访问DOM元素)
  1081. mounted() {
  1082. this.getmon();
  1083. this.getmon2();
  1084. this.getcbdlist();
  1085. },
  1086. beforeUpdate() {}, //生命周期 - 更新之前
  1087. updated() {}, //生命周期 - 更新之后
  1088. beforeDestroy() {}, //生命周期 - 销毁之前
  1089. destroyed() {}, //生命周期 - 销毁完成
  1090. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  1091. };
  1092. </script>
  1093. <style scoped lang="less">
  1094. .cbdbox {
  1095. height: 100%;
  1096. }
  1097. .cbdboxs_search {
  1098. display: flex;
  1099. justify-content: flex-start;
  1100. // height: 40px;
  1101. .el-select {
  1102. width: 250px;
  1103. margin-right: 15px;
  1104. }
  1105. .el-input {
  1106. width: 250px;
  1107. margin-right: 15px;
  1108. }
  1109. /deep/.el-cascader {
  1110. width: 250px;
  1111. margin-right: 15px;
  1112. }
  1113. }
  1114. .cbdboxs_table {
  1115. margin-top: 15px;
  1116. /deep/.el-table__header-wrapper {
  1117. th {
  1118. background-color: #fafafa;
  1119. }
  1120. }
  1121. .state {
  1122. display: flex;
  1123. p:first-child {
  1124. font-size: 40px;
  1125. }
  1126. }
  1127. }
  1128. .addtrapbox {
  1129. display: flex;
  1130. }
  1131. .buttonbox {
  1132. margin-bottom: 23px;
  1133. padding-left: 100px;
  1134. }
  1135. .downloadbox {
  1136. .downloadbox_item {
  1137. display: flex;
  1138. .title {
  1139. width: 100px;
  1140. line-height: 28px;
  1141. }
  1142. .el-input {
  1143. width: 250px;
  1144. margin-left: 15px;
  1145. }
  1146. }
  1147. .tishi {
  1148. padding-left: 100px;
  1149. margin-top: 15px;
  1150. display: flex;
  1151. justify-content: space-between;
  1152. color: #409eff;
  1153. span:last-child {
  1154. cursor: pointer;
  1155. }
  1156. }
  1157. }
  1158. .derivebox {
  1159. display: flex;
  1160. p {
  1161. width: 100px;
  1162. line-height: 28px;
  1163. span {
  1164. color: red;
  1165. }
  1166. }
  1167. .el-input {
  1168. width: 250px;
  1169. }
  1170. }
  1171. /deep/.el-button--info {
  1172. background-color: #409eff;
  1173. border-color: #409eff;
  1174. }
  1175. /deep/.el-date-editor {
  1176. cursor: pointer;
  1177. .el-range-input {
  1178. cursor: pointer;
  1179. }
  1180. }
  1181. </style>