add_detection.vue 14 KB

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