modification.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  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="jidiguanli" 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="dingwei" 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" v-if="baseobjtf">
  53. <view class="base_id" v-for="(item,index) in base_id" :key="index">
  54. <view class="base_id_item">
  55. <span>{{item.device_id}}</span>
  56. <span>{{item.type_name}}</span>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="base_id_box" v-else>
  61. <view class="base_id" v-for="items,indexs in baseobj" :key="indexs">
  62. <view class="base_id_item">
  63. <span>{{items.arr}}</span>
  64. <span>{{items.name}}</span>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="btn" @click="tijiao">
  69. 确 定
  70. </view>
  71. </view>
  72. </view>
  73. <kps-image-cutter @ok="onok" @cancel="oncancle" :url="imgs" :fixed="false" :blob="false" :maxWidth="500" :maxHeight="500"></kps-image-cutter>
  74. </view>
  75. </template>
  76. <script>
  77. import kpsImageCutter from "@/components/ksp-image-cutter/ksp-image-cutter.vue";
  78. export default {
  79. components:{
  80. kpsImageCutter
  81. },
  82. data() {
  83. return {
  84. base_id:[],
  85. baseobj:[],
  86. baseinfo:{
  87. base_name:'',//必传(str) 基地名称
  88. base_charge:'',//必传(str) 负责人
  89. base_phone:'',//必传(str) 联系电话
  90. base_img:'',// 必传(str) 基地图片
  91. base_area:'',//必传(str) 基地面积
  92. base_equip:'', //必传(str) 绑定设备 如果绑定多个设备传 289#299, 如果是单一设备传298
  93. base_describe:'',//非必传(str) 基地描述
  94. lng:'',//必传(str) 经度
  95. lat:'',//必传(str) 纬度
  96. },
  97. city:'',
  98. imgs:"",
  99. baseobjtf:true
  100. }
  101. },
  102. methods: {
  103. //base.bases.base_list新增基地 //modify 修改 list 列表
  104. async addbase() { //获取分布位置
  105. const res = await this.$myRequest({
  106. url: '/api/api_gateway?method=base.bases.base_list',
  107. data:this.baseinfo,
  108. ret:"modify"
  109. })
  110. console.log(res)
  111. if(res){
  112. uni.showToast({
  113. title: '修改成功',
  114. duration: 2000,
  115. icon:"none"
  116. });
  117. }
  118. },
  119. async ybase() { //获取基地设备
  120. const res = await this.$myRequest({
  121. url: '/api/api_gateway?method=base.bases.base_map_list',
  122. data: {
  123. base_id: this.baseinfo.base_id
  124. }
  125. })
  126. this.base_id = res
  127. console.log(res)
  128. },
  129. clickLeft(){
  130. uni.navigateTo({
  131. url:"./index"
  132. })
  133. uni.removeStorage({
  134. key:"typeid"
  135. })
  136. uni.removeStorage({
  137. key:"location"
  138. })
  139. },
  140. binding(){
  141. uni.navigateTo({
  142. url:"./allocation?base_id="+this.baseinfo.base_id
  143. })
  144. },
  145. gainimg() { //添加图片
  146. uni.chooseImage({
  147. count: 1, //默认9
  148. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  149. sourceType: ['album', 'camera'], //从相册选择
  150. success: (res) => {
  151. this.imgs = res.tempFilePaths[0]
  152. }
  153. })
  154. },
  155. map(){
  156. uni.navigateTo({
  157. url:"city"
  158. })
  159. },
  160. tijiao(){
  161. if(this.baseinfo.base_img==''){
  162. uni.showToast({
  163. title: '请选择基地图片',
  164. duration: 2000,
  165. icon:"none"
  166. });
  167. }else if(this.baseinfo.base_name==''){
  168. uni.showToast({
  169. title: '请填写正基地名称',
  170. duration: 2000,
  171. icon:"none"
  172. });
  173. }else if(this.baseinfo.base_charge==''){
  174. uni.showToast({
  175. title: '请填写基地负责人',
  176. duration: 2000,
  177. icon:"none"
  178. });
  179. }else if(this.baseinfo.base_phone==''){
  180. uni.showToast({
  181. title: '请填写手机号',
  182. duration: 2000,
  183. icon:"none"
  184. });
  185. }else if(this.baseinfo.base_area==''){
  186. uni.showToast({
  187. title: '请填写基地面积',
  188. duration: 2000,
  189. icon:"none"
  190. });
  191. }else if(this.baseinfo.lng==''){
  192. uni.showToast({
  193. title: '请选择基地地址',
  194. duration: 2000,
  195. icon:"none"
  196. });
  197. }else if(this.baseinfo.base_id==''){
  198. uni.showToast({
  199. title: '请绑定基地设备',
  200. duration: 2000,
  201. icon:"none"
  202. });
  203. }else{
  204. if(!/^1[23456789]\d{9}$/.test(this.baseinfo.base_phone)){
  205. uni.showToast({
  206. title: '请填写正确的手机号',
  207. duration: 2000,
  208. icon:"none"
  209. });
  210. }else{
  211. if(!this.baseobjtf){
  212. var arr = []
  213. for(var i=0;i<this.baseobj.length;i++){
  214. arr.push(this.baseobj[i].arr)
  215. }
  216. this.baseinfo.base_equip = arr.join("#")
  217. }
  218. console.log(this.baseinfo)
  219. this.addbase()
  220. uni.removeStorage({
  221. key:"typeid"
  222. })
  223. uni.removeStorage({
  224. key:"location"
  225. })
  226. }
  227. }
  228. },
  229. selectaddress(lat,lng) { //获取分布位置
  230. uni.request({
  231. type: "GET",
  232. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," +lat + "&key=27273b81090f78759e4057f94474516f&radius=1000&extensions=all",
  233. dataType: "json",
  234. complete: ress => {
  235. console.log(ress)
  236. this.city = ress.data.regeocode.formatted_address
  237. }
  238. });
  239. },
  240. onok(ev){
  241. uni.uploadFile({
  242. url: 'https://wx.hnyfwlw.com/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  243. filePath: ev.path,
  244. name: 'img_file',
  245. formData: {
  246. 'user': 'test'
  247. },
  248. success: (uploadFileRes) => {
  249. this.baseinfo.base_img = JSON.parse(uploadFileRes.data).data.src
  250. // this.$forceUpdate() //强制刷新视图
  251. }
  252. });
  253. this.imgs = ''
  254. },
  255. oncancle(){
  256. this.imgs = ''
  257. }
  258. },
  259. onLoad(option) {
  260. console.log(JSON.parse(option.id))
  261. this.baseinfo = JSON.parse(option.id)
  262. this.baseinfo.base_id = JSON.parse(option.id).id
  263. this.baseinfo.ret = "modify"
  264. delete this.baseinfo.id
  265. this.selectaddress(this.baseinfo.lat,this.baseinfo.lng)
  266. this.ybase()
  267. },
  268. onShow(){
  269. uni.getStorage({
  270. key:"location",
  271. success:(res)=> {
  272. console.log(res.data)
  273. this.selectaddress(res.data[1],res.data[0])
  274. this.baseinfo.lat = res.data[1]
  275. this.baseinfo.lng = res.data[0]
  276. }
  277. })
  278. uni.getStorage({
  279. key: 'typeid',
  280. success: (res)=> {
  281. this.baseobjtf = false
  282. console.log(JSON.parse(res.data))
  283. var arr = []
  284. for(var key in JSON.parse(res.data)){
  285. console.log(key)
  286. for(var i=0;i<JSON.parse(res.data)[key].length;i++){
  287. var obj={
  288. name:key,
  289. arr:JSON.parse(res.data)[key][i]
  290. }
  291. arr.push(obj)
  292. }
  293. }
  294. console.log(arr)
  295. this.baseobj = arr
  296. }
  297. });
  298. }
  299. }
  300. </script>
  301. <style lang="scss">
  302. .addimg{
  303. position: absolute;
  304. top: 108rpx;
  305. width: 100%;
  306. .addimg_add{
  307. position: relative;
  308. width: 90%;
  309. height: 276rpx;
  310. margin: 0 auto;
  311. background-color: #F7F8FA;
  312. text-align: center;
  313. line-height: 276rpx;
  314. color: #A7A8AA;
  315. .addimg_img{
  316. position: absolute;
  317. top: 0;
  318. width: 100%;
  319. left: 0;
  320. height: 276rpx;
  321. }
  322. }
  323. }
  324. .base_text{
  325. position: absolute;
  326. top: 390rpx;
  327. width: 100%;
  328. margin-bottom: 50rpx;
  329. .title{
  330. width: 90%;
  331. margin: 20rpx auto;
  332. }
  333. .base_text_item2{
  334. width: 90%;
  335. margin: 10rpx auto 20rpx;
  336. padding: 16rpx 20rpx;
  337. background-color: #F7F8FA;
  338. display: flex;
  339. box-sizing: border-box;
  340. position: relative;
  341. height: 200rpx;
  342. .icon{
  343. color: #5FBBA0;
  344. height: 42rpx;
  345. }
  346. span{
  347. margin: 0 20rpx;
  348. }
  349. .textarea{
  350. font-size: 24rpx;
  351. text-align: right;
  352. position: absolute;
  353. right: 20rpx;
  354. width: 70%;
  355. height: 200rpx;
  356. }
  357. }
  358. .base_text_item1{
  359. display: flex;
  360. position: relative;
  361. width: 90%;
  362. height: 70rpx;
  363. margin: 10rpx auto 20rpx;
  364. padding: 16rpx 20rpx;
  365. background-color: #F7F8FA;
  366. box-sizing: border-box;
  367. .icon{
  368. color: #5FBBA0;
  369. }
  370. span{
  371. margin: 0 10rpx;
  372. }
  373. input{
  374. position: absolute;
  375. right: 20rpx;
  376. width: 70%;
  377. text-align: right;
  378. font-size: 24rpx;
  379. margin-top: 5rpx;
  380. }
  381. .iconright{
  382. position: absolute;
  383. right: 10rpx;
  384. top: 28rpx;
  385. color: #B5B6B8;
  386. font-size: 24rpx;
  387. }
  388. }
  389. }
  390. .base_id_box{
  391. width: 90%;
  392. margin: 20rpx auto 70rpx;
  393. }
  394. .base_id{
  395. width: 100%;
  396. .base_id_item{
  397. width: 95%;
  398. padding: 10rpx 30rpx;
  399. display: flex;
  400. justify-content: space-between;
  401. font-size: 28rpx;
  402. background-color: #F7F8FA;
  403. color: #616162;
  404. box-sizing: border-box;
  405. margin: 20rpx auto;
  406. }
  407. }
  408. .btn{
  409. width: 90%;
  410. position: fixed;
  411. bottom: 10rpx;
  412. right: 5%;
  413. text-align: center;
  414. height: 70rpx;
  415. line-height: 70rpx;
  416. background-color: #359773;
  417. font-size: 34rpx;
  418. border-radius: 35rpx;
  419. color: #FFFFFF;
  420. }
  421. </style>