modification.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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="chandi" 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="jidiguanli" 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="dianhua2" 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="xiangqing-" custom-prefix="custom-icon" class="icon"></u-icon>
  38. <span>基地描述</span>
  39. <textarea v-model="baseinfo.base_describe " maxlength="80" :auto-height="true" class="textarea"
  40. placeholder="请输入基地描述(不能大于80字)" />
  41. </view>
  42. <view class="base_text_item1" @click="map">
  43. <u-icon name="dingwei" custom-prefix="custom-icon" class="icon"></u-icon>
  44. <span><span style="color: #ff0000;margin: 0;">*</span>基地定位</span>
  45. <input type="text" v-model="city" placeholder="请选择地址" disabled
  46. style="position: absolute;right: 60rpx;width: 60%;" />
  47. <u-icon name="arrow-right" class="iconright"></u-icon>
  48. </view>
  49. <view class="base_text_item1" @click="binding">
  50. <u-icon name="bangding" custom-prefix="custom-icon" class="icon"></u-icon>
  51. <span><span style="color: #ff0000;margin: 0;">*</span>设备绑定</span>
  52. <u-icon name="arrow-right" class="iconright"></u-icon>
  53. </view>
  54. <view class="base_id_box" v-if="baseobjtf">
  55. <view class="base_id" v-for="(item,index) in base_id" :key="index">
  56. <view class="base_id_item">
  57. <span>{{item.device_id}}</span>
  58. <span>{{item.type_name}}</span>
  59. </view>
  60. </view>
  61. </view>
  62. <view class="base_id_box" v-else>
  63. <view class="base_id" v-for="items,indexs in baseobj" :key="indexs">
  64. <view class="base_id_item">
  65. <span>{{items.arr}}</span>
  66. <span>{{items.name}}</span>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="btn" @click="tijiao">
  71. 确 定
  72. </view>
  73. </view>
  74. </view>
  75. <kps-image-cutter @ok="onok" @cancel="oncancle" :url="imgs" :fixed="false" :blob="false" :maxWidth="500"
  76. :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. },
  100. city: '',
  101. imgs: "",
  102. baseobjtf: true
  103. }
  104. },
  105. methods: {
  106. //base.bases.base_list新增基地 //modify 修改 list 列表
  107. async addbase() { //获取分布位置
  108. const res = await this.$myRequest({
  109. url: '/api/api_gateway?method=base.bases.base_list',
  110. data: this.baseinfo,
  111. ret: "modify"
  112. })
  113. console.log(res)
  114. if (res) {
  115. uni.showToast({
  116. title: '修改成功',
  117. duration: 2000,
  118. icon: "none"
  119. });
  120. }
  121. },
  122. async ybase() { //获取基地设备
  123. const res = await this.$myRequest({
  124. url: '/api/api_gateway?method=base.bases.base_map_list',
  125. data: {
  126. base_id: this.baseinfo.base_id
  127. }
  128. })
  129. this.base_id = res
  130. console.log(res)
  131. },
  132. clickLeft() {
  133. uni.navigateTo({
  134. url: "./index"
  135. })
  136. // localStorage.removeItem("typeid")
  137. // localStorage.removeItem("location")
  138. uni.removeStorage({
  139. key:'typeid'
  140. })
  141. uni.removeStorage({
  142. key:'location'
  143. })
  144. },
  145. binding() {
  146. uni.navigateTo({
  147. url: "./allocation?base_id=" + this.baseinfo.base_id
  148. })
  149. },
  150. gainimg() { //添加图片
  151. uni.chooseImage({
  152. count: 1, //默认9
  153. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  154. sourceType: ['album', 'camera'], //从相册选择
  155. success: (res) => {
  156. this.imgs = res.tempFilePaths[0]
  157. }
  158. })
  159. },
  160. map() {
  161. uni.navigateTo({
  162. url: "city"
  163. })
  164. },
  165. tijiao() {
  166. if (this.baseinfo.base_img == '') {
  167. uni.showToast({
  168. title: '请选择基地图片',
  169. duration: 2000,
  170. icon: "none"
  171. });
  172. } else if (this.baseinfo.base_name == '') {
  173. uni.showToast({
  174. title: '请填写正基地名称',
  175. duration: 2000,
  176. icon: "none"
  177. });
  178. } else if (this.baseinfo.base_charge == '') {
  179. uni.showToast({
  180. title: '请填写基地负责人',
  181. duration: 2000,
  182. icon: "none"
  183. });
  184. } else if (this.baseinfo.base_phone == '') {
  185. uni.showToast({
  186. title: '请填写手机号',
  187. duration: 2000,
  188. icon: "none"
  189. });
  190. } else if (this.baseinfo.base_area == '') {
  191. uni.showToast({
  192. title: '请填写基地面积',
  193. duration: 2000,
  194. icon: "none"
  195. });
  196. } else if (this.baseinfo.lng == '') {
  197. uni.showToast({
  198. title: '请选择基地地址',
  199. duration: 2000,
  200. icon: "none"
  201. });
  202. } else if (!this.baseobj.length && !this.base_id.length) {
  203. uni.showToast({
  204. title: '请绑定基地设备',
  205. duration: 2000,
  206. icon: "none"
  207. });
  208. } else {
  209. if (!/^1[23456789]\d{9}$/.test(this.baseinfo.base_phone)) {
  210. uni.showToast({
  211. title: '请填写正确的手机号',
  212. duration: 2000,
  213. icon: "none"
  214. });
  215. } else {
  216. if (!this.baseobjtf) {
  217. var arr = []
  218. for (var i = 0; i < this.baseobj.length; i++) {
  219. arr.push(this.baseobj[i].arr)
  220. }
  221. this.baseinfo.base_equip = arr.join("#")
  222. }
  223. console.log(this.baseinfo)
  224. this.addbase()
  225. // localStorage.removeItem("typeid")
  226. // localStorage.removeItem("location")
  227. uni.removeStorage({
  228. key:'typeid'
  229. })
  230. uni.removeStorage({
  231. key:'location'
  232. })
  233. }
  234. }
  235. },
  236. selectaddress(lat, lng) { //获取分布位置
  237. uni.request({
  238. type: "GET",
  239. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
  240. "&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. onok(ev) {
  249. uni.uploadFile({
  250. url: 'http://dev.hnyfwlw.com/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  251. filePath: ev.path,
  252. name: 'img_file',
  253. formData: {
  254. 'user': 'test'
  255. },
  256. success: (uploadFileRes) => {
  257. this.baseinfo.base_img = JSON.parse(uploadFileRes.data).data.src
  258. // this.$forceUpdate() //强制刷新视图
  259. }
  260. });
  261. this.imgs = ''
  262. },
  263. oncancle() {
  264. this.imgs = ''
  265. }
  266. },
  267. onLoad(option) {
  268. console.log(JSON.parse(option.id),'on load ')
  269. this.baseinfo = JSON.parse(option.id)
  270. this.baseinfo.base_id = JSON.parse(option.id).id
  271. this.baseinfo.ret = "modify"
  272. delete this.baseinfo.id
  273. this.selectaddress(this.baseinfo.lat, this.baseinfo.lng)
  274. this.ybase()
  275. },
  276. onShow() {
  277. console.warn('on show modification -------------')
  278. uni.getStorage({
  279. key: "location",
  280. success: (res) => {
  281. console.log(res.data,'get storage location')
  282. this.selectaddress(res.data[1], res.data[0])
  283. this.baseinfo.lat = res.data[1]
  284. this.baseinfo.lng = res.data[0]
  285. }
  286. })
  287. uni.getStorage({
  288. key: 'typeid',
  289. success: (res) => {
  290. this.baseobjtf = false
  291. console.log(JSON.parse(res.data),'get storage type id')
  292. var arr = []
  293. for (var key in JSON.parse(res.data)) {
  294. console.log(key)
  295. for (var i = 0; i < JSON.parse(res.data)[key].length; i++) {
  296. var obj = {
  297. name: key,
  298. arr: JSON.parse(res.data)[key][i]
  299. }
  300. arr.push(obj)
  301. }
  302. }
  303. console.log(arr)
  304. this.baseobj = arr
  305. }
  306. });
  307. }
  308. }
  309. </script>
  310. <style lang="scss">
  311. .addimg {
  312. position: absolute;
  313. top: 108rpx;
  314. width: 100%;
  315. .addimg_add {
  316. position: relative;
  317. width: 90%;
  318. height: 276rpx;
  319. margin: 0 auto;
  320. background-color: #F7F8FA;
  321. text-align: center;
  322. line-height: 276rpx;
  323. color: #A7A8AA;
  324. .addimg_img {
  325. position: absolute;
  326. top: 0;
  327. width: 100%;
  328. left: 0;
  329. height: 276rpx;
  330. }
  331. }
  332. }
  333. .base_text {
  334. position: absolute;
  335. top: 390rpx;
  336. width: 100%;
  337. margin-bottom: 50rpx;
  338. .title {
  339. width: 90%;
  340. margin: 20rpx auto;
  341. }
  342. .base_text_item2 {
  343. width: 90%;
  344. margin: 10rpx auto 20rpx;
  345. padding: 16rpx 20rpx;
  346. background-color: #F7F8FA;
  347. display: flex;
  348. box-sizing: border-box;
  349. position: relative;
  350. // height: 200rpx;
  351. .icon {
  352. color: #5FBBA0;
  353. height: 42rpx;
  354. }
  355. span {
  356. margin: 0 20rpx 0 10rpx;
  357. }
  358. .textarea {
  359. font-size: 24rpx;
  360. text-align: right;
  361. // position: absolute;
  362. // right: 20rpx;
  363. width: 70%;
  364. // // height: 200rpx;
  365. // // overflow:hidden;
  366. // // text-overflow:ellipsis;
  367. // // white-space:nowrap;
  368. }
  369. }
  370. .base_text_item1 {
  371. display: flex;
  372. position: relative;
  373. width: 90%;
  374. height: 70rpx;
  375. margin: 10rpx auto 20rpx;
  376. padding: 16rpx 20rpx;
  377. background-color: #F7F8FA;
  378. box-sizing: border-box;
  379. .icon {
  380. color: #5FBBA0;
  381. }
  382. span {
  383. margin: 0 10rpx;
  384. }
  385. input {
  386. position: absolute;
  387. right: 20rpx;
  388. width: 70%;
  389. text-align: right;
  390. font-size: 24rpx;
  391. margin-top: 5rpx;
  392. }
  393. .iconright {
  394. position: absolute;
  395. right: 10rpx;
  396. top: 28rpx;
  397. color: #B5B6B8;
  398. font-size: 24rpx;
  399. }
  400. }
  401. }
  402. .base_id_box {
  403. width: 90%;
  404. margin: 20rpx auto 70rpx;
  405. }
  406. .base_id {
  407. width: 100%;
  408. .base_id_item {
  409. width: 95%;
  410. padding: 10rpx 30rpx;
  411. display: flex;
  412. justify-content: space-between;
  413. font-size: 28rpx;
  414. background-color: #F7F8FA;
  415. color: #616162;
  416. box-sizing: border-box;
  417. margin: 20rpx auto;
  418. }
  419. }
  420. .btn {
  421. width: 90%;
  422. position: fixed;
  423. bottom: 10rpx;
  424. right: 5%;
  425. text-align: center;
  426. height: 70rpx;
  427. line-height: 70rpx;
  428. background-color: #359773;
  429. font-size: 34rpx;
  430. border-radius: 35rpx;
  431. color: #FFFFFF;
  432. }
  433. </style>