modification.vue 9.7 KB

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