addTraining.vue 15 KB

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