add_drill.vue 13 KB

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