modification.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view>
  3. <view style="position: fixed;z-index: 100;">
  4. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="基地修改"></uni-nav-bar>
  5. </view>
  6. <view class="addimg">
  7. <view class="addimg_add" @click="gainimg">
  8. <u-icon name="plus" size="60rpx" color="#A5A6A8"></u-icon>
  9. <image :src="baseinfo.base_img" mode="" class="addimg_img"></image>
  10. </view>
  11. </view>
  12. <view class="base_text">
  13. <p class="title">基地信息</p>
  14. <view class="base_text_item1">
  15. <u-icon name="fangzi" custom-prefix="custom-icon" class="icon"></u-icon>
  16. <span>基地名称</span>
  17. <input type="text" v-model="baseinfo.base_name" placeholder="请输入基地名称" />
  18. </view>
  19. <view class="base_text_item1">
  20. <u-icon name="ren1" custom-prefix="custom-icon" class="icon"></u-icon>
  21. <span>负责人</span>
  22. <input type="text" v-model="baseinfo.base_charge " placeholder="请输入基地负责人" />
  23. </view>
  24. <view class="base_text_item1">
  25. <u-icon name="lianxidianhua" custom-prefix="custom-icon" class="icon"></u-icon>
  26. <span>联系电话</span>
  27. <input type="text" v-model="baseinfo.base_phone" placeholder="请输入联系电话" />
  28. </view>
  29. <view class="base_text_item1">
  30. <u-icon name="mianji" custom-prefix="custom-icon" class="icon"></u-icon>
  31. <span>面积(亩)</span>
  32. <input type="number" v-model="baseinfo.base_area" placeholder="请输入基地面积" />
  33. </view>
  34. <view class="base_text_item2">
  35. <u-icon name="miaoshu" custom-prefix="custom-icon" class="icon"></u-icon>
  36. <span>基地描述</span>
  37. <textarea v-model="baseinfo.base_describe " maxlength="80" auto-height class="textarea" placeholder="请输入基地描述(不能大于80字)" />
  38. </view>
  39. <view class="base_text_item1" @click="map">
  40. <u-icon name="Frame1" custom-prefix="custom-icon" class="icon"></u-icon>
  41. <span>基地定位</span>
  42. <input type="text" v-model="city" placeholder="请选择地址" disabled style="position: absolute;right: 60rpx;width: 60%;"/>
  43. <u-icon name="arrow-right" class="iconright"></u-icon>
  44. </view>
  45. <view class="base_text_item1" @click="binding">
  46. <u-icon name="bangding" custom-prefix="custom-icon" class="icon"></u-icon>
  47. <span>设备绑定</span>
  48. <u-icon name="arrow-right" class="iconright"></u-icon>
  49. </view>
  50. <view class="base_id_box">
  51. <view class="base_id" v-for="(item,key,index) in base_id" :key="index">
  52. <view class="base_id_item" v-for="(items,indexs) in item" :key="indexs">
  53. <span>{{key}}</span>
  54. <span>{{items}}</span>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="btn" @click="tijiao">
  59. 确 定
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <style lang="scss">
  65. </style>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. base_id:{},
  71. baseinfo:{
  72. base_name:'',//必传(str) 基地名称
  73. base_charge:'',//必传(str) 负责人
  74. base_phone:'',//必传(str) 联系电话
  75. base_img:'',// 必传(str) 基地图片
  76. base_area:'',//必传(str) 基地面积
  77. base_equip:'', //必传(str) 绑定设备 如果绑定多个设备传 289#299, 如果是单一设备传298
  78. base_describe:'',//非必传(str) 基地描述
  79. lng:'',//必传(str) 经度
  80. lat:'',//必传(str) 纬度
  81. },
  82. city:''
  83. }
  84. },
  85. methods: {
  86. //base.bases.base_list新增基地 //modify 修改 list 列表
  87. async addbase() { //获取分布位置
  88. const res = await this.$myRequest({
  89. url: '/api/api_gateway?method=base.bases.base_list',
  90. data:this.baseinfo
  91. })
  92. console.log(res)
  93. },
  94. clickLeft(){
  95. uni.navigateTo({
  96. url:"./index"
  97. })
  98. },
  99. binding(){
  100. uni.navigateTo({
  101. url:"./allocation?type="+this.baseinfo.base_equip
  102. })
  103. },
  104. gainimg() { //添加图片
  105. uni.chooseImage({
  106. count: 1, //默认9
  107. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  108. sourceType: ['album', 'camera'], //从相册选择
  109. success: (res) => {
  110. uni.uploadFile({
  111. url: 'http://182.92.193.64:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  112. filePath: res.tempFilePaths[0],
  113. name: 'img_file',
  114. formData: {
  115. 'user': 'test'
  116. },
  117. success: (uploadFileRes) => {
  118. this.baseinfo.base_img = JSON.parse(uploadFileRes.data).data.src
  119. // this.$forceUpdate() //强制刷新视图
  120. }
  121. });
  122. }
  123. })
  124. },
  125. map(){
  126. uni.getLocation({
  127. type: 'wgs84',
  128. success: (res) => {
  129. console.log('当前位置的经度:' + res.longitude);
  130. console.log('当前位置的纬度:' + res.latitude);
  131. this.longitude = res.longitude
  132. this.latitude = res.latitude
  133. uni.chooseLocation({
  134. success:(res)=>{
  135. console.log('位置名称:' + res.name);//address 详细地址
  136. this.city = res.name
  137. this.baseinfo.lat = res.latitude
  138. this.baseinfo.lng = res.longitude
  139. }
  140. });
  141. }
  142. });
  143. },
  144. tijiao(){
  145. // console.log(this.baseinfo)
  146. // this.addbase()
  147. // localStorage.removeItem("id")
  148. // uni.navigateBack({
  149. // delta:1
  150. // })
  151. if(this.baseinfo.base_img==''){
  152. uni.showToast({
  153. title: '请选择基地图片',
  154. duration: 2000,
  155. icon:"none"
  156. });
  157. }else if(this.baseinfo.base_name==''){
  158. uni.showToast({
  159. title: '请填写正基地名称',
  160. duration: 2000,
  161. icon:"none"
  162. });
  163. }else if(this.baseinfo.base_charge==''){
  164. uni.showToast({
  165. title: '请填写基地负责人',
  166. duration: 2000,
  167. icon:"none"
  168. });
  169. }else if(this.baseinfo.base_phone==''){
  170. uni.showToast({
  171. title: '请填写手机号',
  172. duration: 2000,
  173. icon:"none"
  174. });
  175. }else if(this.baseinfo.base_area==''){
  176. uni.showToast({
  177. title: '请填写基地面积',
  178. duration: 2000,
  179. icon:"none"
  180. });
  181. }else if(this.baseinfo.lng==''){
  182. uni.showToast({
  183. title: '请选择基地地址',
  184. duration: 2000,
  185. icon:"none"
  186. });
  187. }else if(this.baseinfo.base_id==''){
  188. uni.showToast({
  189. title: '请绑定基地设备',
  190. duration: 2000,
  191. icon:"none"
  192. });
  193. }else{
  194. if(!/^1[23456789]\d{9}$/.test(this.baseinfo.base_phone)){
  195. uni.showToast({
  196. title: '请填写正确的手机号',
  197. duration: 2000,
  198. icon:"none"
  199. });
  200. }else{
  201. console.log(this.baseinfo)
  202. this.addbase()
  203. localStorage.removeItem("id")
  204. uni.navigateBack({
  205. delta:1
  206. })
  207. }
  208. }
  209. },
  210. selectaddress(lat,lng) { //获取分布位置
  211. uni.request({
  212. url: '/dpc/geocoder/v1?location='+lat+","+lng+'&key=B2EBZ-2UW6P-RDJDG-LCMLE-AIQUS-CGFMJ',
  213. success: (res) => {
  214. this.city = res.data.result.address
  215. console.log(res.data.result.address)
  216. }
  217. })
  218. },
  219. },
  220. onLoad(option) {
  221. this.baseinfo = JSON.parse(option.id)
  222. this.baseinfo.base_id = JSON.parse(option.id).id
  223. this.baseinfo.ret = "modify"
  224. delete this.baseinfo.id
  225. this.selectaddress(this.baseinfo.lat,this.baseinfo.lng)
  226. console.log(this.baseinfo)
  227. },
  228. onShow(){
  229. this.base_id=JSON.parse(localStorage.getItem("id"))
  230. if(localStorage.getItem("id")!=null){
  231. var arr = []
  232. for(var key in this.base_id){
  233. arr.push(this.base_id[key].join("#"))
  234. }
  235. this.baseinfo.base_equip = arr.join("#")
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss">
  241. .addimg{
  242. position: absolute;
  243. top: 108rpx;
  244. width: 100%;
  245. .addimg_add{
  246. position: relative;
  247. width: 90%;
  248. height: 276rpx;
  249. margin: 0 auto;
  250. background-color: #F7F8FA;
  251. text-align: center;
  252. line-height: 276rpx;
  253. color: #A7A8AA;
  254. .addimg_img{
  255. position: absolute;
  256. top: 0;
  257. width: 100%;
  258. left: 0;
  259. height: 276rpx;
  260. }
  261. }
  262. }
  263. .base_text{
  264. position: absolute;
  265. top: 390rpx;
  266. width: 100%;
  267. .title{
  268. width: 90%;
  269. margin: 20rpx auto;
  270. }
  271. .base_text_item2{
  272. width: 90%;
  273. margin: 10rpx auto 20rpx;
  274. padding: 16rpx 20rpx;
  275. background-color: #F7F8FA;
  276. display: flex;
  277. box-sizing: border-box;
  278. position: relative;
  279. height: 200rpx;
  280. .icon{
  281. color: #5FBBA0;
  282. height: 42rpx;
  283. }
  284. span{
  285. margin: 0 20rpx;
  286. }
  287. .textarea{
  288. font-size: 24rpx;
  289. text-align: right;
  290. position: absolute;
  291. right: 20rpx;
  292. width: 70%;
  293. height: 200rpx;
  294. }
  295. }
  296. .base_text_item1{
  297. display: flex;
  298. position: relative;
  299. width: 90%;
  300. height: 70rpx;
  301. margin: 10rpx auto 20rpx;
  302. padding: 16rpx 20rpx;
  303. background-color: #F7F8FA;
  304. box-sizing: border-box;
  305. .icon{
  306. color: #5FBBA0;
  307. }
  308. span{
  309. margin: 0 20rpx;
  310. }
  311. input{
  312. position: absolute;
  313. right: 20rpx;
  314. width: 70%;
  315. text-align: right;
  316. font-size: 24rpx;
  317. margin-top: 5rpx;
  318. }
  319. .iconright{
  320. position: absolute;
  321. right: 20rpx;
  322. top: 28rpx;
  323. color: #B5B6B8;
  324. font-size: 24rpx;
  325. }
  326. }
  327. }
  328. .base_id_box{
  329. width: 90%;
  330. margin: 20rpx auto 70rpx;
  331. }
  332. .base_id{
  333. width: 100%;
  334. .base_id_item{
  335. width: 95%;
  336. padding: 10rpx 30rpx;
  337. display: flex;
  338. justify-content: space-between;
  339. font-size: 28rpx;
  340. background-color: #F7F8FA;
  341. color: #616162;
  342. box-sizing: border-box;
  343. margin: 20rpx auto;
  344. }
  345. }
  346. .btn{
  347. width: 90%;
  348. position: fixed;
  349. bottom: 0;
  350. right: 5%;
  351. text-align: center;
  352. height: 70rpx;
  353. line-height: 70rpx;
  354. background-color: #359773;
  355. font-size: 34rpx;
  356. border-radius: 35rpx;
  357. color: #FFFFFF;
  358. }
  359. </style>