edit_device.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <template>
  2. <view class=" uni-container">
  3. <view class="example container" :style="'height: ' + (screenHeight - wheight - 75) + 'px'">
  4. <!-- 自定义表单校验 1-->
  5. <u--form ref="customForm" :model="formData" labelPosition="left" labelWidth="150" labelAlign="left">
  6. <view class=" flex flex-direction width100">
  7. <u-form-item label="设施名称 " prop="fpdName" :required="true">
  8. <u-input v-model="formData.fpdName" placeholder="必填。请输入设施名称" />
  9. </u-form-item>
  10. <u-form-item label="所属单位" @click="
  11. showSex5 = true;
  12. hideKeyboard();
  13. " :required="true" prop="orgName">
  14. <u--input v-model="formData.orgName" disabled disabledColor="#ffffff" placeholder="请选择所属单位">
  15. </u--input>
  16. </u-form-item>
  17. <u-form-item label="设施编号 " prop="fpdCode">
  18. <u-input v-model="formData.fpdCode" placeholder="请输入设施编号 " />
  19. </u-form-item>
  20. <u-form-item label="设施二维码">
  21. <img :src="formData.fpdQcode" alt="设施二维码" style='width: 300upx;height: 300upx;'
  22. @click="viewImageBig(formData.fpdQcode)">
  23. </u-form-item>
  24. <!-- <u-form-item label="设备状态" @click="
  25. showSex4 = true;
  26. hideKeyboard();
  27. ">
  28. <u--input v-model="fpdStatus" disabled disabledColor="#ffffff" placeholder="请选择设备状态"></u--input>
  29. </u-form-item> -->
  30. <u-form-item label="所在位置 " prop="fpdLocal">
  31. <u-input v-model="formData.fpdLocal" placeholder="请输入所在位置" />
  32. </u-form-item>
  33. <u-form-item label="所属建筑" @click="
  34. showBuilding = true;
  35. hideKeyboard();
  36. ">
  37. <u-input v-model="formData.buildingName" placeholder="请输入所属建筑" />
  38. </u-form-item>
  39. <u-form-item label="设施类别" prop="fpdType" @click="
  40. showSex = true;
  41. hideKeyboard();
  42. ">
  43. <u--input v-model="formData.fpdTypeName" disabled disabledColor="#ffffff" placeholder="请选择设施类别">
  44. </u--input>
  45. </u-form-item>
  46. </view>
  47. <view class="show-title">
  48. <view class="paizhao">现场照片:<text style="color:#822e2e;"></text></view>
  49. <view class="">
  50. <image :src="photograph" @click="photoUpload()" class="tiantupian"></image>
  51. </view>
  52. <view>
  53. 拍照上传
  54. </view>
  55. <uni-load-more v-show="loading" status="loading" :content-text="contentText" />
  56. </view>
  57. <view class="uni-grid-wraps" v-if="formData.picVOList">
  58. <view v-for="(items,indexs) in formData.picVOList" :key="indexs">
  59. <view style="display:flex;align-items:center;justify-content:space-between;">
  60. <view style="position: relative;width: 180rpx;float: left;margin: 10rpx 15rpx 0 0rpx;">
  61. <image :src="items.url" @click="viewImageBig(items.url)"
  62. style="width: 160rpx;height: 160rpx;border-radius: 30rpx;float: left;">
  63. <u-icon name="close" color="#4CB2B6" size="19" @click="closeImage(items,indexs)">
  64. </u-icon>
  65. </view>
  66. <view class="">
  67. <view>
  68. 图片名称
  69. </view>
  70. <view style="margin-top:20rpx">
  71. <u-input v-model="items.picname" placeholder="请输入图片名称" />
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </u--form>
  78. <u-action-sheet :show="showSex" :actions="actions2" title="设施类别" @close="showSex = false"
  79. @select="sexSelect2"></u-action-sheet>
  80. <u-action-sheet :show="showSex4" :actions="actions4" title="设备状态" @close="showSex4 = false"
  81. @select="sexSelect4"></u-action-sheet>
  82. <u-action-sheet :show="showSex5" :actions="actions5" title="请选择单位" @close="showSex5 = false"
  83. @select="sexSelect5"></u-action-sheet>
  84. <u-action-sheet :show="showBuilding" :actions="buildingData" title="请选择所属建筑" @close="showBuilding = false"
  85. @select="buildingSelect"></u-action-sheet>
  86. <!-- 加载中 -->
  87. <!-- <isLodingModel></isLodingModel> -->
  88. </view>
  89. <uni-row class="heigthButton">
  90. <u-button @click="submit('customForm')" type="primary" shape="circle" size="large" color="#4CB2B6"
  91. text="确认修改"></u-button>
  92. </uni-row>
  93. </view>
  94. </template>
  95. <script>
  96. import {
  97. updateDevice, //获取消防设施列表
  98. getOrgId,
  99. fpdGet
  100. } from '@/api/fire_device';
  101. import {
  102. DICT_TYPE,
  103. getDictDatas
  104. } from '@/utils/dict';
  105. import config from '@/config'
  106. import {
  107. getAccessToken
  108. } from '@/utils/auth'
  109. import {
  110. getArc, //获取建筑信息列表
  111. } from '@/api/architecture';
  112. import loadImage from 'blueimp-load-image';
  113. const baseUrlImg = config.baseUrlImg
  114. const baseUrl = config.baseUrl
  115. let that = null;
  116. export default {
  117. data() {
  118. return {
  119. showBuilding: false,
  120. buildingData: [],
  121. contentText: {
  122. contentrefresh: '上传照片中',
  123. },
  124. screenHeight: this.$screenHeight,
  125. wheight: '',
  126. photograph: `${baseUrlImg}/checkActive/photograph.png`,
  127. showSex: false, //有无避难层
  128. showSex4: false, //设备状态
  129. showSex5: false, //所属单位
  130. actions2: getDictDatas(DICT_TYPE.FPD_TYPE),
  131. actions4: [{
  132. id: 0,
  133. name: '正常'
  134. }, {
  135. id: 1,
  136. name: '有问题'
  137. }],
  138. actions5: [],
  139. // 每页数据量
  140. pageSize: 5,
  141. // 当前页
  142. pageNo: 1,
  143. // 数据总量
  144. total: 0,
  145. // tableData数据加载中
  146. loading: false,
  147. // 自定义表单数据
  148. formData: {
  149. status: '0',
  150. orgName: '',
  151. picVOList: [],
  152. fpdTypeName: '',
  153. fpdType: ''
  154. },
  155. fileList1: [],
  156. // 用于显示下拉确认内容,不作为提交
  157. fpdStatus: '',
  158. // 自定义表单校验规则
  159. customRules: {
  160. fpdName: {
  161. type: 'string',
  162. required: true,
  163. message: '设施名称不能为空',
  164. trigger: ['blur', 'change']
  165. },
  166. },
  167. };
  168. },
  169. computed: {},
  170. mounted() {
  171. uni.createSelectorQuery().in(this).select('.heigthButton').boundingClientRect(data => {
  172. this.wheight = data.height
  173. }).exec()
  174. },
  175. watch: {
  176. loading: {
  177. handler(newLength, oldLength) {
  178. this.$modal.isLoadingModel(this.loading)
  179. },
  180. immediate: true
  181. }
  182. },
  183. // 在 vue页面,向起始页通过事件传递数据
  184. onLoad: function(option) {
  185. this.actions2.map(i => {
  186. i.name = i.label;
  187. i.id = i.value;
  188. });
  189. this.buildingData = JSON.parse(option.buildingData)
  190. this.loading = true
  191. // 接收传值
  192. var data = option.id;
  193. that = this;
  194. fpdGet({
  195. id: option.id
  196. }).then(res => {
  197. this.formData = res.data
  198. that.formData.orgName = res.data.orgDO.orgName
  199. this.actions2.map(i => {
  200. if (res.data.fpdType == i.id) {
  201. this.formData.fpdTypeName = i.name
  202. this.formData.fpdType = i.id
  203. }
  204. })
  205. that.buildingData.map(v => {
  206. if (v.id == that.formData.buildingId) {
  207. that.formData.buildingName = v.name
  208. }
  209. })
  210. })
  211. // const eventChannel = this.getOpenerEventChannel();
  212. // eventChannel.on('acceptDataFromOpenerPage', function(val) {
  213. // that.formData = val;
  214. // });
  215. //
  216. if (that.formData.fpdStatus === '' || that.formData.fpdStatus === null) {
  217. that.fpdStatus = ''
  218. } else if (that.formData.fpdStatus == 0) {
  219. that.fpdStatus = '正常'
  220. } else if (that.formData.fpdStatus == 1) {
  221. that.fpdStatus = '有问题'
  222. }
  223. // 获取单位id
  224. getOrgId({
  225. pageNo: this.pageNo,
  226. pageSize: this.pageSize,
  227. userId: this.$store.state.user.id
  228. }).then(response => {
  229. this.loading = false
  230. // 取到用户对应的单位名称与id
  231. response.data.map(v => {
  232. this.actions5.push({
  233. id: v.id,
  234. name: v.orgName
  235. });
  236. });
  237. });
  238. },
  239. onReady() {
  240. this.$refs.customForm.setRules(this.customRules);
  241. },
  242. onShow() {
  243. },
  244. methods: {
  245. //所属建筑
  246. buildingSelect(e) {
  247. this.formData.buildingId = e.id;
  248. this.formData.buildingName = e.name;
  249. },
  250. viewImageBig(i) {
  251. let imgList = []
  252. imgList.push(i)
  253. uni.previewImage({
  254. urls: imgList,
  255. current: i
  256. });
  257. },
  258. // ===
  259. closeImage(val, index) {
  260. this.formData.picVOList.splice(index, 1)
  261. },
  262. photoUpload() {
  263. let pictures = [];
  264. let that = this;
  265. uni.chooseImage({
  266. sourceType: ['camera'], //实现拍照
  267. count: 3,
  268. sizeType: ['original', 'compressed'],
  269. // sourceType: ['album','camera'], //打开系统相册
  270. success(res) {
  271. that.loading = true
  272. if (Array.isArray(res.tempFilePaths)) { //从相册选择有三张的情况
  273. res.tempFilePaths.forEach(item => {
  274. loadImage(
  275. item,
  276. function(canvas) {
  277. canvas.toBlob(function(blob) {
  278. // 压缩后的 Blob 对象
  279. const compressedFile = blob;
  280. // 将压缩后的文件 `compressedFile` 转换为临时URL
  281. const fileUrl = URL.createObjectURL(
  282. compressedFile);
  283. uni.uploadFile({
  284. url: baseUrl +
  285. '/admin-api/infra/file/upload', //后端用于处理图片并返回图片地址的接口
  286. filePath: item,
  287. name: 'file',
  288. header: {
  289. "Authorization": 'Bearer ' +
  290. getAccessToken(),
  291. }, //请求token
  292. success: (res) => {
  293. let imgUrl = JSON.parse(res
  294. .data)
  295. that.loading = false
  296. //拍照下展示的图片
  297. that.formData.picVOList.push({
  298. url: imgUrl.data,
  299. picname: ''
  300. })
  301. that.$forceUpdate();
  302. // // 返回的url
  303. },
  304. fail: () => {
  305. that.loading = false
  306. }
  307. })
  308. URL.revokeObjectURL(fileUrl);
  309. }, 'image/jpeg', 0.6); // 设置压缩后的图片格式为 JPEG,压缩质量为 0.6
  310. }, {
  311. canvas: true,
  312. maxWidth: 800
  313. } // 设置最大宽度为 800px
  314. );
  315. })
  316. }
  317. }
  318. })
  319. },
  320. submit(ref) {
  321. this.$refs[ref]
  322. .validate()
  323. .then(res => {
  324. this.formData['status'] = 0;
  325. this.formData.picVOList.forEach((item) => {
  326. // 删除除了feildname和url以外的多余字段
  327. Object.keys(item).forEach((key) => {
  328. if (key !== 'picname' && key !== 'url' && key !== 'fpdid') {
  329. delete item[key];
  330. }
  331. });
  332. // 如果feildname为空,赋值为默认名称
  333. if (!item.picname) {
  334. item.picname = '默认名称';
  335. }
  336. if (!item.fpdid) {
  337. item.fpdid = this.formData.id
  338. }
  339. });
  340. var jsdata = JSON.stringify(this.formData);
  341. updateDevice(jsdata).then(response => {
  342. uni.showLoading({
  343. title: response.data.msg
  344. });
  345. setTimeout(() => {
  346. uni.navigateBack({
  347. delta: 1
  348. })
  349. }, 0);
  350. });
  351. })
  352. .catch(err => {
  353. uni.showToast({
  354. icon: 'none',
  355. title: '错误!' + err[0].message
  356. })
  357. });
  358. },
  359. // 隐藏键盘
  360. hideKeyboard() {
  361. uni.hideKeyboard();
  362. },
  363. // 有无避难层
  364. sexSelect2(e) {
  365. this.formData.fpdTypeName = e.label;
  366. this.formData.fpdType = e.id;
  367. },
  368. // 设备状态
  369. sexSelect4(e) {
  370. this.formData.fpdStatus = e.id;
  371. this.fpdStatus = e.name;
  372. },
  373. // 所属单位
  374. sexSelect5(e) {
  375. this.formData.orgId = e.id;
  376. this.formData.orgName = e.name;
  377. },
  378. // 生成隐患弹出层 //暂存为草稿箱弹出层
  379. cancel() {
  380. this.show = false;
  381. },
  382. confirm() {
  383. setTimeout(() => {
  384. // 0.5秒后自动关闭
  385. this.show = false;
  386. }, 500);
  387. },
  388. // 触底的事件
  389. scrolltolower() {
  390. // 判断是否还有下一页数据
  391. if (this.pageNo * this.pageSize >= this.total)
  392. return uni.showToast({
  393. title: `数据加载完毕`
  394. });
  395. // 判断是否正在请求其它数据,如果是,则不发起额外的请求
  396. if (this.loading) return;
  397. this.pageNo += 1;
  398. this.showCheckboxShow(this.pageNo);
  399. }
  400. }
  401. };
  402. </script>
  403. <style lang="scss" scoped>
  404. page {
  405. height: 100%;
  406. background-color: #f5f7f9;
  407. position: relative;
  408. }
  409. .buttomBorder {
  410. height: 0px;
  411. border: 1px dashed #cbd5e1;
  412. }
  413. /deep/ .uni-section .uni-section-header {
  414. padding: 0px;
  415. }
  416. /deep/ .u-form-item__body {
  417. font-weight: 500;
  418. flex-direction: column !important;
  419. }
  420. /deep/ .u-form-item__body__left__content__label {
  421. margin-bottom: 16rpx;
  422. font-size: 30rpx !important;
  423. color: #274647 !important;
  424. }
  425. .arrow-icon {
  426. //主动检查箭头
  427. position: absolute;
  428. right: 14px;
  429. top: 49px;
  430. transform: rotate(90deg);
  431. }
  432. /deep/ .u-input[data-v-fdbb9fe6],
  433. /deep/ .u-input.data-v-fdbb9fe6,
  434. /deep/ .u-input {
  435. background-color: #fff;
  436. }
  437. /deep/.u-button[data-v-3bf2dba7],
  438. /deep/.u-button.data-v-3bf2dba7,
  439. /deep/.u-button {
  440. width: 60% !important;
  441. }
  442. //弹框样式
  443. .btnList {
  444. // width: 40%;
  445. display: flex;
  446. // display:flex;
  447. .u-button[data-v-3bf2dba7] {
  448. width: 30%;
  449. }
  450. }
  451. /deep/ .u-popup__content {
  452. //弹出的宽高
  453. height: 100%;
  454. }
  455. /deep/ .u-form-item__body__right__message {
  456. //校验的文字的位置
  457. margin-left: 10rpx !important;
  458. }
  459. /deep/ .uicon-close {
  460. //关闭按钮背景色
  461. background-color: rgba(199, 203, 210, 0.9);
  462. border-radius: 10%;
  463. }
  464. .checkbox {
  465. .checkbox-item {
  466. box-sizing: border-box;
  467. padding-top: 40px;
  468. }
  469. }
  470. //侧边联动
  471. .page-body {
  472. display: flex;
  473. background: #fff;
  474. overflow: hidden;
  475. }
  476. .nav {
  477. display: flex;
  478. width: 100%;
  479. }
  480. .nav-left {
  481. width: 25%;
  482. background: #fafafa;
  483. }
  484. .nav-left-item {
  485. height: 100upx;
  486. border-right: solid 1px #f1f1f1;
  487. border-bottom: solid 1px #f1f1f1;
  488. font-size: 30upx;
  489. display: flex;
  490. align-items: center;
  491. justify-content: center;
  492. }
  493. /deep/.nav-right-item[data-v-73caef23],
  494. /deep/.nav-right-item {
  495. display: flex;
  496. flex-wrap: wrap;
  497. }
  498. .nav-left-item:last-child {
  499. border-bottom: none;
  500. }
  501. .nav-right {
  502. width: 75%;
  503. }
  504. .box {
  505. display: block;
  506. overflow: hidden;
  507. border-bottom: 20upx solid #f3f3f3;
  508. /* min-height: 100vh; */
  509. /*若您的子分类过少想使得每个子分类占满屏请放开上边注视 */
  510. }
  511. .box:last-child {
  512. border: none;
  513. // min-height: 100vh;
  514. }
  515. .nav-right-item {
  516. margin-top: 20px;
  517. // width: 28%;
  518. // min-height: 200upx;
  519. float: left;
  520. text-align: center;
  521. padding: 11upx;
  522. font-size: 28upx;
  523. background: #fff;
  524. /deep/.u-checkbox__icon-wrap[data-v-532d01c7],
  525. /deep/.u-checkbox__icon-wrap {
  526. //复选框的样式
  527. margin: 0 20rpx;
  528. }
  529. /deep/ uni-view[data-v-3d1b15f2] {
  530. //复选框上线的间距
  531. margin: 20rpx 0 !important;
  532. }
  533. // /deep/ .u-checkbox__icon-wrap--square{
  534. // margin: 20rpx;
  535. // }
  536. .u-checkbox-label--right[data-v-532d01c7],
  537. .u-checkbox-label--right {
  538. margin-right: 40rpx;
  539. }
  540. }
  541. .nav-right-item image {
  542. width: 150upx;
  543. height: 150upx;
  544. }
  545. .active {
  546. font-weight: 700;
  547. color: #274647;
  548. background: #fff;
  549. border-right: 0;
  550. }
  551. ::-webkit-scrollbar {
  552. /*取消小程序的默认导航条样式*/
  553. width: 0;
  554. height: 0;
  555. color: transparent;
  556. }
  557. .selectBtn {
  558. width: 250rpx;
  559. margin-left: 0;
  560. font-size: 30rpx;
  561. background-color: #4cb2b6;
  562. }
  563. .tiantupian {
  564. width: 95rpx;
  565. height: 95rpx;
  566. }
  567. .example {
  568. overflow-y: auto;
  569. }
  570. /deep/.u-action-sheet {
  571. overflow-y: auto;
  572. height: 1000rpx;
  573. background-color: #fff;
  574. }
  575. </style>