siteAdd.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <template>
  2. <view class="appWrapper">
  3. <!-- 站点新增start -->
  4. <form action="" @submit="formSubmit" v-if="!id">
  5. <view class="form-item margin-top">
  6. <view class="title">
  7. <text class="necessary">*</text>
  8. 站点名称:
  9. </view>
  10. <input name="userName" v-model="siteName"></input>
  11. </view>
  12. <view class="form-item">
  13. <view class="title"><text class="necessary">*</text>地址:</view>
  14. <input name="input" v-model="address"></input>
  15. </view>
  16. <view class="form-item">
  17. <view class="title"><text class="necessary">*</text>经度:</view>
  18. <input name="input" v-model="longitude"></input>
  19. </view>
  20. <view class="form-item">
  21. <view class="title"><text class="necessary">*</text>纬度:</view>
  22. <input name="input" v-model="latitude"></input>
  23. </view>
  24. <view class="form-item">
  25. <view class="title"></view>
  26. <button class=" cu-btn " style="padding:10rpx 20rpx" @click="getLocation()">
  27. <image src="../../static/nav-icon.png" style="width:25rpx;height:25rpx;margin-right:26rpx"></image>
  28. 获取当前经纬度
  29. </button>
  30. </view>
  31. <view class="form-item">
  32. <view class="title"><text class="necessary">*</text>联系人:</view>
  33. <input name="input" v-model="userName"></input>
  34. </view>
  35. <view class="form-item">
  36. <view class="title"><text class="necessary">*</text>手机号码:</view>
  37. <input name="input" v-model="phone"></input>
  38. </view>
  39. <view class="btn-area submitBottomBtn padding-lr-sm">
  40. <button class="bg-blue round margin-top" @click="addSubmit">提 交 </button>
  41. </view>
  42. </form>
  43. <!-- 站点新增end -->
  44. <!-- 站点修改start -->
  45. <form action="" @submit="formSubmit" v-else>
  46. <view class="form-item margin-top">
  47. <view class="title">
  48. <text class="necessary">*</text>
  49. 站点名称:
  50. </view>
  51. <input name="userName" v-model="siteMessage.siteName"></input>
  52. </view>
  53. <view class="form-item">
  54. <view class="title">地址:</view>
  55. <input name="input" v-model="siteMessage.address"></input>
  56. </view>
  57. <view class="form-item">
  58. <view class="title">经度:</view>
  59. <input name="input" v-model="siteMessage.longitude"></input>
  60. </view>
  61. <view class="form-item">
  62. <view class="title">纬度:</view>
  63. <input name="input" v-model="siteMessage.latitude"></input>
  64. </view>
  65. <view class="form-item">
  66. <view class="title"></view>
  67. <button class=" cu-btn " style="padding:10rpx 20rpx" @click="getLocation2()">
  68. <image src="../../static/nav-icon.png" style="width:25rpx;height:25rpx;margin-right:26rpx"></image>
  69. 获取当前经纬度
  70. </button>
  71. </view>
  72. <view class="form-item">
  73. <view class="title">联系人:</view>
  74. <input name="input" v-model="siteMessage.userName"></input>
  75. </view>
  76. <view class="form-item">
  77. <view class="title">手机号码:</view>
  78. <input name="input" v-model="siteMessage.phone"></input>
  79. </view>
  80. <view class="btn-area submitBottomBtn padding-lr-sm">
  81. <button class="bg-blue round margin-top" @click="editSubmit">提 交 </button>
  82. </view>
  83. </form>
  84. <!-- 站点修改end -->
  85. </view>
  86. </template>
  87. <script>
  88. //引入js sdk的封装
  89. import * as jwx from '../../util/jssdk.js'
  90. export default {
  91. data() {
  92. return {
  93. id: 0,
  94. latitude: "",
  95. siteName: "",
  96. userName: "",
  97. phone: "",
  98. address: "",
  99. longitude: "",
  100. siteMessage:{}
  101. }
  102. },
  103. onLoad: function(option) {
  104. this.id=option.id
  105. if (option.id) {
  106. uni.setNavigationBarTitle({
  107. title: '站点修改'
  108. });
  109. this.getSiteList({"id":option.id})
  110. } else {
  111. uni.setNavigationBarTitle({
  112. title: '站点新增'
  113. });
  114. }
  115. },
  116. methods: {
  117. //新增
  118. getLocation(){
  119. // 将this赋值给that
  120. let that = this
  121. // 微信公众号获取位置
  122. jwx.configWeiXin(jweixin => {
  123. wx.getLocation({
  124. type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  125. success: function (res) {
  126. that.longitude=res.longitude
  127. that.latitude=res.latitude
  128. }
  129. });
  130. });
  131. },
  132. //修改
  133. getLocation2(){
  134. // 将this赋值给that
  135. let that = this
  136. // 微信公众号获取位置
  137. jwx.configWeiXin(jweixin => {
  138. wx.getLocation({
  139. type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  140. success: function (res) {
  141. that.siteMessage.longitude=res.longitude
  142. that.siteMessage.latitude=res.latitude
  143. }
  144. });
  145. });
  146. },
  147. //新增验证并提交
  148. addSubmit() {
  149. if (!this.siteName) {
  150. uni.showToast({
  151. title: "请输入站点名称...",
  152. icon: "none"
  153. });
  154. return
  155. }
  156. if (!this.address) {
  157. uni.showToast({
  158. title: "请输入地址...",
  159. icon: "none"
  160. });
  161. return
  162. }
  163. if (!this.longitude) {
  164. uni.showToast({
  165. title: "请输入经度...",
  166. icon: "none"
  167. });
  168. return
  169. }
  170. if (!this.latitude) {
  171. uni.showToast({
  172. title: "请输入纬度...",
  173. icon: "none"
  174. });
  175. return
  176. }
  177. if (!this.userName) {
  178. uni.showToast({
  179. title: "请输入联系人...",
  180. icon: "none"
  181. });
  182. return
  183. }
  184. if (!this.phone) {
  185. uni.showToast({
  186. title: "请输入手机号码...",
  187. icon: "none"
  188. });
  189. return
  190. }
  191. if (!/^1[3456789]\d{9}$/.test(this.phone)){
  192. uni.showToast({
  193. title: "请输入正确的手机号码...",
  194. icon:"none"
  195. });
  196. return
  197. }
  198. this.getAddSite({
  199. "siteName": this.siteName,
  200. "userName": this.userName,
  201. "phone": this.phone,
  202. "address": this.address,
  203. "longitude": this.longitude,
  204. "latitude": this.latitude
  205. })
  206. },
  207. //编辑验证并提交
  208. editSubmit() {
  209. if (!this.siteMessage.siteName) {
  210. uni.showToast({
  211. title: "请填写站点名称...",
  212. icon: "none"
  213. });
  214. return
  215. }
  216. if (!this.siteMessage.address) {
  217. uni.showToast({
  218. title: "请输入地址...",
  219. icon: "none"
  220. });
  221. return
  222. }
  223. if (!this.siteMessage.longitude) {
  224. uni.showToast({
  225. title: "请输入经度...",
  226. icon: "none"
  227. });
  228. return
  229. }
  230. if (!this.siteMessage.latitude) {
  231. uni.showToast({
  232. title: "请输入纬度...",
  233. icon: "none"
  234. });
  235. return
  236. }
  237. if (!this.siteMessage.userName) {
  238. uni.showToast({
  239. title: "请输入联系人...",
  240. icon: "none"
  241. });
  242. return
  243. }
  244. if (!this.siteMessage.phone) {
  245. uni.showToast({
  246. title: "请输入手机号码...",
  247. icon: "none"
  248. });
  249. return
  250. }
  251. if (!/^1[3456789]\d{9}$/.test(this.siteMessage.phone)){
  252. uni.showToast({
  253. title: "请输入正确的手机号码...",
  254. icon:"none"
  255. });
  256. return
  257. }
  258. this.setEditSite({
  259. "id":this.id,
  260. "siteName": this.siteMessage.siteName,
  261. "userName": this.siteMessage.userName,
  262. "phone": this.siteMessage.phone,
  263. "address": this.siteMessage.address,
  264. "longitude": this.siteMessage.longitude,
  265. "latitude": this.siteMessage.latitude
  266. })
  267. },
  268. // 新增请求
  269. async getAddSite(ming = {}) {
  270. const res = await this.$myRequest({
  271. url: 'SiteManagement/setAddSite',
  272. data: ming
  273. })
  274. if (!res.data.flag) {
  275. uni.showToast({
  276. title: "添加失败",
  277. icon: "none"
  278. });
  279. } else {
  280. uni.showToast({
  281. title: "添加成功",
  282. });
  283. }
  284. setTimeout(() => {
  285. uni.navigateTo({
  286. url: '/pages/siteManage/siteManage',
  287. });
  288. }, 1000);
  289. },
  290. // 修改回显请求
  291. async getSiteList(ming = {}) {
  292. const res = await this.$myRequest({
  293. url: 'SiteManagement/getSiteList',
  294. showLoading: true,
  295. data: ming
  296. })
  297. this.siteMessage=res.data.data[0];
  298. },
  299. // 编辑请求
  300. async setEditSite(ming = {}) {
  301. const res = await this.$myRequest({
  302. url: 'SiteManagement/setEditSite',
  303. data: ming
  304. })
  305. if (!res.data.flag) {
  306. uni.showToast({
  307. title: "编辑失败",
  308. icon: "none"
  309. });
  310. } else {
  311. uni.showToast({
  312. title: "编辑成功",
  313. });
  314. }
  315. setTimeout(() => {
  316. uni.navigateTo({
  317. url: '/pages/siteManage/siteManage',
  318. });
  319. }, 1000);
  320. },
  321. }
  322. }
  323. </script>
  324. <style lang="scss">
  325. .cu-form-group {
  326. border-top: 0;
  327. }
  328. input,
  329. select,
  330. option {
  331. line-height: 70rpx;
  332. padding: 0 20rpx;
  333. height: 70rpx;
  334. border: 1px solid #EDEDED;
  335. // width:500rpx!important;
  336. background-color: #fff;
  337. box-sizing: border-box;
  338. appearance: none;
  339. -moz-appearance: none;
  340. -webkit-appearance: none;
  341. color: #999;
  342. }
  343. select:focus,
  344. select:active,
  345. select:hover {
  346. outline: none;
  347. }
  348. select {
  349. background: url(../../static/arrow.png) no-repeat scroll 98% center;
  350. background-size: 6%;
  351. }
  352. .form-item label text {
  353. position: relative;
  354. top: 2rpx
  355. }
  356. .form-item {
  357. padding: 0 40rpx;
  358. display: flex;
  359. align-items: top;
  360. margin-bottom: 20rpx;
  361. .title {
  362. width: 170rpx;
  363. position: relative;
  364. .necessary {
  365. color: red;
  366. display: inline-block;
  367. position: absolute;
  368. top: -2rpx;
  369. left: -20rpx;
  370. font-size: 40rpx;
  371. }
  372. }
  373. input,
  374. select {
  375. width: 500rpx;
  376. font-size: 28rpx;
  377. }
  378. }
  379. /* 站点多选下拉样式 start */
  380. .layui-btn {
  381. background-color: #5fb878;
  382. }
  383. a {
  384. text-decoration: none;
  385. }
  386. .label {
  387. padding: 2px 0px;
  388. background: #aaa;
  389. border-radius: 2px;
  390. color: #fff;
  391. display: block;
  392. line-height: 20px;
  393. height: 20px;
  394. margin: 2px 5px 2px 0;
  395. float: left;
  396. }
  397. .label span {
  398. padding: 0 5px;
  399. color: #fff;
  400. }
  401. .close {
  402. padding: 1px 5px !important;
  403. }
  404. .close:hover {
  405. /* background-color: #009E94;
  406. border-radius: 2px;
  407. color: tomato; */
  408. }
  409. .selectId input {
  410. width: 100% !important;
  411. }
  412. .selectId input {
  413. height: 25px;
  414. padding: 1px 5px;
  415. border-radius: 3px;
  416. width: calc(100% - 12px);
  417. outline-color: #5fb878;
  418. border: 1px solid #5fb878;
  419. }
  420. .selectId {
  421. position: relative;
  422. }
  423. .selectId dl {
  424. border: 1px solid #eee;
  425. border-radius: 3px;
  426. margin: 2px 0px;
  427. max-height: 300px;
  428. overflow-x: hidden;
  429. white-space: nowrap;
  430. position: absolute;
  431. width: 100%;
  432. top: 40px;
  433. background: #fff;
  434. z-index: 1000
  435. }
  436. .selectId dl dd {
  437. margin: 0;
  438. padding: 5px 10px;
  439. }
  440. .selectId dl dd:hover {
  441. background-color: #5FB878;
  442. color: white;
  443. }
  444. .AD {
  445. /* width: 210px;
  446. margin-left: 40px; */
  447. overflow-y: auto;
  448. max-height: 200px;
  449. /* border: 2px solid #5fb878;
  450. border-radius: 6px;
  451. padding: 1px 2px; */
  452. }
  453. form .AD span {
  454. width: auto;
  455. }
  456. .siteSelect {
  457. width: 71%;
  458. display: inline-block;
  459. }
  460. /* 站点多选下拉样式end */
  461. </style>