addbase.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view>
  3. <view style="position: fixed;z-index: 100;">
  4. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="新增基地"></uni-nav-bar>
  5. </view>
  6. <view class="addimg">
  7. <view class="addimg_add" @click="gainimg">
  8. <u-icon name="plus" size="60rpx" color="#A5A6A8"></u-icon>
  9. <image :src="baseinfo.base_img" mode="" class="addimg_img"></image>
  10. </view>
  11. </view>
  12. <view class="base_text">
  13. <p class="title">基地信息</p>
  14. <view class="base_text_item1">
  15. <u-icon name="fangzi" custom-prefix="custom-icon" class="icon"></u-icon>
  16. <span><span style="color: #ff0000;margin: 0;">*</span>基地名称</span>
  17. <input type="text" v-model="baseinfo.base_name" placeholder="请输入基地名称" />
  18. </view>
  19. <view class="base_text_item1">
  20. <u-icon name="ren1" 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_charge " placeholder="请输入基地负责人" />
  23. </view>
  24. <view class="base_text_item1">
  25. <u-icon name="lianxidianhua" 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_phone" placeholder="请输入联系电话" @blur="yanzheng"/>
  28. </view>
  29. <view class="base_text_item1">
  30. <u-icon name="mianji" custom-prefix="custom-icon" class="icon"></u-icon>
  31. <span><span style="color: #ff0000;margin: 0;">*</span>面积(亩)</span>
  32. <input type="number" v-model="baseinfo.base_area" placeholder="请输入基地面积" />
  33. </view>
  34. <view class="base_text_item2">
  35. <u-icon name="miaoshu" custom-prefix="custom-icon" class="icon"></u-icon>
  36. <span>基地描述</span>
  37. <textarea v-model="baseinfo.base_describe " maxlength="80" auto-height class="textarea" placeholder="请输入基地描述(不能大于80字)" />
  38. </view>
  39. <view class="base_text_item1" @click="map">
  40. <u-icon name="Frame1" custom-prefix="custom-icon" class="icon"></u-icon>
  41. <span><span style="color: #ff0000;margin: 0;">*</span>基地定位</span>
  42. <input type="text" v-model="city" placeholder="请选择地址" disabled style="position: absolute;right: 60rpx;width: 60%;"/>
  43. <u-icon name="arrow-right" class="iconright"></u-icon>
  44. </view>
  45. <view class="base_text_item1" @click="binding">
  46. <u-icon name="bangding" custom-prefix="custom-icon" class="icon"></u-icon>
  47. <span><span style="color: #ff0000;margin: 0;">*</span>设备绑定</span>
  48. <u-icon name="arrow-right" class="iconright"></u-icon>
  49. </view>
  50. <view class="base_id_box">
  51. <view class="base_id" v-for="(item,key,index) in base_id" :key="index">
  52. <view class="base_id_item" v-for="(items,indexs) in item" :key="indexs">
  53. <span>{{key}}</span>
  54. <span>{{items}}</span>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="btn" @click="tijiao">
  59. 确 定
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <style lang="scss">
  65. </style>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. base_id:{},
  71. baseinfo:{
  72. base_name:'',//必传(str) 基地名称
  73. base_charge:'',//必传(str) 负责人
  74. base_phone:'',//必传(str) 联系电话
  75. base_img:'',// 必传(str) 基地图片
  76. base_area:'',//必传(str) 基地面积
  77. base_equip:'', //必传(str) 绑定设备 如果绑定多个设备传 289#299, 如果是单一设备传298
  78. base_describe:'',//非必传(str) 基地描述
  79. lng:'',//必传(str) 经度
  80. lat:'',//必传(str) 纬度
  81. ret:"add",//必传(str) 区分
  82. },
  83. city:''
  84. }
  85. },
  86. methods: {
  87. //base.bases.base_list新增基地
  88. async addbase() { //获取分布位置
  89. const res = await this.$myRequest({
  90. url: '/api/api_gateway?method=base.bases.base_list',
  91. data: this.baseinfo
  92. })
  93. },
  94. clickLeft(){
  95. uni.navigateTo({
  96. url:"./index"
  97. })
  98. },
  99. binding(){
  100. uni.navigateTo({
  101. url:"./allocation"
  102. })
  103. },
  104. gainimg() { //添加图片
  105. uni.chooseImage({
  106. count: 1, //默认9
  107. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  108. sourceType: ['album', 'camera'], //从相册选择
  109. success: (res) => {
  110. uni.uploadFile({
  111. url: 'http://182.92.193.64:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  112. filePath: res.tempFilePaths[0],
  113. name: 'img_file',
  114. formData: {
  115. 'user': 'test'
  116. },
  117. success: (uploadFileRes) => {
  118. this.baseinfo.base_img = JSON.parse(uploadFileRes.data).data.src
  119. // this.$forceUpdate() //强制刷新视图
  120. }
  121. });
  122. }
  123. })
  124. },
  125. map(){
  126. uni.getLocation({
  127. type: 'wgs84',
  128. success: (res) => {
  129. console.log('当前位置的经度:' + res.longitude);
  130. console.log('当前位置的纬度:' + res.latitude);
  131. this.longitude = res.longitude
  132. this.latitude = res.latitude
  133. uni.chooseLocation({
  134. success:(res)=>{
  135. console.log('位置名称:' + res.name);//address 详细地址
  136. this.city = res.name
  137. this.baseinfo.lat = res.latitude
  138. this.baseinfo.lng = res.longitude
  139. }
  140. });
  141. }
  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. this.addbase()
  197. localStorage.removeItem("id")
  198. uni.navigateBack({
  199. delta:1
  200. })
  201. }
  202. }
  203. },
  204. yanzheng(){
  205. if(!/^1[23456789]\d{9}$/.test(this.baseinfo.base_phone)){
  206. uni.showToast({
  207. title: '请填写正确的手机号',
  208. duration: 2000,
  209. icon:"none"
  210. });
  211. }
  212. }
  213. },
  214. onLoad() {
  215. },
  216. onShow(){
  217. // this.base_id=JSON.parse(localStorage.getItem("id"))
  218. if(localStorage.getItem("id")!=null){
  219. var arr = []
  220. for(var key in this.base_id){
  221. arr.push(this.base_id[key].join("#"))
  222. }
  223. this.baseinfo.base_equip = arr.join("#")
  224. }
  225. }
  226. }
  227. </script>
  228. <style lang="scss">
  229. .addimg{
  230. position: absolute;
  231. top: 108rpx;
  232. width: 100%;
  233. .addimg_add{
  234. position: relative;
  235. width: 90%;
  236. height: 276rpx;
  237. margin: 0 auto;
  238. background-color: #F7F8FA;
  239. text-align: center;
  240. line-height: 276rpx;
  241. color: #A7A8AA;
  242. .addimg_img{
  243. position: absolute;
  244. top: 0;
  245. width: 100%;
  246. left: 0;
  247. height: 276rpx;
  248. }
  249. }
  250. }
  251. .base_text{
  252. position: absolute;
  253. top: 390rpx;
  254. width: 100%;
  255. .title{
  256. width: 90%;
  257. margin: 20rpx auto;
  258. }
  259. .base_text_item2{
  260. width: 90%;
  261. margin: 10rpx auto 20rpx;
  262. padding: 16rpx 20rpx;
  263. background-color: #F7F8FA;
  264. display: flex;
  265. box-sizing: border-box;
  266. position: relative;
  267. height: 200rpx;
  268. .icon{
  269. color: #5FBBA0;
  270. height: 42rpx;
  271. }
  272. span{
  273. margin: 0 20rpx;
  274. }
  275. .textarea{
  276. font-size: 24rpx;
  277. text-align: right;
  278. position: absolute;
  279. right: 20rpx;
  280. width: 70%;
  281. height: 200rpx;
  282. }
  283. }
  284. .base_text_item1{
  285. display: flex;
  286. position: relative;
  287. width: 90%;
  288. height: 70rpx;
  289. margin: 10rpx auto 20rpx;
  290. padding: 16rpx 20rpx;
  291. background-color: #F7F8FA;
  292. box-sizing: border-box;
  293. .icon{
  294. color: #5FBBA0;
  295. }
  296. span{
  297. margin: 0 20rpx;
  298. }
  299. input{
  300. position: absolute;
  301. right: 20rpx;
  302. width: 70%;
  303. text-align: right;
  304. font-size: 24rpx;
  305. margin-top: 5rpx;
  306. }
  307. .iconright{
  308. position: absolute;
  309. right: 20rpx;
  310. top: 28rpx;
  311. color: #B5B6B8;
  312. font-size: 24rpx;
  313. }
  314. }
  315. }
  316. .base_id_box{
  317. width: 90%;
  318. margin: 20rpx auto 70rpx;
  319. }
  320. .base_id{
  321. width: 100%;
  322. .base_id_item{
  323. width: 95%;
  324. padding: 10rpx 30rpx;
  325. display: flex;
  326. justify-content: space-between;
  327. font-size: 28rpx;
  328. background-color: #F7F8FA;
  329. color: #616162;
  330. box-sizing: border-box;
  331. margin: 20rpx auto;
  332. }
  333. }
  334. .btn{
  335. width: 90%;
  336. position: fixed;
  337. bottom: 0;
  338. right: 5%;
  339. text-align: center;
  340. height: 70rpx;
  341. line-height: 70rpx;
  342. background-color: #359773;
  343. font-size: 34rpx;
  344. border-radius: 35rpx;
  345. color: #FFFFFF;
  346. }
  347. </style>