add_detection.vue 16 KB

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