index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <div>
  3. <van-nav-bar
  4. title="应急仓库编辑"
  5. left-arrow
  6. placeholder
  7. @click-left="goback"
  8. :fixed="true"
  9. @click-right="bjclick"
  10. >
  11. </van-nav-bar>
  12. <div>
  13. <div class="content">
  14. <div>
  15. <van-cell-group>
  16. <van-field
  17. v-model="whdata.value.name"
  18. label="仓库命名"
  19. input-align="right"
  20. :readonly="isedit"
  21. placeholder="请输入仓库命名"
  22. />
  23. <van-field
  24. v-model="whdata.value.manageUnit"
  25. label="管理单位"
  26. input-align="right"
  27. :readonly="isedit"
  28. placeholder="请输入管理单位"
  29. />
  30. <van-field
  31. v-model="whdata.value.contactName"
  32. required
  33. :readonly="isedit"
  34. label="联系人"
  35. input-align="right"
  36. placeholder="请输入联系人"
  37. />
  38. <van-field
  39. v-model="whdata.value.contactPhone"
  40. required
  41. label="联系方式"
  42. :readonly="isedit"
  43. input-align="right"
  44. placeholder="请输入联系方式"
  45. />
  46. <van-field
  47. v-model="whdata.value.address"
  48. label="地址"
  49. :readonly="isedit"
  50. input-align="right"
  51. placeholder="请输入地址"
  52. >
  53. <template #button v-if="isedit">
  54. <van-button
  55. size="small"
  56. type="primary"
  57. color="#f2f4fa"
  58. @click="searchaddr"
  59. ><van-icon name="search"
  60. /></van-button>
  61. </template>
  62. </van-field>
  63. </van-cell-group>
  64. </div>
  65. </div>
  66. <div style="padding: 15px; background: #fff; position: relative">
  67. <Map
  68. v-model:map="state.map"
  69. style="
  70. height: 240px;
  71. borderradius: 2px;
  72. boxshadow: 0px 0px 0px 1px #d9d9d9;
  73. "
  74. />
  75. <div v-if="isshowmove" class="mark">
  76. <img :src="icon_map_location" />
  77. </div>
  78. <div v-if="isedit" class="marklocation" @click="getLocation">
  79. <img src="../../assets/icons/incident/location.svg" />
  80. </div>
  81. <div v-if="isedit" style="position: absolute; right: 21px; top: 21px">
  82. <van-button type="primary" size="mini" @click="selectpoint">{{
  83. isshowmove ? '确定' : '选点'
  84. }}</van-button>
  85. </div>
  86. </div>
  87. <div style="padding: 30px 20px" v-if="isedit">
  88. <van-button
  89. type="primary"
  90. block
  91. style="border-radius: 30px"
  92. @click="dosavedata"
  93. >保存</van-button
  94. >
  95. </div>
  96. </div>
  97. </div>
  98. </template>
  99. <script setup>
  100. import { ref, reactive, onUpdated, onMounted, watch } from 'vue';
  101. import { RouterView, useRoute, useRouter } from 'vue-router';
  102. import icon_map_location from '@/assets/icons/home/icon_map_location@2x.png';
  103. import {
  104. api_getresource,
  105. api_getresourcedetail,
  106. api_putresource,
  107. api_bj,
  108. api_isbj,
  109. } from '@/service/warehouse';
  110. import { api_getusergps } from '@/service/login';
  111. import { Toast, Notify, Dialog } from 'vant';
  112. import { BaseMediaUrl } from '@/utils';
  113. import { upload } from '@/api/common';
  114. import Map from '@/components/MapView';
  115. const state = reactive({
  116. map: null,
  117. _marker: null,
  118. loading: false,
  119. postition: {
  120. longitude: '',
  121. latitude: '',
  122. name: '',
  123. },
  124. });
  125. const whdata = reactive({
  126. value: {
  127. name: '',
  128. manageUnit: '',
  129. contactName: '',
  130. contactPhone: '',
  131. longitude: '',
  132. latitude: '',
  133. },
  134. });
  135. const isedit = ref(false);
  136. const isempt = ref(true);
  137. onMounted(() => {
  138. whdata.value = JSON.parse(localStorage.getItem('cck'));
  139. // isedit.value = true;
  140. isedit.value = localStorage.getItem("cedit")=="true"?true:false;
  141. // debugger
  142. var taskid = route.query.taskid;
  143. if (taskid) {
  144. api_isbj(taskid).then((res) => {
  145. isbj.value = !res.data;
  146. console.log(isbj.value);
  147. });
  148. }
  149. state.postition = {
  150. longitude: whdata.value.longitude,
  151. latitude: whdata.value.latitude,
  152. name: whdata.value.address,
  153. };
  154. if (state.map && state._marker) {
  155. state._marker.remove();
  156. state._marker = null;
  157. }
  158. if (state.map) {
  159. setpoint(
  160. Number(whdata.value.longitude),
  161. Number(whdata.value.latitude),
  162. whdata.value.address,
  163. );
  164. }
  165. });
  166. const isshowmove = ref(false);
  167. let allmark = [];
  168. const selectpoint = () => {
  169. if (isshowmove.value) {
  170. var center = state.map.getCenter();
  171. getlocalname(center.lng.toFixed(6) + ',' + center.lat.toFixed(6));
  172. } else {
  173. isshowmove.value = true;
  174. state._marker.remove();
  175. }
  176. };
  177. const setpoint = (longitude, latitude, name) => {
  178. if (state._marker) {
  179. state._marker.remove();
  180. }
  181. var el = document.createElement('div');
  182. el.id = 'marker';
  183. el.style.backgroundImage = `url(${icon_map_location})`;
  184. el.style.backgroundSize = 'cover';
  185. el.style.width = '24px';
  186. el.style.height = '24px';
  187. el.style.borderRadius = '50%';
  188. const popup = new window.minemap.Popup({
  189. closeOnClick: false,
  190. closeButton: false,
  191. offset: [0, -15],
  192. }).setText(name);
  193. state._marker = new window.minemap.Marker(el, {
  194. offset: [-12, -12],
  195. })
  196. .setLngLat([longitude, latitude])
  197. .setPopup(popup)
  198. .addTo(state.map);
  199. state.map.flyTo({
  200. center: [longitude, latitude],
  201. zoom: 14,
  202. bearing: 0,
  203. pitch: 0,
  204. duration: 2000,
  205. });
  206. state._marker.togglePopup();
  207. whdata.value.address = name;
  208. whdata.value.latitude = latitude;
  209. whdata.value.longitude = longitude;
  210. isshowmove.value = false;
  211. };
  212. const searchaddr = () => {
  213. isshowmove.value = false;
  214. fetch(
  215. `https://minedata.cn/service/lbs/search/v1/keywords?keywords=${whdata.value.address}&city=宿迁&citylimit=true&page_idx=1&page_size=10&key=${window.key}`,
  216. )
  217. .then((res) => res.json())
  218. .then((data) => {
  219. // console.log(data.pois)
  220. var clearallmark = () => {
  221. state._marker.remove();
  222. if (allmark.length > 0) {
  223. allmark.map((item) => {
  224. item.remove();
  225. });
  226. allmark = [];
  227. }
  228. };
  229. clearallmark();
  230. var top = [];
  231. var bottom = [];
  232. data.pois.map((item) => {
  233. if (top.length < 1) {
  234. top = [
  235. Number(item.location.split(',')[0]),
  236. Number(item.location.split(',')[1]),
  237. ];
  238. bottom = [
  239. Number(item.location.split(',')[0]),
  240. Number(item.location.split(',')[1]),
  241. ];
  242. }
  243. var el = document.createElement('div');
  244. el.id = 'marker';
  245. el.style.backgroundImage = `url(${icon_map_location})`;
  246. el.style.backgroundSize = 'cover';
  247. el.style.width = '24px';
  248. el.style.height = '24px';
  249. el.style.borderRadius = '50%';
  250. el.onclick = () => {
  251. clearallmark();
  252. setpoint(
  253. Number(item.location.split(',')[0]),
  254. Number(item.location.split(',')[1]),
  255. item.name,
  256. );
  257. };
  258. const popup = new window.minemap.Popup({
  259. closeOnClick: false,
  260. closeButton: false,
  261. offset: [0, -15],
  262. }).setText(item.name);
  263. var mark = new window.minemap.Marker(el, {
  264. offset: [-12, -12],
  265. })
  266. .setLngLat([
  267. Number(item.location.split(',')[0]),
  268. Number(item.location.split(',')[1]),
  269. ])
  270. .setPopup(popup)
  271. .addTo(state.map);
  272. allmark.push(mark);
  273. mark.togglePopup();
  274. if (top[0] < Number(item.location.split(',')[0])) {
  275. top[0] = Number(item.location.split(',')[0]);
  276. }
  277. if (top[1] > Number(item.location.split(',')[1])) {
  278. top[1] = Number(item.location.split(',')[1]);
  279. }
  280. if (bottom[0] > Number(item.location.split(',')[0])) {
  281. bottom[0] = Number(item.location.split(',')[0]);
  282. }
  283. if (bottom[1] < Number(item.location.split(',')[1])) {
  284. bottom[1] = Number(item.location.split(',')[1]);
  285. }
  286. });
  287. state.map.fitBounds([top, bottom]);
  288. });
  289. };
  290. const getlocalname = (location) => {
  291. fetch(
  292. `https://minedata.cn/service/lbs/reverse/v1/regeo?location=${location}&key=${window.key}`,
  293. )
  294. .then((res) => res.json())
  295. .then((data) => {
  296. setpoint(
  297. Number(location.split(',')[0]),
  298. Number(location.split(',')[1]),
  299. data.regeocodes[0].formatted_address,
  300. );
  301. });
  302. };
  303. const getLocation = () => {
  304. api_getusergps().then((res) => {
  305. var lat = null;
  306. var lon = null;
  307. var iserror = false;
  308. try {
  309. lat = res.result[0].lat;
  310. lon = res.result[0].lon;
  311. if (lat == null || lat == undefined) iserror = true;
  312. } catch (e) {
  313. iserror = true;
  314. }
  315. if (!iserror) {
  316. // debugger
  317. var location = `${lon},${lat}`;
  318. getlocalname(location);
  319. // setpoint(lon,lat,data.regeocodes[0].formatted_address)
  320. } else {
  321. Notify({
  322. type: 'danger',
  323. message: 'App不支持地理定位。',
  324. });
  325. }
  326. });
  327. };
  328. const goback = () => {
  329. try {
  330. uni.navigateBack();
  331. } catch (E) {}
  332. window.history.back();
  333. };
  334. const dosavedata = () => {
  335. Toast.loading({
  336. message: '加载中...',
  337. duration: 0,
  338. forbidClick: true,
  339. });
  340. var data = whdata.value;
  341. api_putresource(data)
  342. .then((res) => {
  343. Toast.clear();
  344. setTimeout(() => {
  345. Toast('保存成功');
  346. }, 1000);
  347. // Notify({ type: 'success', message: '保存成功'});
  348. getdata();
  349. })
  350. .catch((ee) => {
  351. Toast.clear();
  352. });
  353. };
  354. const isbj = ref(true);
  355. const route = useRoute();
  356. </script>
  357. <style lang="scss">
  358. .content label,
  359. .content span {
  360. font-size: 15px;
  361. font-family: PingFangSC, PingFangSC-Regular;
  362. color: #333333;
  363. }
  364. .bjbtn {
  365. font-size: 14px;
  366. font-weight: 500;
  367. color: #ffffff;
  368. font-size: 13px;
  369. font-weight: 500;
  370. background: #bb0000;
  371. padding: 3px 8px;
  372. border-radius: 2px;
  373. }
  374. .content {
  375. .cell-header {
  376. font-family: PingFangSC, PingFangSC-Regular;
  377. font-weight: 400;
  378. line-height: 42px;
  379. padding: 0px 15px;
  380. span {
  381. font-size: 12px;
  382. }
  383. div {
  384. font-size: 14px;
  385. color: #0b33a8;
  386. }
  387. }
  388. }
  389. .mark {
  390. position: absolute;
  391. top: 50%;
  392. left: 50%;
  393. transform: translate(-50%, -50%);
  394. img {
  395. width: 24px;
  396. height: 24px;
  397. }
  398. }
  399. .marklocation {
  400. img {
  401. width: 24px;
  402. height: 24px;
  403. }
  404. position: absolute;
  405. bottom: 10%;
  406. right: 20px;
  407. }
  408. </style>