addRehearsalTask.vue 16 KB

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