index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <div class="editPublishTask">
  3. <section class="main-section pubconfig">
  4. <div v-if="showEmpty">
  5. <header>
  6. <headTitle title="checklist" />
  7. </header>
  8. <div class="empty">
  9. 未设置 <span class="createBtn" @click="addAction">点击添加</span>
  10. </div>
  11. </div>
  12. <div v-else>
  13. <header>
  14. <headTitle title="checklist" :open-edit="openEdit" @editHandle="editHandle" />
  15. </header>
  16. <div class="wrap">
  17. <redTipword title="关联任务" :isedit="edit" />
  18. <multipleSelect placeholder="🔍 请输入任务名称或ID" :isedit="edit" :data="data.tasks" :task-id="taskId" @change="changeTask" />
  19. <div v-if="edit" style="margin-top: 30px">
  20. <redTipword title="选择checklist列表" :isedit="edit" />
  21. <checkboxList :selected-list="data.selectedBizTemplateIds" :data="temList" @change="updateSelectedTemHandle" />
  22. </div>
  23. </div>
  24. <div class="moduleList wrap">
  25. <redTipword v-if="!edit" title="检查项" :isedit="edit" />
  26. <div v-for="(item, index) in data.templates" :key="item.id" class="item">
  27. <div v-if="item.content.indexOf('s') > -1">
  28. <p :id="`s${item.id}`" class="title">
  29. <el-checkbox v-if="!edit" v-model="item.isCheck" :label="item.name" @change="updateCheckItemHandle(item.isCheck, item)">{{ item.name }}</el-checkbox>
  30. <span v-else>{{ item.name }}</span>
  31. </p>
  32. <onlineCheckList
  33. :module-id="item.id"
  34. :isedit="edit"
  35. :data="item.onlineModule"
  36. :task-id="taskId"
  37. @changeSelectedHandle="changeOnlineSelectedHandle"
  38. @changeRow="changeOnlineModuleRow"
  39. @onChangeModuleName="(val, subIdx) => onChangeModuleName(val, subIdx, index)"
  40. />
  41. </div>
  42. <div v-else>
  43. <p :id="`s${item.id}`" class="title">
  44. <el-checkbox v-if="!edit" v-model="item.isCheck" :label="item.name" @change="updateCheckItemHandle(item)">{{ item.name }}</el-checkbox>
  45. <span v-else>{{ item.name }}</span>
  46. </p>
  47. <normal-area
  48. v-if="edit"
  49. :id="'tem'+item.id"
  50. :value.sync="item.content"
  51. :empty-text="'点击'"
  52. :input-button="'修改模板'"
  53. :styles="{ padding: '0 0px 20px 0px', width: '690px' }"
  54. />
  55. <div v-else v-html="item.content" />
  56. </div>
  57. </div>
  58. </div>
  59. <div v-if="edit" class="control">
  60. <el-button size="small" @click="cancel()">取消</el-button>
  61. <el-button type="primary" size="small" @click="saveHandle()">
  62. 保存
  63. </el-button>
  64. </div>
  65. </div>
  66. </section>
  67. <div v-if="!edit">
  68. <section class="main-section">
  69. <div>
  70. <headTitle title="动态" />
  71. </div>
  72. <actionDynamic :comments="commentlist" @addComment="createCommentHandle" />
  73. </section>
  74. <div v-if="!showEmpty" class="step">
  75. <step :data="data.templates" :type-list="data.templates" @goto="scrollToHandle" />
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. const _ = require('lodash')
  82. import redTipword from '@/components/redTipTitle'
  83. import headTitle from '@/components/headTitle'
  84. import multipleSelect from './components/multipleSelect'
  85. import checkboxList from './components/checkboxList'
  86. import onlineCheckList from './components/onlineCheckList'
  87. import actionDynamic from '@/components/actionDynamic'
  88. import step from './components/step'
  89. // 富文本
  90. // import textArea from '@/components/input/textArea'
  91. import normalArea from '@/components/input/normalArea' // 富文本
  92. import 'tinymce/plugins/table'// 插入表格插件
  93. import store from '@/store'
  94. import {
  95. getCheckListBytask,
  96. getBizBindTemList,
  97. updateChecklist,
  98. createChecklist,
  99. updateTemplateCheckStatus,
  100. getCommentList,
  101. createComment
  102. } from '@/api/publishTask'
  103. export default {
  104. components: {
  105. redTipword,
  106. multipleSelect,
  107. checkboxList,
  108. onlineCheckList,
  109. normalArea,
  110. headTitle,
  111. actionDynamic,
  112. step
  113. },
  114. props: {
  115. taskId: {
  116. type: Number,
  117. required: true,
  118. default: -1
  119. },
  120. taskName: {
  121. type: String,
  122. required: true,
  123. default: ''
  124. },
  125. userNames: {
  126. type: String,
  127. required: true,
  128. default: ''
  129. },
  130. userInformation: {
  131. type: String,
  132. required: true,
  133. default: ''
  134. }
  135. },
  136. data() {
  137. return {
  138. description: '<p style="color:red;">123</p>',
  139. edit: false, // 是否是编辑状态
  140. showEmpty: true,
  141. openEdit: true,
  142. data: {},
  143. temList: [],
  144. commentlist: [] // 评价列表
  145. }
  146. },
  147. mounted() {
  148. // 获取模板列表
  149. this.getBizBindTemList()
  150. // 获取checklist详情
  151. this.getList()
  152. // 获取评论列表
  153. this.getCommentList()
  154. },
  155. methods: {
  156. // 获取checklist详情
  157. async getList() {
  158. console.log(this.taskId)
  159. if (this.taskId) {
  160. const res = await getCheckListBytask({ taskId: this.taskId })
  161. // res.data = null
  162. if (res.data) {
  163. // 如果绑定过
  164. this.showEmpty = false
  165. this.data = res.data
  166. } else {
  167. this.showEmpty = true
  168. }
  169. }
  170. },
  171. // 获取业务线下绑定的可以选checklist列表
  172. async getBizBindTemList() {
  173. const { bizId = null } = store.state.global || {}
  174. const res = await getBizBindTemList({ name: '', bizId, belongType: 2 })
  175. this.temList = res.data
  176. },
  177. async getCommentList() {
  178. const res = await getCommentList({ type: 5, joinId: this.taskId })
  179. this.commentList = res.data
  180. if (res.code === 200) {
  181. this.comments = res.data
  182. }
  183. },
  184. // 添加评论
  185. async createCommentHandle(content, callback) {
  186. const commentInfo = {
  187. joinId: this.taskId,
  188. content,
  189. type: 5,
  190. fatherId: 0,
  191. name: this.userNames,
  192. email: this.userInformation
  193. }
  194. const user = { name: this.userNames, ename: this.userInformation, id: '' }
  195. const res = await createComment({ commentInfo, user })
  196. if (res.code === 200) {
  197. this.$message({ message: '评论成功', type: 'success', duration: 1000, offset: 150 })
  198. this.getCommentList()
  199. callback()
  200. } else {
  201. this.$message.warning(res.msg)
  202. }
  203. },
  204. // 添加或者删除线上模板的模版名
  205. changeOnlineSelectedHandle(id, name, value, type) {
  206. /**
  207. * id: 模块id
  208. * name: 线上模块中哪个模块下的模块名称
  209. * value: 模块名
  210. * type: 是添加还是删除
  211. **/
  212. // const tem = this.data.templates
  213. this.data.templates.map(t => {
  214. if (t.id === id) {
  215. if (type === 'del') {
  216. t.onlineModule.onlineOrder = t.onlineModule.onlineOrder.filter(g => g !== value)
  217. t.onlineModule.tableContent.map(t => {
  218. if (t.module === name) {
  219. t.moduleNames = t.moduleNames.filter(g => g !== value)
  220. }
  221. })
  222. } else if (!t.onlineModule.onlineOrder.includes(value)) {
  223. t.onlineModule.onlineOrder.push(value)
  224. t.onlineModule.tableContent.map(t => {
  225. if (t.module === name) {
  226. t.moduleNames.push(value)
  227. }
  228. })
  229. } else {
  230. console.log('已经添加过该模块名称')
  231. }
  232. }
  233. })
  234. },
  235. changeOnlineModuleRow(type, mId, index) {
  236. console.log(type, mId, index, this.data.templates)
  237. this.data.templates.map(t => {
  238. if (t.id === mId) {
  239. if (type === 'del') {
  240. t.onlineModule.tableContent.splice(index, 1)
  241. } else {
  242. t.onlineModule.tableContent.splice(index + 1, 0, {})
  243. }
  244. }
  245. })
  246. },
  247. // 保存
  248. async saveHandle() {
  249. if (this.data.tasks.length < 1) {
  250. this.$message({
  251. message: '请关联一个任务',
  252. type: 'error'
  253. })
  254. return
  255. }
  256. let res = null
  257. if (this.data.id) {
  258. res = await updateChecklist(this.data)
  259. } else {
  260. res = await createChecklist(this.data)
  261. }
  262. if (res.code === 200) {
  263. this.edit = false
  264. this.openEdit = true
  265. this.$message({
  266. message: '保存成功',
  267. type: 'success'
  268. })
  269. }
  270. },
  271. // 取消
  272. cancel() {
  273. this.edit = false
  274. this.openEdit = true
  275. this.data = this.copyData
  276. if (!this.data || JSON.stringify(this.data) === '{}') {
  277. this.showEmpty = true
  278. }
  279. },
  280. // 点击添加
  281. addAction() {
  282. // 复制一份数据,以便取消时复原
  283. this.copyData = this.data
  284. // 编辑按钮隐藏
  285. this.openEdit = false
  286. // 编辑状态打开
  287. this.edit = true
  288. // 是否显示空状态
  289. this.showEmpty = false
  290. this.data = {
  291. selectedBizTemplateIds: [],
  292. templates: [],
  293. tasks: [{
  294. id: this.taskId,
  295. name: this.taskName
  296. }]
  297. }
  298. this.checkAllTem()
  299. },
  300. // 编辑
  301. editHandle() {
  302. // 复制一份数据,以便取消时复原
  303. this.copyData = this.data
  304. // 编辑状态打开
  305. this.edit = true
  306. // 编辑按钮隐藏
  307. this.openEdit = false
  308. this.checkAllTem()
  309. },
  310. // 添加和编辑checklist时 如果没有选择模版默认全选。
  311. checkAllTem() {
  312. const { selectedBizTemplateIds } = this.data
  313. if (!selectedBizTemplateIds || selectedBizTemplateIds.length < 1) {
  314. this.temList.map(t => {
  315. this.data.selectedBizTemplateIds.push(t.id)
  316. this.data.templates.push(t)
  317. })
  318. }
  319. },
  320. // 修改checklist绑定模版列表
  321. updateSelectedTemHandle(checkedIds) {
  322. console.log(checkedIds)
  323. const selectedBizTemplateIds = []
  324. const templates = []
  325. checkedIds.map(checkedId => {
  326. this.temList.map(t => {
  327. if (t.id === checkedId) {
  328. selectedBizTemplateIds.push(t.id)
  329. templates.push(t)
  330. }
  331. })
  332. })
  333. this.data = { ...this.data, templates, selectedBizTemplateIds }
  334. },
  335. // 锚点
  336. scrollToHandle(targe) {
  337. const anchorH = document.getElementById(targe).offsetTop
  338. const container = document.getElementsByClassName('main-wrapper')[0]
  339. container.scrollTop = anchorH - 20
  340. },
  341. // 解绑删除任务
  342. changeTask(task, type) {
  343. let hasTask = false
  344. let tasks = []
  345. this.data.tasks.map(g => {
  346. if (g.id === task.id) {
  347. hasTask = true
  348. }
  349. })
  350. if (type === 'del') {
  351. tasks = this.data.tasks.filter(t => t.id !== task.id)
  352. } else if (!hasTask) {
  353. tasks = [...this.data.tasks, task]
  354. } else {
  355. console.log('已经添加过该任务')
  356. return
  357. }
  358. this.data = { ...this.data, tasks }
  359. },
  360. // 更新检查项到数据库
  361. async updateCheckItemHandle(item) {
  362. console.log(item)
  363. const { id: templateId, isCheck } = item
  364. const res = await updateTemplateCheckStatus({ templateId, isCheck })
  365. if (res.code === 200) {
  366. this.$message({
  367. message: '检查项状态更新成功',
  368. type: 'success'
  369. })
  370. }
  371. },
  372. // 修改线上问题模块
  373. onChangeModuleName: _.debounce(function(val, subIdx, index) {
  374. console.log(val, subIdx, index, this.data)
  375. this.data.templates[index].onlineModule.tableContent[subIdx].module = val
  376. console.log(this.data)
  377. })
  378. }
  379. }
  380. </script>
  381. <style scoped lang="scss">
  382. @import '@/styles/detail-pages.scss';
  383. .editPublishTask {
  384. min-height: 400px;
  385. overflow-y: auto;
  386. padding-bottom: 20px;
  387. .step {
  388. position: fixed;
  389. top: 200px;
  390. right:100px;
  391. }
  392. .pubconfig {
  393. .control {
  394. padding: 20px 0px 20px 690px;
  395. }
  396. }
  397. .main-section {
  398. @include main-section;
  399. }
  400. .wrap{
  401. padding: 0 40px;
  402. }
  403. .moduleList {
  404. margin-top: 40px;
  405. padding-bottom: 16px;
  406. .title {
  407. font-weight: 400;
  408. color: #444444;
  409. font-size: 14px;
  410. margin-bottom: 16px;
  411. margin-top: 40px;
  412. &:first-child {
  413. margin-top: 0px;
  414. }
  415. }
  416. }
  417. }
  418. .empty {
  419. padding: 0px 30px 40px 30px;
  420. color: #444;
  421. font-size: 14px;
  422. .createBtn {
  423. color: #409EFF;
  424. margin-left: 5px;
  425. cursor: pointer;
  426. }
  427. }
  428. .main-title {
  429. @include main-title;
  430. }
  431. </style>