addTraining.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <template>
  2. <div>
  3. <NavBar />
  4. <van-form class="bigbox" ref="form">
  5. <div class="mainItem">
  6. <div class="label">培训主题</div>
  7. <div>{{ trainingData.title }}</div>
  8. </div>
  9. <div class="mainItem">
  10. <div class="label">单位名称</div>
  11. <div>{{ trainingData.orgName }}</div>
  12. </div>
  13. <!-- <van-field
  14. readonly
  15. clickable
  16. required
  17. name="picker"
  18. :value="form.typeText"
  19. label="培训类型"
  20. :rules="[{ required: true, message: '培训类型不能为空' }]"
  21. placeholder="请选择培训类型"
  22. @click="showPicker = true"
  23. />-->
  24. <van-popup v-model="showPicker" position="bottom">
  25. <van-picker show-toolbar :columns="columns" @confirm="onConfirm" @cancel="showPicker = false" />
  26. </van-popup>
  27. <!-- 培训开始时间 -->
  28. <van-field
  29. readonly
  30. clickable
  31. name="datetimePicker"
  32. :value="form.trainingStartDateTime"
  33. required
  34. :rules="[{ required: true, message: '培训开始时间不能为空' }]"
  35. label="培训开始时间"
  36. placeholder="请选择培训开始时间"
  37. @click="showStartDate = true"
  38. />
  39. <van-popup v-model="showStartDate" position="bottom">
  40. <van-datetime-picker
  41. v-model="startDateTime"
  42. type="datetime"
  43. @confirm="onConfirmDate"
  44. @cancel="showStartDate = false"
  45. :formatter="formatter"
  46. />
  47. </van-popup>
  48. <!-- 培训结束时间 -->
  49. <van-field
  50. readonly
  51. clickable
  52. name="datetimePicker"
  53. :value="form.trainingEndDateTime"
  54. required
  55. :rules="[{ required: true, message: '培训结束时间不能为空' }]"
  56. label="培训结束时间"
  57. placeholder="请选择培训结束时间"
  58. @click="showEndDate = true"
  59. />
  60. <van-popup v-model="showEndDate" position="bottom">
  61. <van-datetime-picker
  62. v-model="endDateTime"
  63. type="datetime"
  64. :formatter="formatter"
  65. @confirm="onConfirmEndDate"
  66. @cancel="showEndDate = false"
  67. />
  68. </van-popup>
  69. <!-- <van-button type="info">从学习资料选取</van-button> -->
  70. <div class="mainItem mainItemData">
  71. <p class="label labelPeople">培训资料</p>
  72. <div>
  73. <div v-for="item in studyList" :key="item.name">
  74. <van-tag type="primary" @click="tagHandler(item)" class="tagCls" plain>{{ item.name }}</van-tag
  75. ><span class="deleteCls" @click="close(item)">删除</span>
  76. </div>
  77. </div>
  78. </div>
  79. <van-field label="">
  80. <template #input>
  81. <van-button type="info" size="small" @click="selectData">选取知识库文件</van-button>
  82. </template>
  83. </van-field>
  84. <!-- 培训内容 -->
  85. <van-field
  86. required
  87. :rules="[{ required: true, message: '培训内容不能为空' }]"
  88. v-model="form.content"
  89. name="content"
  90. label="培训内容"
  91. type="textarea"
  92. rows="6"
  93. maxlength="2000"
  94. show-word-limit
  95. placeholder="请填写培训内容"
  96. />
  97. <!-- 总结 -->
  98. <van-field
  99. required
  100. :rules="[{ required: true, message: '总结不能为空' }]"
  101. v-model="form.note"
  102. name="note"
  103. label="总结"
  104. type="textarea"
  105. rows="6"
  106. maxlength="2000"
  107. show-word-limit
  108. placeholder="请结合网点进行总结"
  109. />
  110. <!-- 主持人 -->
  111. <van-field
  112. required
  113. :rules="[{ required: true, message: '地点不能为空' }]"
  114. v-model="form.site"
  115. name="site"
  116. label="地点"
  117. rows="6"
  118. placeholder="请输入地点"
  119. />
  120. <!-- 参与人员 -->
  121. <!-- 主持人 -->
  122. <van-field
  123. required
  124. :rules="[{ required: true, message: '主持人不能为空' }]"
  125. v-model="form.hostName"
  126. name="hostName"
  127. label="主持人"
  128. rows="6"
  129. placeholder="请输入主持人"
  130. />
  131. <!-- 必填 -->
  132. <CheckPeople
  133. :userList="userPeopleList"
  134. :organizationId="trainingData.orgId"
  135. :isRequired="true"
  136. @userList="userListHandler"
  137. ></CheckPeople>
  138. <!-- 缺席人员 -->
  139. <CheckPeople
  140. :userList="lackPeopleList"
  141. :inpitLabel="'缺席人员'"
  142. :organizationId="trainingData.orgId"
  143. :isRequired="false"
  144. @userList="lackUserListHandler"
  145. ></CheckPeople>
  146. <!-- 上传 -->
  147. <van-field readonly required clickable name="uploader" label="上传图片">
  148. <template #input>
  149. <Upload v-model="form.imageList" :multiple="true" :maxCount="10" @input="listHandler"></Upload>
  150. </template>
  151. </van-field>
  152. <div class="btns" v-show="isBtn">
  153. <van-button type="info" @click="submitHandler(1)">保存</van-button>
  154. <van-button type="info" @click="submitHandler(2)">提交</van-button>
  155. </div>
  156. <!-- 选择资料 -->
  157. <SelectData
  158. ref="SelectData"
  159. :organizationId="trainingData.orgId"
  160. :listLength="studyList.length"
  161. @dataList="dataList"
  162. ></SelectData>
  163. </van-form>
  164. </div>
  165. </template>
  166. <script>
  167. import NavBar from '@/components/NavBar'
  168. import CheckPeople from '@/components/peopleList/index.vue'
  169. import SelectData from './selectData.vue'
  170. import Upload from '@/components/upload/index.vue'
  171. // import imgCom from '@/components/imgCom/index.vue'
  172. // import VuePdf from '@/components/pdfCom/index.vue'
  173. import { gettrainingInfo, edittrainingInfo } from '@/api/training.js'
  174. import { newDateTimeMin } from '@/utils/date.js'
  175. import { Dialog, Toast } from 'vant'
  176. import { uniqBy } from 'lodash'
  177. import PDFAndImgLook from '@/components/imgAndPDF/index.vue'
  178. import {onresizeHandler} from '@/utils/onresizeMixins.js'
  179. export default {
  180. name: 'SocAppAddTraining',
  181. mixins:[onresizeHandler],
  182. components: {
  183. SelectData,
  184. NavBar,
  185. PDFAndImgLook,
  186. // imgCom,
  187. Upload,
  188. CheckPeople
  189. },
  190. data() {
  191. return {
  192. current: 0,
  193. this_window: window,
  194. studyList: [], //学习资料数组
  195. startDateTime: new Date(),
  196. endDateTime: new Date(),
  197. falg: false, //校验是否通过
  198. username: '',
  199. password: '',
  200. form: {
  201. // typeText: '', //培训类型
  202. site: '', //地点
  203. type: '', //培训value
  204. content: '', //培训内容
  205. note: '', //培训总结
  206. hostName: '',//主持人
  207. taskUserList: [], //人员数组
  208. imageList: [], //图片数组
  209. trainingStartDateTime: '', //开始时间
  210. trainingEndDateTime: '' //结束时间
  211. },
  212. trainingData: {},
  213. userPeopleList: [], //参与人员数组
  214. lackPeopleList: [], //缺席人员数组
  215. showPicker: false, //培训类型显示隐藏
  216. showStartDate: false, //开始时间显示隐藏
  217. showEndDate: false, //结束时间显示隐藏
  218. columns: ['每月安全培训教育', '专项安全培训教育']
  219. }
  220. },
  221. created() {
  222. this.getDictHandler('edu_training_type', res => {
  223. this.columnsList = res
  224. this.columns = res.map(item => item.dictLabel)
  225. })
  226. //获取详情信息
  227. gettrainingInfo(this.$route.params.id).then(res => {
  228. let { code, data, msg } = res
  229. if (code == 200) {
  230. this.trainingData = data
  231. if (!data.taskUserList) {
  232. data.taskUserList = []
  233. }
  234. let newlist = data.fileList || []
  235. if (newlist.length > 0) {
  236. newlist.forEach(item => {
  237. let i = JSON.parse(item)
  238. if (i.url.split('.')[1] == 'pdf') {
  239. i.type = 1
  240. } else {
  241. i.type = 0
  242. }
  243. i.path = i.url
  244. this.studyList.push(i)
  245. })
  246. }
  247. if (!data.imageList) {
  248. data.imageList = []
  249. } else {
  250. let list = []
  251. data.imageList = data.imageList.split(',')
  252. data.imageList.forEach(item => {
  253. list.push({
  254. name: '',
  255. path: item
  256. })
  257. })
  258. data.imageList = list || []
  259. }
  260. Object.assign(this.form, data)
  261. // checkPeople
  262. this.form.taskUserList
  263. .map(item => {
  264. if (item.type === 1) {
  265. this.userPeopleList.push(item)
  266. return item.userName
  267. }
  268. })
  269. .join(',')
  270. this.form.taskUserList
  271. .map(item => {
  272. if (item.type === 2) {
  273. this.lackPeopleList.push(item)
  274. return item.userName
  275. }
  276. })
  277. .join(',')
  278. }
  279. })
  280. },
  281. mounted() {},
  282. methods: {
  283. //日期选择组件formatter
  284. formatter(type, val) {
  285. if (type === 'month') {
  286. return `${val}月`;
  287. } else if (type === 'day') {
  288. return `${val}日`;
  289. } else if (type === 'year') {
  290. return `${val}年`;
  291. }else if (type === 'hour') {
  292. return `${val}时`;
  293. }else if (type === 'minute') {
  294. return `${val}分`;
  295. }
  296. return val;
  297. },
  298. //从资料里选取
  299. selectData() {
  300. this.$refs.SelectData.show = true
  301. this.studyList = this.studyList.filter(item => item.type != undefined)
  302. },
  303. clikHadner() {
  304. this.$refs.PDFAndImgLook.show = true
  305. },
  306. onChange(index) {
  307. this.current = index
  308. },
  309. // 查看pdf
  310. onSubmit(values) {
  311. console.log('submit', values)
  312. Dialog.confirm({
  313. title: '',
  314. message: '是否提交培训数据?'
  315. })
  316. .then(() => {
  317. // on confirm
  318. })
  319. .catch(() => {
  320. // on cancel
  321. })
  322. },
  323. //培训类型确认
  324. onConfirm(val) {
  325. this.form.typeText = val //培训类型赋值
  326. switch (val) {
  327. case '每月安全培训教育':
  328. this.form.type = '0'
  329. break
  330. case '专项安全培训教育':
  331. this.form.type = '1'
  332. break
  333. }
  334. this.showPicker = false
  335. },
  336. //开始时间确认
  337. onConfirmDate(val) {
  338. this.form.trainingStartDateTime = newDateTimeMin(val)
  339. this.showStartDate = false
  340. },
  341. //结束时间
  342. onConfirmEndDate(val) {
  343. this.form.trainingEndDateTime = newDateTimeMin(val)
  344. this.showEndDate = false
  345. },
  346. userListHandler(list) {
  347. list.forEach(item => {
  348. ;(item.type = 1), (item.userId = item.id)
  349. item.userName = item.username
  350. item.name = item.userName
  351. delete item.username
  352. })
  353. this.userPeopleList = list
  354. },
  355. lackUserListHandler(list) {
  356. list.forEach(item => {
  357. item.type = 2
  358. ;(item.userId = item.id), (item.userName = item.username)
  359. delete item.username
  360. })
  361. this.lackPeopleList = list
  362. },
  363. //上传附件成功
  364. listHandler(list) {
  365. this.form.imageList = list || []
  366. },
  367. //表单提交前校验
  368. beforSubmitV() {
  369. this.falg = false
  370. let startDate = JSON.parse(JSON.stringify(this.form.trainingStartDateTime))
  371. let objStart=startDate.replace(/-/g,"/");
  372. startDate = Date.parse(new Date(startDate))
  373. if(!startDate){
  374. startDate = Date.parse(new Date(objStart));
  375. }
  376. if(!startDate){
  377. Toast('培训开始时间不能为空')
  378. this.falg = true
  379. return
  380. }
  381. let endDate = JSON.parse(JSON.stringify(this.form.trainingEndDateTime))
  382. let objend=endDate.replace(/-/g,"/");
  383. endDate = Date.parse(new Date(endDate))
  384. if(!endDate){
  385. endDate = Date.parse(new Date(objend));
  386. }
  387. if(!endDate){
  388. Toast('培训结束时间不能为空')
  389. this.falg = true
  390. return
  391. }
  392. if (startDate >= endDate) {
  393. Toast('开始时间不能大于或等于结束时间')
  394. this.falg = true
  395. return
  396. }
  397. if (this.form.imageList.length == 0) {
  398. Toast('上传图片不能为空')
  399. this.falg = true
  400. return
  401. }
  402. if (this.userPeopleList.length == 0) {
  403. Toast('参与人员不能为空!')
  404. this.falg = true
  405. return
  406. }
  407. if (this.userPeopleList.length > this.lackPeopleList.length) {
  408. let isTrue = false
  409. this.userPeopleList.forEach(item => {
  410. this.lackPeopleList.forEach(i => {
  411. if (item.userId == i.userId) {
  412. isTrue = true
  413. }
  414. })
  415. })
  416. if (isTrue) {
  417. Toast('参与人员与缺席人员存在同一个人请修正!')
  418. this.falg = true
  419. }
  420. } else {
  421. let isTrue = false
  422. this.lackPeopleList.forEach(item => {
  423. this.userPeopleList.forEach(i => {
  424. if (item.userId == i.userId) {
  425. isTrue = true
  426. }
  427. })
  428. })
  429. if (isTrue) {
  430. Toast('参与人员与缺席人员存在同一个人请修正!')
  431. this.falg = true
  432. }
  433. }
  434. },
  435. //表单提交校验
  436. submitHandler(type) {
  437. Dialog.confirm({
  438. title: '',
  439. message: `是否${type === 2 ? '提交' : '保存'}培训数据?`
  440. })
  441. .then(() => {
  442. if (type === 1) {
  443. //type 1保存2提交
  444. // this.beforSubmitV()
  445. this.submitHandlerConfirm(type)
  446. } else {
  447. this.beforSubmitV() //校验
  448. if (!this.falg) {
  449. //校验通过触发
  450. this.$refs.form.validate().then(() => {
  451. this.submitHandlerConfirm(type)
  452. })
  453. }
  454. }
  455. })
  456. .catch(() => {
  457. // on cancel
  458. })
  459. },
  460. // 表单提交
  461. submitHandlerConfirm(type) {
  462. let obj = JSON.parse(JSON.stringify(this.form))
  463. //动态拼接秒钟
  464. obj.trainingStartDateTime = obj.trainingStartDateTime ? obj.trainingStartDateTime + ':00' : ''
  465. obj.trainingEndDateTime = obj.trainingEndDateTime ? obj.trainingEndDateTime + ':00' : ''
  466. obj.imageList = obj.imageList.map(item => item.path).join(',')
  467. obj.taskUserList = []
  468. let list = this.studyList
  469. obj.fileList = []
  470. list.forEach(item => {
  471. obj.fileList.push(JSON.stringify(item))
  472. })
  473. obj.taskUserList.push(...this.userPeopleList, ...this.lackPeopleList)
  474. edittrainingInfo({
  475. id: this.trainingData.id,
  476. type: this.trainingData.type,
  477. submitType: type,
  478. ...obj
  479. }).then(res => {
  480. let { code, msg } = res
  481. if (code == 200) {
  482. Toast(`${type == 1 ? '保存' : '提交'}成功`)
  483. this.$router.go(-1)
  484. } else {
  485. Toast(msg)
  486. }
  487. })
  488. },
  489. dataList(list) {
  490. this.studyList.push(...list)
  491. this.studyList = uniqBy(this.studyList, 'name')
  492. },
  493. tagHandler(i) {
  494. let str = i.name.split('.')[1]
  495. if (str == 'png' || str == 'jpg' || str == 'jpeg' || str == 'pdf') {
  496. //当前是图片||PDF
  497. this.openFilePreview(i)
  498. } else {
  499. const filePath = `${process.env.NODE_ENV === 'development' ? '/dev' : window.origin}${i.url}`
  500. const tempLink = document.createElement('a')
  501. tempLink.style.display = 'none'
  502. tempLink.href = filePath
  503. tempLink.setAttribute('download', i.name)
  504. tempLink.setAttribute('target', '_blank')
  505. document.body.appendChild(tempLink)
  506. tempLink.click()
  507. document.body.removeChild(tempLink)
  508. }
  509. },
  510. //清除
  511. close(item) {
  512. this.studyList = this.studyList.filter(i => item.name != i.name)
  513. }
  514. }
  515. }
  516. </script>
  517. <style lang="scss" scoped>
  518. .mainItem {
  519. display: flex;
  520. font-size: 28px;
  521. align-items: center;
  522. padding: 34px;
  523. justify-content: space-between;
  524. background-color: #fff;
  525. flex-wrap: wrap;
  526. div {
  527. flex: 1;
  528. text-align: left;
  529. }
  530. p {
  531. }
  532. .label {
  533. width: 200px;
  534. flex: none;
  535. }
  536. .labelPeople {
  537. margin-bottom: 20px;
  538. }
  539. }
  540. .mainItemData {
  541. justify-content: end;
  542. }
  543. .bigbox {
  544. height: calc(100vh - 200px);
  545. overflow: scroll;
  546. }
  547. // .imglIST{
  548. // width: 100px;
  549. // height: 100px;
  550. // }
  551. .btns {
  552. position: fixed;
  553. bottom: -7%;
  554. height: 200px;
  555. width: 100%;
  556. background-color: #fff;
  557. // margin: 16px;
  558. display: flex;
  559. justify-content: space-around;
  560. .van-button {
  561. width: 300px;
  562. margin-left: 50px;
  563. }
  564. }
  565. .tagCls {
  566. margin-bottom: 20px;
  567. margin-left: 10px;
  568. }
  569. .deleteCls {
  570. color: #3095fb;
  571. text-decoration: dashed;
  572. margin-left: 30px;
  573. }
  574. </style>