add_device.vue 14 KB

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