addbase.vue 9.3 KB

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