addTraining.vue 14 KB

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