addbase.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. },
  131. binding(){
  132. var str = ''
  133. uni.navigateTo({
  134. url:"./allocation?base_id="+str
  135. })
  136. },
  137. gainimg() { //添加图片
  138. uni.chooseImage({
  139. count: 1, //默认9
  140. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  141. sourceType: ['album', 'camera'], //从相册选择
  142. success: (res) => {
  143. this.imgs = res.tempFilePaths[0]
  144. this.loding = true
  145. }
  146. })
  147. },
  148. map(){
  149. uni.navigateTo({
  150. url:"city"
  151. })
  152. },
  153. tijiao(){
  154. if(this.baseinfo.base_img==''){
  155. uni.showToast({
  156. title: '请选择基地图片',
  157. duration: 2000,
  158. icon:"none"
  159. });
  160. }else if(this.baseinfo.base_name==''){
  161. uni.showToast({
  162. title: '请填写基地名称',
  163. duration: 2000,
  164. icon:"none"
  165. });
  166. }else if(this.baseinfo.base_charge==''){
  167. uni.showToast({
  168. title: '请填写基地负责人',
  169. duration: 2000,
  170. icon:"none"
  171. });
  172. }else if(this.baseinfo.base_phone==''){
  173. uni.showToast({
  174. title: '请填写手机号',
  175. duration: 2000,
  176. icon:"none"
  177. });
  178. }else if(this.baseinfo.base_area==''){
  179. uni.showToast({
  180. title: '请填写基地面积',
  181. duration: 2000,
  182. icon:"none"
  183. });
  184. }else if(this.baseinfo.lng==''){
  185. uni.showToast({
  186. title: '请选择基地地址',
  187. duration: 2000,
  188. icon:"none"
  189. });
  190. }else if(this.baseinfo.base_id==''){
  191. uni.showToast({
  192. title: '请绑定基地设备',
  193. duration: 2000,
  194. icon:"none"
  195. });
  196. }else{
  197. if(!/^1[23456789]\d{9}$/.test(this.baseinfo.base_phone)){
  198. uni.showToast({
  199. title: '请填写正确的手机号',
  200. duration: 2000,
  201. icon:"none"
  202. });
  203. }else{
  204. console.log(this.baseinfo)
  205. if(!this.baseobjtf){
  206. var arr = []
  207. for(var i=0;i<this.baseobj.length;i++){
  208. arr.push(this.baseobj[i].arr)
  209. }
  210. this.baseinfo.base_equip = arr.join("#")
  211. }
  212. console.log(this.baseinfo)
  213. this.addbase()
  214. localStorage.removeItem("typeid")
  215. localStorage.removeItem("location")
  216. }
  217. }
  218. },
  219. yanzheng(){
  220. if(!/^1[23456789]\d{9}$/.test(this.baseinfo.base_phone)){
  221. uni.showToast({
  222. title: '请填写正确的手机号',
  223. duration: 2000,
  224. icon:"none"
  225. });
  226. }
  227. },
  228. onok(ev){
  229. uni.uploadFile({
  230. url: 'http://114.115.147.140:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  231. filePath: ev.path,
  232. name: 'img_file',
  233. formData: {
  234. 'user': 'test'
  235. },
  236. success: (uploadFileRes) => {
  237. this.baseinfo.base_img = JSON.parse(uploadFileRes.data).data.src
  238. // this.$forceUpdate() //强制刷新视图
  239. this.loding = false
  240. }
  241. });
  242. this.imgs = ''
  243. },
  244. oncancle(){
  245. this.imgs = ''
  246. },
  247. selectaddress(lat,lng) { //获取分布位置
  248. uni.request({
  249. type: "GET",
  250. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," +lat + "&key=27273b81090f78759e4057f94474516f&radius=1000&extensions=all",
  251. dataType: "json",
  252. complete: ress => {
  253. console.log(ress)
  254. this.city = ress.data.regeocode.formatted_address
  255. }
  256. });
  257. },
  258. },
  259. onLoad() {
  260. },
  261. onShow(){
  262. uni.getStorage({
  263. key:"location",
  264. success:(res)=> {
  265. console.log(res.data)
  266. this.selectaddress(res.data[1],res.data[0])
  267. this.baseinfo.lat = res.data[1]
  268. this.baseinfo.lng = res.data[0]
  269. }
  270. })
  271. uni.getStorage({
  272. key: 'typeid',
  273. success: (res)=> {
  274. this.baseobjtf = false
  275. console.log(JSON.parse(res.data))
  276. var arr = []
  277. for(var key in JSON.parse(res.data)){
  278. console.log(key)
  279. for(var i=0;i<JSON.parse(res.data)[key].length;i++){
  280. var obj={
  281. name:key,
  282. arr:JSON.parse(res.data)[key][i]
  283. }
  284. arr.push(obj)
  285. }
  286. }
  287. console.log(arr)
  288. this.baseobj = arr
  289. }
  290. });
  291. }
  292. }
  293. </script>
  294. <style lang="scss">
  295. .addimg{
  296. position: absolute;
  297. top: 108rpx;
  298. width: 100%;
  299. .addimg_add{
  300. position: relative;
  301. width: 90%;
  302. height: 276rpx;
  303. margin: 0 auto;
  304. background-color: #F7F8FA;
  305. text-align: center;
  306. line-height: 276rpx;
  307. color: #A7A8AA;
  308. .sim_info_loding{
  309. position: absolute;
  310. top: 0;
  311. left: 50%;
  312. margin-left: -25%;
  313. image{
  314. width: 300rpx;
  315. height: 300rpx;
  316. }
  317. }
  318. .addimg_img{
  319. position: absolute;
  320. top: 0;
  321. width: 100%;
  322. left: 0;
  323. height: 276rpx;
  324. }
  325. }
  326. }
  327. .base_text{
  328. position: absolute;
  329. top: 390rpx;
  330. width: 100%;
  331. margin-bottom: 50rpx;
  332. .title{
  333. width: 90%;
  334. margin: 20rpx auto;
  335. }
  336. .base_text_item2{
  337. width: 90%;
  338. margin: 10rpx auto 20rpx;
  339. padding: 16rpx 20rpx;
  340. background-color: #F7F8FA;
  341. display: flex;
  342. box-sizing: border-box;
  343. position: relative;
  344. height: 200rpx;
  345. .icon{
  346. color: #5FBBA0;
  347. height: 42rpx;
  348. }
  349. span{
  350. margin: 0 20rpx 0 10rpx;
  351. }
  352. .textarea{
  353. font-size: 24rpx;
  354. text-align: right;
  355. position: absolute;
  356. right: 20rpx;
  357. width: 70%;
  358. height: 200rpx;
  359. }
  360. }
  361. .base_text_item1{
  362. display: flex;
  363. position: relative;
  364. width: 90%;
  365. height: 70rpx;
  366. margin: 10rpx auto 20rpx;
  367. padding: 16rpx 20rpx;
  368. background-color: #F7F8FA;
  369. box-sizing: border-box;
  370. .icon{
  371. color: #5FBBA0;
  372. }
  373. span{
  374. margin: 0 10rpx;
  375. }
  376. input{
  377. position: absolute;
  378. right: 20rpx;
  379. width: 70%;
  380. text-align: right;
  381. font-size: 24rpx;
  382. margin-top: 5rpx;
  383. }
  384. .iconright{
  385. position: absolute;
  386. right: 20rpx;
  387. top: 28rpx;
  388. color: #B5B6B8;
  389. font-size: 24rpx;
  390. }
  391. }
  392. }
  393. .base_id_box{
  394. width: 90%;
  395. margin: 20rpx auto 70rpx;
  396. }
  397. .base_id{
  398. width: 100%;
  399. .base_id_item{
  400. width: 95%;
  401. padding: 10rpx 30rpx;
  402. display: flex;
  403. justify-content: space-between;
  404. font-size: 28rpx;
  405. background-color: #F7F8FA;
  406. color: #616162;
  407. box-sizing: border-box;
  408. margin: 20rpx auto;
  409. }
  410. }
  411. .btn{
  412. width: 90%;
  413. position: fixed;
  414. bottom: 10rpx;
  415. right: 5%;
  416. text-align: center;
  417. height: 70rpx;
  418. line-height: 70rpx;
  419. background-color: #359773;
  420. font-size: 34rpx;
  421. border-radius: 35rpx;
  422. color: #FFFFFF;
  423. }
  424. </style>