addbase.vue 11 KB

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