modification.vue 9.7 KB

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