siteAdd.vue 9.8 KB

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