add_device.vue 13 KB

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