addTraining.vue 15 KB

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