edit_device.vue 15 KB

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