edit_device.vue 14 KB

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