addbase.vue 11 KB

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