siteAdd.vue 12 KB

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