add_device.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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.FPD_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.actions2.map(i => {
  174. i.name = i.label;
  175. i.id = i.value;
  176. });
  177. console.log('this.actions2: ', this.actions2);
  178. this.loading = true
  179. // 获取单位id
  180. getOrgId({
  181. pageNo: this.pageNo,
  182. pageSize: this.pageSize,
  183. userId: this.$store.state.user.id
  184. }).then(response => {
  185. console.log(response, 'response');
  186. this.loading = false
  187. // 取到用户对应的单位名称与id
  188. response.data.map(v => {
  189. this.actions5.push({
  190. id: v.dwid,
  191. name: v.orgName
  192. });
  193. });
  194. });
  195. },
  196. onReady() {
  197. this.$refs.customForm.setRules(this.customRules);
  198. },
  199. methods: {
  200. closeImage(val, index) {
  201. this.formData.picVOList.splice(index, 1)
  202. console.log(this.formData.picVOList, 'this.formData.picVOList');
  203. },
  204. photoUpload() {
  205. let pictures = [];
  206. var that = this;
  207. uni.chooseImage({
  208. sourceType: ['camera'], //实现拍照
  209. count: 3,
  210. sizeType: ['original', 'compressed'],
  211. // sourceType: ['album','camera'], //打开系统相册
  212. success(res) {
  213. that.loading = true
  214. if (Array.isArray(res.tempFilePaths)) { //从相册选择有三张的情况
  215. res.tempFilePaths.forEach(item => {
  216. loadImage(
  217. item,
  218. function(canvas) {
  219. canvas.toBlob(function(blob) {
  220. // 压缩后的 Blob 对象
  221. const compressedFile = blob;
  222. // 将压缩后的文件 `compressedFile` 转换为临时URL
  223. const fileUrl = URL.createObjectURL(
  224. compressedFile);
  225. uni.uploadFile({
  226. url: baseUrl +
  227. '/admin-api/infra/file/upload', //后端用于处理图片并返回图片地址的接口
  228. filePath: item,
  229. name: 'file',
  230. header: {
  231. "Authorization": 'Bearer ' +
  232. getAccessToken(),
  233. }, //请求token
  234. success: (res) => {
  235. let imgUrl = JSON.parse(res
  236. .data)
  237. that.loading = false
  238. //拍照下展示的图片
  239. that.formData.picVOList.push({
  240. url: imgUrl.data,
  241. picname: ''
  242. })
  243. that.$forceUpdate();
  244. // // 返回的url
  245. },
  246. fail: () => {
  247. that.loading = false
  248. console.log("err");
  249. }
  250. })
  251. URL.revokeObjectURL(fileUrl);
  252. }, 'image/jpeg', 0.6); // 设置压缩后的图片格式为 JPEG,压缩质量为 0.6
  253. }, {
  254. canvas: true,
  255. maxWidth: 800
  256. } // 设置最大宽度为 800px
  257. );
  258. })
  259. }
  260. }
  261. })
  262. },
  263. submit(ref) {
  264. console.log('this.formData: ', this.formData);
  265. this.$refs[ref]
  266. .validate()
  267. .then(res => {
  268. this.formData['status'] = 0;
  269. // this.formData.picVOList=JSON.stringify(this.formData.picVOList);
  270. this.formData.picVOList.map(i => {
  271. if (!i.picname) {
  272. i.picname = '默认名称'
  273. }
  274. })
  275. var jsdata = JSON.stringify(this.formData);
  276. console.log(jsdata, 'jsdatajsdatajsdata');
  277. createDevice(jsdata).then(response => {
  278. console.log('response.data.msg,', response.data);
  279. uni.showLoading({
  280. title: response.data.msg
  281. });
  282. uni.navigateBack({
  283. delta: 1
  284. });
  285. });
  286. })
  287. .catch(err => {
  288. console.log('err错误信息为:', err);
  289. uni.showToast({
  290. icon: 'none',
  291. title: '错误!' + err[0].message
  292. })
  293. });
  294. },
  295. // 隐藏键盘
  296. hideKeyboard() {
  297. uni.hideKeyboard();
  298. },
  299. // 类型
  300. sexSelect2(e) {
  301. console.log('e: ', e);
  302. this.formData.fpdTypeName = e.label;
  303. this.formData.fpdType = e.value;
  304. console.log(this.formData.fpdType);
  305. },
  306. // 设备状态
  307. sexSelect4(e) {
  308. this.formData.fpdStatus = e.id;
  309. this.fpdStatus = e.name;
  310. console.log(this.formData.fpdStatus);
  311. },
  312. // 所属单位
  313. sexSelect5(e) {
  314. this.formData.orgId = e.id;
  315. this.formData.orgName = e.name;
  316. console.log(this.formData.orgId);
  317. },
  318. // 生成隐患弹出层 //暂存为草稿箱弹出层
  319. cancel() {
  320. this.show = false;
  321. },
  322. confirm() {
  323. setTimeout(() => {
  324. // 0.5秒后自动关闭
  325. this.show = false;
  326. }, 500);
  327. }
  328. }
  329. };
  330. </script>
  331. <style lang="scss" scoped>
  332. page {
  333. height: 100%;
  334. background-color: #f5f7f9;
  335. position: relative;
  336. }
  337. .buttomBorder {
  338. height: 0px;
  339. border: 1px dashed #cbd5e1;
  340. }
  341. /deep/ .uni-section .uni-section-header {
  342. padding: 0px;
  343. }
  344. /deep/ .u-form-item__body {
  345. font-weight: 500;
  346. flex-direction: column !important;
  347. }
  348. /deep/ .u-form-item__body__left__content__label,
  349. .paizhao {
  350. margin-bottom: 16rpx;
  351. font-size: 30rpx !important;
  352. color: #274647 !important;
  353. }
  354. .arrow-icon {
  355. //主动检查箭头
  356. position: absolute;
  357. right: 14px;
  358. top: 49px;
  359. transform: rotate(90deg);
  360. }
  361. /deep/ .u-input[data-v-fdbb9fe6],
  362. /deep/ .u-input.data-v-fdbb9fe6,
  363. /deep/ .u-input {
  364. background-color: #fff;
  365. }
  366. /deep/.u-button[data-v-3bf2dba7],
  367. /deep/.u-button.data-v-3bf2dba7,
  368. /deep/.u-button {
  369. width: 60% !important;
  370. }
  371. //弹框样式
  372. .btnList {
  373. // width: 40%;
  374. display: flex;
  375. // display:flex;
  376. .u-button[data-v-3bf2dba7],
  377. .u-button {
  378. width: 30%;
  379. }
  380. }
  381. /deep/ .u-popup__content {
  382. //弹出的宽高
  383. height: 100%;
  384. }
  385. /deep/ .u-form-item__body__right__message {
  386. //校验的文字的位置
  387. margin-left: 10rpx !important;
  388. }
  389. /deep/ .uicon-close {
  390. //关闭按钮背景色
  391. background-color: rgba(199, 203, 210, 0.9);
  392. border-radius: 10%;
  393. }
  394. .checkbox {
  395. .checkbox-item {
  396. box-sizing: border-box;
  397. padding-top: 40px;
  398. }
  399. }
  400. //侧边联动
  401. .page-body {
  402. display: flex;
  403. background: #fff;
  404. overflow: hidden;
  405. }
  406. .nav {
  407. display: flex;
  408. width: 100%;
  409. }
  410. .nav-left {
  411. width: 25%;
  412. background: #fafafa;
  413. }
  414. .nav-left-item {
  415. height: 100upx;
  416. border-right: solid 1px #f1f1f1;
  417. border-bottom: solid 1px #f1f1f1;
  418. font-size: 30upx;
  419. display: flex;
  420. align-items: center;
  421. justify-content: center;
  422. }
  423. /deep/.nav-right-item[data-v-73caef23],
  424. /deep/.nav-right-item {
  425. display: flex;
  426. flex-wrap: wrap;
  427. }
  428. .nav-left-item:last-child {
  429. border-bottom: none;
  430. }
  431. .nav-right {
  432. width: 75%;
  433. }
  434. .box {
  435. display: block;
  436. overflow: hidden;
  437. border-bottom: 20upx solid #f3f3f3;
  438. /* min-height: 100vh; */
  439. /*若您的子分类过少想使得每个子分类占满屏请放开上边注视 */
  440. }
  441. .box:last-child {
  442. border: none;
  443. // min-height: 100vh;
  444. }
  445. .nav-right-item {
  446. margin-top: 20px;
  447. // width: 28%;
  448. // min-height: 200upx;
  449. float: left;
  450. text-align: center;
  451. padding: 11upx;
  452. font-size: 28upx;
  453. background: #fff;
  454. /deep/.u-checkbox__icon-wrap[data-v-532d01c7],
  455. /deep/.u-checkbox__icon-wrap {
  456. //复选框的样式
  457. margin: 0 20rpx;
  458. }
  459. /deep/ uni-view[data-v-3d1b15f2] {
  460. //复选框上线的间距
  461. margin: 20rpx 0 !important;
  462. }
  463. // /deep/ .u-checkbox__icon-wrap--square{
  464. // margin: 20rpx;
  465. // }
  466. .u-checkbox-label--right[data-v-532d01c7],
  467. .u-checkbox-label--right {
  468. margin-right: 40rpx;
  469. }
  470. }
  471. .nav-right-item image {
  472. width: 150upx;
  473. height: 150upx;
  474. }
  475. .active {
  476. font-weight: 700;
  477. color: #274647;
  478. background: #fff;
  479. border-right: 0;
  480. }
  481. ::-webkit-scrollbar {
  482. /*取消小程序的默认导航条样式*/
  483. width: 0;
  484. height: 0;
  485. color: transparent;
  486. }
  487. .selectBtn {
  488. width: 250rpx;
  489. margin-left: 0;
  490. font-size: 30rpx;
  491. background-color: #4cb2b6;
  492. }
  493. .tiantupian {
  494. width: 95rpx;
  495. height: 95rpx;
  496. }
  497. .example {
  498. overflow-y: auto;
  499. }
  500. </style>