addbase.vue 11 KB

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