add_device.vue 13 KB

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