siteAdd.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. getLocation(){
  118. // 将this赋值给that
  119. let that = this
  120. // 微信公众号获取位置
  121. jwx.configWeiXin(jweixin => {
  122. wx.getLocation({
  123. type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  124. success: function (res) {
  125. // var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
  126. // var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
  127. // var speed = res.speed; // 速度,以米/每秒计
  128. // var accuracy = res.accuracy; // 位置精度
  129. that.longitude=res.longitude
  130. that.latitude=res.latitude
  131. }
  132. });
  133. });
  134. },
  135. //新增验证并提交
  136. addSubmit() {
  137. if (!this.siteName) {
  138. uni.showToast({
  139. title: "请输入站点名称...",
  140. icon: "none"
  141. });
  142. return
  143. }
  144. if (!this.address) {
  145. uni.showToast({
  146. title: "请输入地址...",
  147. icon: "none"
  148. });
  149. return
  150. }
  151. if (!this.longitude) {
  152. uni.showToast({
  153. title: "请输入经度...",
  154. icon: "none"
  155. });
  156. return
  157. }
  158. if (!this.latitude) {
  159. uni.showToast({
  160. title: "请输入纬度...",
  161. icon: "none"
  162. });
  163. return
  164. }
  165. if (!this.userName) {
  166. uni.showToast({
  167. title: "请输入联系人...",
  168. icon: "none"
  169. });
  170. return
  171. }
  172. if (!this.phone) {
  173. uni.showToast({
  174. title: "请输入手机号码...",
  175. icon: "none"
  176. });
  177. return
  178. }
  179. if (!/^1[345678]\d{9}$/.test(this.phone)){
  180. uni.showToast({
  181. title: "请输入正确的手机号码...",
  182. icon:"none"
  183. });
  184. return
  185. }
  186. this.getAddSite({
  187. "siteName": this.siteName,
  188. "userName": this.userName,
  189. "phone": this.phone,
  190. "address": this.address,
  191. "longitude": this.longitude,
  192. "latitude": this.latitude
  193. })
  194. },
  195. //编辑验证并提交
  196. editSubmit() {
  197. if (!this.siteMessage.siteName) {
  198. uni.showToast({
  199. title: "请填写站点名称...",
  200. icon: "none"
  201. });
  202. return
  203. }
  204. if (!this.siteMessage.address) {
  205. uni.showToast({
  206. title: "请输入地址...",
  207. icon: "none"
  208. });
  209. return
  210. }
  211. if (!this.siteMessage.longitude) {
  212. uni.showToast({
  213. title: "请输入经度...",
  214. icon: "none"
  215. });
  216. return
  217. }
  218. if (!this.siteMessage.latitude) {
  219. uni.showToast({
  220. title: "请输入纬度...",
  221. icon: "none"
  222. });
  223. return
  224. }
  225. if (!this.siteMessage.userName) {
  226. uni.showToast({
  227. title: "请输入联系人...",
  228. icon: "none"
  229. });
  230. return
  231. }
  232. if (!this.siteMessage.phone) {
  233. uni.showToast({
  234. title: "请输入手机号码...",
  235. icon: "none"
  236. });
  237. return
  238. }
  239. if (!/^1[345678]\d{9}$/.test(this.siteMessage.phone)){
  240. uni.showToast({
  241. title: "请输入正确的手机号码...",
  242. icon:"none"
  243. });
  244. return
  245. }
  246. this.setEditSite({
  247. "id":this.id,
  248. "siteName": this.siteMessage.siteName,
  249. "userName": this.siteMessage.userName,
  250. "phone": this.siteMessage.phone,
  251. "address": this.siteMessage.address,
  252. "longitude": this.siteMessage.longitude,
  253. "latitude": this.siteMessage.latitude
  254. })
  255. },
  256. // 新增请求
  257. async getAddSite(ming = {}) {
  258. const res = await this.$myRequest({
  259. url: 'SiteManagement/setAddSite',
  260. data: ming
  261. })
  262. if (!res.data.flag) {
  263. uni.showToast({
  264. title: "添加失败",
  265. icon: "none"
  266. });
  267. } else {
  268. uni.showToast({
  269. title: "添加成功",
  270. });
  271. }
  272. setTimeout(() => {
  273. uni.navigateTo({
  274. url: '/pages/siteManage/siteManage',
  275. });
  276. }, 1000);
  277. },
  278. // 修改回显请求
  279. async getSiteList(ming = {}) {
  280. const res = await this.$myRequest({
  281. url: 'SiteManagement/getSiteList',
  282. showLoading: true,
  283. data: ming
  284. })
  285. this.siteMessage=res.data.data[0];
  286. },
  287. // 编辑请求
  288. async setEditSite(ming = {}) {
  289. const res = await this.$myRequest({
  290. url: 'SiteManagement/setEditSite',
  291. data: ming
  292. })
  293. if (!res.data.flag) {
  294. uni.showToast({
  295. title: "编辑失败",
  296. icon: "none"
  297. });
  298. } else {
  299. uni.showToast({
  300. title: "编辑成功",
  301. });
  302. }
  303. setTimeout(() => {
  304. uni.navigateTo({
  305. url: '/pages/siteManage/siteManage',
  306. });
  307. }, 1000);
  308. },
  309. }
  310. }
  311. </script>
  312. <style lang="scss">
  313. .cu-form-group {
  314. border-top: 0;
  315. }
  316. input,
  317. select,
  318. option {
  319. line-height: 70rpx;
  320. padding: 0 20rpx;
  321. height: 70rpx;
  322. border: 1px solid #EDEDED;
  323. // width:500rpx!important;
  324. background-color: #fff;
  325. box-sizing: border-box;
  326. appearance: none;
  327. -moz-appearance: none;
  328. -webkit-appearance: none;
  329. color: #999;
  330. }
  331. select:focus,
  332. select:active,
  333. select:hover {
  334. outline: none;
  335. }
  336. select {
  337. background: url(../../static/arrow.png) no-repeat scroll 98% center;
  338. background-size: 6%;
  339. }
  340. .form-item label text {
  341. position: relative;
  342. top: 2rpx
  343. }
  344. .form-item {
  345. padding: 0 40rpx;
  346. display: flex;
  347. align-items: top;
  348. margin-bottom: 20rpx;
  349. .title {
  350. width: 170rpx;
  351. position: relative;
  352. .necessary {
  353. color: red;
  354. display: inline-block;
  355. position: absolute;
  356. top: -2rpx;
  357. left: -20rpx;
  358. font-size: 40rpx;
  359. }
  360. }
  361. input,
  362. select {
  363. width: 500rpx;
  364. font-size: 28rpx;
  365. }
  366. }
  367. /* 站点多选下拉样式 start */
  368. .layui-btn {
  369. background-color: #5fb878;
  370. }
  371. a {
  372. text-decoration: none;
  373. }
  374. .label {
  375. padding: 2px 0px;
  376. background: #aaa;
  377. border-radius: 2px;
  378. color: #fff;
  379. display: block;
  380. line-height: 20px;
  381. height: 20px;
  382. margin: 2px 5px 2px 0;
  383. float: left;
  384. }
  385. .label span {
  386. padding: 0 5px;
  387. color: #fff;
  388. }
  389. .close {
  390. padding: 1px 5px !important;
  391. }
  392. .close:hover {
  393. /* background-color: #009E94;
  394. border-radius: 2px;
  395. color: tomato; */
  396. }
  397. .selectId input {
  398. width: 100% !important;
  399. }
  400. .selectId input {
  401. height: 25px;
  402. padding: 1px 5px;
  403. border-radius: 3px;
  404. width: calc(100% - 12px);
  405. outline-color: #5fb878;
  406. border: 1px solid #5fb878;
  407. }
  408. .selectId {
  409. position: relative;
  410. }
  411. .selectId dl {
  412. border: 1px solid #eee;
  413. border-radius: 3px;
  414. margin: 2px 0px;
  415. max-height: 300px;
  416. overflow-x: hidden;
  417. white-space: nowrap;
  418. position: absolute;
  419. width: 100%;
  420. top: 40px;
  421. background: #fff;
  422. z-index: 1000
  423. }
  424. .selectId dl dd {
  425. margin: 0;
  426. padding: 5px 10px;
  427. }
  428. .selectId dl dd:hover {
  429. background-color: #5FB878;
  430. color: white;
  431. }
  432. .AD {
  433. /* width: 210px;
  434. margin-left: 40px; */
  435. overflow-y: auto;
  436. max-height: 200px;
  437. /* border: 2px solid #5fb878;
  438. border-radius: 6px;
  439. padding: 1px 2px; */
  440. }
  441. form .AD span {
  442. width: auto;
  443. }
  444. .siteSelect {
  445. width: 71%;
  446. display: inline-block;
  447. }
  448. /* 站点多选下拉样式end */
  449. </style>