modification.vue 9.5 KB

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