add_detection.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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" :rules='customRules' :model="formData" labelPosition="left" labelWidth="150"
  6. labelAlign="left">
  7. <view class=" flex flex-direction width100">
  8. <u-form-item label="检测项目" prop="detinspect" :required="true"
  9. @click="showInspOption = true;hideKeyboard();">
  10. <u--input v-model="formData.detinspect" disabled disabledColor="#ffffff"
  11. placeholder="请选择检测项目"></u--input>
  12. <!-- <u-input v-model="formData.detinspect" placeholder="请输入检测项目" /> -->
  13. </u-form-item>
  14. <u-form-item label="预计检测时间" prop="detdate">
  15. <uni-datetime-picker :show="unitTime" v-model="formData.detdate" type="datetime"
  16. closeOnClickOverlay @confirm="ActiveUnitTime" @cancel="unitTime = false"
  17. @change="changetime" @close="unitTime = false"></uni-datetime-picker>
  18. </u-form-item>
  19. <u-form-item label="检测维保结果" prop="detresult" @click="
  20. showreOption = true;
  21. hideKeyboard();" :required="true">
  22. <u--input v-model="formData.detresult.name" disabled disabledColor="#ffffff"
  23. placeholder="请选择检测维保结果"></u--input>
  24. <!-- <u-input v-model="formData.detresult" placeholder="请输入检测维保结果" /> -->
  25. </u-form-item>
  26. <u-form-item label="所属单位" @click="
  27. showSex5 = true;
  28. hideKeyboard();" prop="orgName" :required="true">
  29. <u--input v-model="formData.orgName" disabled disabledColor="#ffffff"
  30. placeholder="请选择所属单位"></u--input>
  31. </u-form-item>
  32. <u-form-item label="附件">
  33. <!-- 选择文件上传 -->
  34. <uni-file-picker v-model="formData.File" del-icon limit="1" auto-upload file-mediatype="all"
  35. @select="select" @delete="deleteFile">
  36. <button type="primary" class="selectBtn"
  37. style="background-color: rgba(76, 178, 182, 0.5);">选择附件</button>
  38. <!-- 加载中 -->
  39. <isLodingModel v-if="loading"></isLodingModel>
  40. </uni-file-picker>
  41. </u-form-item>
  42. </view>
  43. </u-form>
  44. <u-action-sheet :show="showSex5" :actions="actions5" title="请选择单位" @close="showSex5 = false"
  45. @select="sexSelect5"></u-action-sheet>
  46. <!-- 检测结果选项框 -->
  47. <u-action-sheet :show="showreOption" :actions="resultOptions" title="请选择检测维保结果"
  48. @close="showreOption = false" @select="setResult"></u-action-sheet>
  49. <!-- 检测项目选项框 -->
  50. <!-- <u-action-sheet :show="showInspOption" :actions="detinspectOptions" title="请选择检测项目"
  51. @close="showInspOption = false" @select="setInsp"></u-action-sheet> -->
  52. <!-- ----隐患 -->
  53. <u-popup :show="showInspOption" :round="10" @close="showInspOption=false">
  54. <view style="width: 70vw;overflow-y: auto;margin-bottom: 80rpx;padding:0 10px">
  55. <view style="position: sticky; top: 0; background-color: white;height:50px;padding-top: 10px;">
  56. <text class="text-xl">选择检测项目:</text>
  57. <text class="btn" @tap="onSelectAll">
  58. {{selectAll?'取消全选':'全选'}}
  59. </text>
  60. </view>
  61. <view class="person-forward" style="margin-top: 10px;">
  62. <u-checkbox-group placement="column" v-model="checkArr" @change="checkboxChange2"
  63. activeColor="#4CB2B6" iconSize="red">
  64. <u-checkbox v-for="(items, indexs) in detinspectOptions" :key="indexs"
  65. :customStyle="{marginBottom: '60rpx'}" :label="items.name" :name="items.name">
  66. </u-checkbox>
  67. </u-checkbox-group>
  68. </view>
  69. <view class="flex flex-direction-row "
  70. style="position: fixed;bottom: 10px;left: 50%;transform: translate(-50%);height: 100rpx;width: 80%">
  71. <u-button shape="circle" type="primary" color="#4CB2B6" text="确定" @click="checkboxConfirm2()"
  72. customStyle="margin-right:20px;padding:0 30px">
  73. </u-button>
  74. <u-button type="primary" plain color="#4CB2B6" text="取消" shape="circle"
  75. @click="checkboxCancel2()" customStyle="padding:0 30px">
  76. </u-button>
  77. </view>
  78. </view>
  79. </u-popup>
  80. <!-- ----隐患 -->
  81. </view>
  82. <uni-row class="heigthButton">
  83. <u-button @click="submit('customForm')" type="primary" shape="circle" size="large" color="#4CB2B6"
  84. text="确认新增"></u-button>
  85. </uni-row>
  86. </view>
  87. </template>
  88. <script>
  89. import {
  90. createFpdDetection, // 更新
  91. getOrgId,
  92. upload, //上传文件
  93. } from '@/api/fpdDetection/index.js';
  94. import {
  95. DICT_TYPE,
  96. getDictDatas
  97. } from '@/utils/dict';
  98. import {
  99. getAccessToken
  100. } from '@/utils/auth';
  101. import config from '@/config';
  102. import store from '@/store';
  103. import {
  104. uploadAvatar
  105. } from '@/api/system/user';
  106. const baseUrl = config.baseUrl;
  107. var that = null;
  108. export default {
  109. data() {
  110. return {
  111. isCheckAll: false,
  112. screenHeight: this.$screenHeight,
  113. wheight: '',
  114. showSex5: false, //所属单位
  115. actions: [],
  116. actions2: getDictDatas(DICT_TYPE.TRAIN_DRILL),
  117. actions5: [],
  118. //检测维保结果
  119. showreOption: false,
  120. resultOptions: getDictDatas(DICT_TYPE.BACKEND_DET_RESULT), //检测维保结果选项
  121. //检测项目
  122. showInspOption: false,
  123. detinspectOptions: getDictDatas(DICT_TYPE.DICT_INSPECT_TYPE), //检测项目选项
  124. checkArr: [],
  125. // 每页数据量
  126. pageSize: 5,
  127. // 当前页
  128. pageNo: 1,
  129. // 数据总量
  130. total: 0,
  131. unitTime: false,
  132. loading: false,
  133. selectAll: false,
  134. title: '生成隐患',
  135. content: '确认将此检查项目生成为隐患',
  136. // 自定义表单数据
  137. formData: {
  138. status: '0',
  139. File: [],
  140. detresult: {
  141. id: null,
  142. name: null
  143. }
  144. },
  145. // 自定义表单校验规则
  146. customRules: {
  147. detinspect: {
  148. type: 'string',
  149. required: true,
  150. message: ' 检测项目不能为空',
  151. trigger: ['blur', 'change']
  152. },
  153. unitTime: {
  154. type: 'string',
  155. message: '预计检测时间不能为空',
  156. trigger: ['blur', 'change']
  157. },
  158. orgName: {
  159. // pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/,
  160. // 自定义验证函数
  161. validator: (rule, value, callback) => {
  162. // 上面有说,返回true表示校验通过,返回false表示不通过
  163. // uni.$u.test.mobile()就是返回true或者false的
  164. //是否符合正则 且不为空
  165. if (!value) {
  166. return false
  167. }
  168. },
  169. message: '请输入检测维保结果',
  170. trigger: ['blur', 'change']
  171. },
  172. detresult: {
  173. // pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/,
  174. // 自定义验证函数
  175. validator: (rule, value, callback) => {
  176. // 上面有说,返回true表示校验通过,返回false表示不通过
  177. // uni.$u.test.mobile()就是返回true或者false的
  178. //是否符合正则 且不为空
  179. if (!value.id) {
  180. return false
  181. }
  182. },
  183. message: '请输入检测维保结果',
  184. trigger: ['blur', 'change']
  185. }
  186. }
  187. };
  188. },
  189. watch: {
  190. loading: {
  191. handler(newLength, oldLength) {
  192. this.$modal.isLoadingModel(this.loading)
  193. },
  194. immediate: true
  195. }
  196. },
  197. computed: {},
  198. mounted() {
  199. uni.createSelectorQuery().in(this).select('.heigthButton').boundingClientRect(data => {
  200. this.wheight = data.height
  201. }).exec()
  202. },
  203. // 在 vue页面,向起始页通过事件传递数据
  204. // 在 vue页面,向起始页通过事件传递数据
  205. onLoad: function(option) {
  206. this.formData.orgName = option.orgName ? option.orgName : ''
  207. this.formData.orgId = option.orgId ? option.orgId : ''
  208. this.actions2.map(i => {
  209. i.name = i.label;
  210. i.id = i.value;
  211. });
  212. // 获取单位id
  213. getOrgId({
  214. pageNo: this.pageNo,
  215. pageSize: this.pageSize,
  216. userId: this.$store.state.user.id
  217. }).then(response => {
  218. // console.log(response, 'response');
  219. // 取到用户对应的单位名称与id
  220. response.data.map(v => {
  221. this.actions5.push({
  222. id: v.dwid,
  223. name: v.orgName
  224. });
  225. });
  226. });
  227. //初始化检测结果选项
  228. const trueArr = []
  229. this.resultOptions.forEach(item => {
  230. trueArr.push({
  231. id: item.value,
  232. name: item.label
  233. })
  234. })
  235. this.resultOptions = [...trueArr]
  236. //初始化检测项目选项
  237. const trueArr1 = []
  238. // console.log('detinspectOptions', this.detinspectOptions);
  239. this.detinspectOptions.forEach(item => {
  240. trueArr1.push({
  241. id: item.value,
  242. name: item.label
  243. })
  244. })
  245. this.detinspectOptions = [...trueArr1]
  246. },
  247. onReady() {
  248. this.$refs.customForm.setRules(this.customRules);
  249. },
  250. methods: {
  251. onSelectAll() {
  252. this.selectAll = !this.selectAll;
  253. this.checkArr = this.selectAll ? this.detinspectOptions.map(item => item.name) : [];
  254. },
  255. submit(ref) {
  256. // console.log(this.formData, 'alertalertalert');
  257. // if (!this.formData.orgName) {
  258. // return this.$modal.msgError('请选择所属单位')
  259. // }
  260. // if (this.formData.unitTime && this.formData.unitTime.indexOf(":") === -1) {
  261. // this.formData.unitTime = this.formData.unitTime + ' 00:00:00'
  262. // }
  263. this.$refs[ref]
  264. .validate()
  265. .then(res => {
  266. this.formData['status'] = 0;
  267. // console.log('this.formData', this.formData);
  268. if (this.formData.File.length > 0) {
  269. this.formData.att = this.formData.File[0].url.toString();
  270. } else {
  271. this.formData.att = ''
  272. }
  273. //对要提交的数据进行处理 {id,name}只保存name
  274. this.$set(this.formData, 'detresult', this.formData.detresult.id)
  275. var jsdata = JSON.stringify(this.formData);
  276. // console.log(jsdata, 'jsdatajsdatajsdata');
  277. createFpdDetection(jsdata).then(response => {
  278. // console.log('response.data.msg,', response.data);
  279. uni.showLoading({
  280. title: response.data.msg
  281. });
  282. setTimeout(() => {
  283. // console.log('新增成功!');
  284. uni.hideLoading();
  285. uni.navigateBack({
  286. delta: 1
  287. })
  288. }, 0);
  289. }).catch(err => {});
  290. })
  291. .catch(err => {
  292. // console.log(err,'eeeeeeeeee');
  293. // uni.showToast({
  294. // icon:'none',
  295. // title:'错误!'+ err[0].message
  296. // })
  297. });
  298. },
  299. // 上传图片 获取上传状态
  300. // 选择上传触发函数
  301. select(e) {
  302. // 根据所选图片的个数,多次调用上传函数
  303. let promises = [];
  304. for (let i = 0; i < e.tempFilePaths.length; i++) {
  305. const promise = this.uploadFiles(e.tempFilePaths, i);
  306. promises.push(promise);
  307. }
  308. Promise.all(promises).then(result => {});
  309. },
  310. // 上传函数
  311. async uploadFiles(tempFilePaths, i) {
  312. const that = this;
  313. this.loading = true
  314. await uni.uploadFile({
  315. url: baseUrl + '/admin-api/infra/file/upload', //后端用于处理图片并返回图片地址的接口
  316. filePath: tempFilePaths[i],
  317. name: 'file',
  318. header: {
  319. Authorization: 'Bearer ' + getAccessToken()
  320. }, //请求token
  321. success: res => {
  322. // console.log('uploadres', res);
  323. let data = JSON.parse(res.data);
  324. // 返回的url
  325. var fileLink = data.data;
  326. const code = data.code;
  327. // 如果成功,将返回的data数据给 formdata
  328. if (code == 0) {
  329. that.formData.File.push({
  330. url: fileLink,
  331. name: fileLink
  332. });
  333. uni.showToast({
  334. title: '文件上传成功!'
  335. });
  336. that.loading = false
  337. // that.formData.attId = fileLink
  338. }
  339. // this.formData.attId = this.formData.attId.toString();
  340. },
  341. fail: () => {
  342. // console.log('err');
  343. uni.showToast({
  344. icon: 'error',
  345. title: '文件上传失败!'
  346. });
  347. }
  348. });
  349. },
  350. // 移出图片函数
  351. async deleteFile(e) {
  352. // console.log(e);
  353. this.formData.attId = [];
  354. // console.log('移除了:', this.formData.attId);
  355. },
  356. //检测项目多选框选中
  357. checkboxChange2(arr) { //勾选的事件
  358. console.log('arr', arr);
  359. this.checkArr = [...arr]
  360. },
  361. //多选确定事件
  362. checkboxConfirm2() {
  363. this.showInspOption = false
  364. this.formData.detinspect = this.checkArr.join(',')
  365. // console.log('detinspect',this.formData.detinspect);
  366. },
  367. //多选取消事件
  368. checkboxCancel2() {
  369. this.showInspOption = false
  370. // console.log('this.formData.detinspect',this.formData.detinspect);
  371. if (this.formData.detinspect) {
  372. const nowArr = this.formData.detinspect.split(',')
  373. this.checkArr = [...nowArr]
  374. } else {
  375. this.checkArr = []
  376. }
  377. },
  378. // 隐藏键盘
  379. hideKeyboard() {
  380. uni.hideKeyboard();
  381. },
  382. changetime(e) {
  383. console.log('change', e);
  384. },
  385. // 所属单位
  386. sexSelect5(e) {
  387. // console.log('e',e);
  388. this.formData.orgId = e.id;
  389. this.formData.orgName = e.name;
  390. // console.log(this.formData);
  391. },
  392. // 检测维保结果select事件
  393. setResult(e) {
  394. // console.log('e', e);
  395. this.formData.detresult = {
  396. id: e.id,
  397. name: e.name
  398. };
  399. // this.formData.orgName = e.name;
  400. },
  401. // 检测检测项目select事件
  402. setInsp(e) {
  403. // console.log('e', e);
  404. this.formData.detinspect = e.name;
  405. // this.formData.orgName = e.name;
  406. // console.log(this.formData.orgId);
  407. },
  408. // 生成隐患弹出层 //暂存为草稿箱弹出层
  409. cancel() {
  410. this.show = false;
  411. },
  412. confirm() {
  413. setTimeout(() => {
  414. // 0.5秒后自动关闭
  415. this.show = false;
  416. }, 500);
  417. },
  418. // 触底的事件
  419. scrolltolower() {
  420. // 判断是否还有下一页数据
  421. if (this.pageNo * this.pageSize >= this.total)
  422. return uni.showToast({
  423. title: `数据加载完毕`
  424. });
  425. // 判断是否正在请求其它数据,如果是,则不发起额外的请求
  426. if (this.loading) return;
  427. this.pageNo += 1;
  428. this.showCheckboxShow(this.pageNo);
  429. }
  430. }
  431. };
  432. </script>
  433. <style lang="scss" scoped>
  434. page {
  435. height: 100%;
  436. background-color: #f5f7f9;
  437. position: relative;
  438. }
  439. .buttomBorder {
  440. height: 0px;
  441. border: 1px dashed #cbd5e1;
  442. }
  443. /deep/ .uni-section .uni-section-header {
  444. padding: 0px;
  445. }
  446. /deep/ .u-form-item__body {
  447. font-weight: 500;
  448. flex-direction: column !important;
  449. }
  450. /deep/ .u-form-item__body__left__content__label {
  451. margin-bottom: 16rpx;
  452. font-size: 30rpx !important;
  453. color: #274647 !important;
  454. }
  455. .arrow-icon {
  456. //主动检查箭头
  457. position: absolute;
  458. right: 14px;
  459. top: 49px;
  460. transform: rotate(90deg);
  461. }
  462. /deep/ .u-input[data-v-fdbb9fe6],
  463. /deep/ .u-input.data-v-fdbb9fe6,
  464. /deep/ .u-input {
  465. background-color: #fff;
  466. }
  467. /deep/.u-button[data-v-3bf2dba7],
  468. /deep/.u-button.data-v-3bf2dba7,
  469. /deep/.u-button {
  470. width: 60% !important;
  471. }
  472. //弹框样式
  473. .btnList {
  474. // width: 40%;
  475. display: flex;
  476. // display:flex;
  477. .u-button[data-v-3bf2dba7] {
  478. width: 30%;
  479. }
  480. }
  481. /deep/ .u-popup__content {
  482. //弹出的宽高
  483. height: 100%;
  484. }
  485. /deep/ .u-form-item__body__right__message {
  486. //校验的文字的位置
  487. margin-left: 10rpx !important;
  488. }
  489. /deep/ .uicon-close {
  490. //关闭按钮背景色
  491. background-color: rgba(199, 203, 210, 0.9);
  492. border-radius: 10%;
  493. }
  494. .checkbox {
  495. .checkbox-item {
  496. box-sizing: border-box;
  497. padding-top: 40px;
  498. }
  499. }
  500. //侧边联动
  501. .page-body {
  502. display: flex;
  503. background: #fff;
  504. overflow: hidden;
  505. }
  506. .nav {
  507. display: flex;
  508. width: 100%;
  509. }
  510. .nav-left {
  511. width: 25%;
  512. background: #fafafa;
  513. }
  514. .nav-left-item {
  515. height: 100upx;
  516. border-right: solid 1px #f1f1f1;
  517. border-bottom: solid 1px #f1f1f1;
  518. font-size: 30upx;
  519. display: flex;
  520. align-items: center;
  521. justify-content: center;
  522. }
  523. /deep/.nav-right-item[data-v-73caef23],
  524. /deep/.nav-right-item {
  525. display: flex;
  526. flex-wrap: wrap;
  527. }
  528. .nav-left-item:last-child {
  529. border-bottom: none;
  530. }
  531. .nav-right {
  532. width: 75%;
  533. }
  534. .box {
  535. display: block;
  536. overflow: hidden;
  537. border-bottom: 20upx solid #f3f3f3;
  538. /* min-height: 100vh; */
  539. /*若您的子分类过少想使得每个子分类占满屏请放开上边注视 */
  540. }
  541. .box:last-child {
  542. border: none;
  543. // min-height: 100vh;
  544. }
  545. .nav-right-item {
  546. margin-top: 20px;
  547. // width: 28%;
  548. // min-height: 200upx;
  549. float: left;
  550. text-align: center;
  551. padding: 11upx;
  552. font-size: 28upx;
  553. background: #fff;
  554. /deep/.u-checkbox__icon-wrap[data-v-532d01c7],
  555. /deep/.u-checkbox__icon-wrap {
  556. //复选框的样式
  557. margin: 0 20rpx;
  558. }
  559. /deep/ uni-view[data-v-3d1b15f2] {
  560. //复选框上线的间距
  561. margin: 20rpx 0 !important;
  562. }
  563. // /deep/ .u-checkbox__icon-wrap--square{
  564. // margin: 20rpx;
  565. // }
  566. .u-checkbox-label--right[data-v-532d01c7],
  567. .u-checkbox-label--right {
  568. margin-right: 40rpx;
  569. }
  570. }
  571. .nav-right-item image {
  572. width: 150upx;
  573. height: 150upx;
  574. }
  575. .active {
  576. font-weight: 700;
  577. color: #274647;
  578. background: #fff;
  579. border-right: 0;
  580. }
  581. ::-webkit-scrollbar {
  582. /*取消小程序的默认导航条样式*/
  583. width: 0;
  584. height: 0;
  585. color: transparent;
  586. }
  587. .selectBtn {
  588. width: 200rpx;
  589. margin-left: 0;
  590. font-size: 30rpx;
  591. background-color: #4cb2b6;
  592. }
  593. /deep/.u-action-sheet,
  594. /deep/.u-transition {
  595. overflow-y: auto;
  596. height: 1000rpx;
  597. background-color: #fff;
  598. }
  599. .example {
  600. overflow-y: auto;
  601. }
  602. .btn{
  603. color: #4CB2B6;
  604. margin-left: 20px;
  605. padding:10rpx 40rpx;
  606. border: 1px solid #4CB2B6;
  607. border-radius: 8rpx;
  608. }
  609. </style>