add_detection.vue 15 KB

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