index.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. import { uuid10 } from '@/utils'
  2. import {
  3. getMonthlyReport,
  4. updateMonthlyReport,
  5. delMonthlyReport,
  6. getAllSubReportCatalog,
  7. getSubReport,
  8. // getReportDependence,
  9. getDeptArch,
  10. sendConfirm,
  11. returnReport,
  12. sendSubConfirm,
  13. publishReport,
  14. getSubReportInfo,
  15. updateSubReport,
  16. pullDataAgain
  17. } from '@/api/qualityMonthlyReport/edit'
  18. import { getAvaliableInfo } from '@/api/qualityMonthlyReport'
  19. import {
  20. reportDataBack,
  21. setReportData,
  22. setTabActive,
  23. setDeptArch,
  24. setIndexTitle,
  25. arrToObj,
  26. objToArr,
  27. setTableHeader
  28. } from './utils'
  29. import { message } from '@/utils/mesDebounce'
  30. import _ from 'lodash'
  31. export default {
  32. /* 月报编辑 */
  33. namespaced: true,
  34. state: {
  35. pageDate: null, // 页面的完整数据
  36. tabsList: [
  37. '上月问题跟进',
  38. '本月重点问题',
  39. '服务端详情',
  40. '客户端详情',
  41. '硬件详情',
  42. '本月优秀&持续改进'
  43. ],
  44. tabsActive: '', // 最上层tabs焦点
  45. tabPageData: null, // 单个标签页数据
  46. reportData: [], // 所有标签页数据
  47. editKeys: [], // 存放需要编辑的区域的 domKey(唯一)
  48. subTabsActive: [], // 当前页签中所有已切换的数据
  49. domKeys: [], // 记录所有元素区域的唯一标识
  50. selectEnum: [], // 部门数据
  51. userNames: [], // 人员数据
  52. subTitle: '新建月报',
  53. subReportName: '',
  54. subReportInfo: null, // 为回退时,当前页面为查看完整时,无法获取子月报数据情况设置
  55. offsetList: [],
  56. /**
  57. * 用户身份权限编号
  58. * 100 月报发起人
  59. * 50 确认人
  60. * 30 用户
  61. * 0 管理员
  62. */
  63. roleCode: 50, // 默认为用户
  64. reportList: [], // 默认为用户
  65. pageType: 'edit', // edit:(月报编辑和新建); readAll:(查看月报详情)
  66. loading: false,
  67. clientTypeList: [],
  68. // 单业务线编辑时,数据迁移
  69. saveAsTargetList: []
  70. // saveAsData: {
  71. // tableRow: '',
  72. // targetSubReportId: ''
  73. // }
  74. },
  75. mutations: {
  76. // 页面基础数据赋值
  77. INIT_PAGE_DATA(state, params) {
  78. const { pageType } = state
  79. if (pageType === 'read' || pageType === 'edit') return
  80. if (pageType === 'readAll') {
  81. // 设置tabs数据
  82. state.tabsList = state.tabsList.map((elm) => ({
  83. label: elm,
  84. name: `tab_${elm}`
  85. }))
  86. state.tabsActive = 'tab_上月问题跟进'
  87. return
  88. }
  89. state.pageDate = { ...params }
  90. delete state.pageDate.subReports
  91. // state.subTitle = state.pageDate.reportName
  92. const subReports = [...params.subReports]
  93. // 设置部门数据
  94. // state.selectEnum = [...params.dependence.deptArch.children]
  95. // setDeptArch(state.selectEnum)
  96. // 设置端数据
  97. if (params.dependence.clientType) {
  98. state.clientTypeList = [...params.dependence.clientType]
  99. }
  100. setDeptArch(state.clientTypeList)
  101. if (subReports.length) {
  102. state.tabsList = []
  103. subReports.forEach((elm, index) => {
  104. // 设置tabs数据
  105. state.tabsList.push({
  106. label: elm.reportName,
  107. reportName: elm.reportName,
  108. id: elm.id,
  109. name: `tab_${elm.id}`
  110. })
  111. })
  112. state.subReportInfo = _.cloneDeep(state.tabsList)
  113. // 设置tabs数据
  114. state.tabsActive = state.tabsList[0].name
  115. // table页签
  116. state.reportData = [...subReports]
  117. }
  118. },
  119. // 设置页面的是否为编辑页面
  120. SET_PAGE_TYPE(state, key) {
  121. state.pageType = key
  122. },
  123. // 单个tab页面数据初始化设置
  124. INIT_TAB_PAGE_DATA(state, tabsActive = '') {
  125. const { pageType } = state
  126. const setKey = (arr, depth) => {
  127. if (arr && arr.length) {
  128. arr.forEach((elm) => {
  129. elm.domKey = uuid10()
  130. elm.depth = depth
  131. if (arr.children && arr.children.length) {
  132. setKey(arr.children, depth + 1)
  133. }
  134. if (arr.content && arr.content.length) {
  135. setKey(arr.content, depth + 1)
  136. }
  137. })
  138. }
  139. }
  140. if (pageType === 'readAll') {
  141. state.tabsActive = tabsActive || state.tabsActive
  142. return
  143. }
  144. state.reportData.forEach((elm) => {
  145. setKey(elm.reportCatalog.children, 0)
  146. })
  147. // 从其他页面跳转过来
  148. const [tabPageData] = state.reportData.filter((elm) => {
  149. return (
  150. `${elm.id}` === setTabActive('tab_', tabsActive || state.tabsActive)
  151. )
  152. })
  153. if (tabsActive) {
  154. state.tabsActive = `tab_${tabsActive}`
  155. }
  156. // state.tabPageData = setReportData(tabPageData)
  157. const { newObj, domKeys } = setReportData(
  158. tabPageData
  159. ? tabPageData.reportCatalog
  160. : state.reportData[0].reportCatalog
  161. )
  162. state.tabPageData = newObj
  163. state.domKeys = domKeys
  164. },
  165. // 切换页面之后数据维护
  166. TAB_ACTIVE_CHANGE(state, tabsActive) {
  167. // 获取原来页签的选中对象的id
  168. const newTabsActive = setTabActive('tab_', tabsActive)
  169. // tabPageData => 后台源数据结构
  170. const oldTabPageData = reportDataBack({ ...state.tabPageData })
  171. // console.log(oldTabPageData)
  172. let newTabPageData = {}
  173. const reportData = state.reportData.map((elm) => {
  174. // 找出新页面的数据 && newTabsActive !== oldTabPageData.id
  175. if (newTabsActive === `${elm.id}`) {
  176. newTabPageData = { ...elm }
  177. }
  178. // 将上一个被选中的页签数据赋值给源数据(reportData)
  179. if (`${elm.reportName}` === `${oldTabPageData.title}`) {
  180. return {
  181. ...elm,
  182. reportCatalog: { ...oldTabPageData }
  183. }
  184. }
  185. return elm
  186. })
  187. state.reportData = [...reportData]
  188. // console.log(state.reportData)
  189. // 对新数据进行转换
  190. const { newObj, domKeys } = setReportData(
  191. newTabPageData.reportCatalog,
  192. 108
  193. )
  194. state.tabsActive = `tab_${newTabsActive}`
  195. state.tabPageData = newObj
  196. state.domKeys = domKeys
  197. // 页面恢复待编辑状态
  198. state.editKeys = []
  199. // 子页面页签切换,清空原来的tabs选中状态
  200. state.subTabsActive = []
  201. },
  202. // 添加行
  203. ADD_EDIT_KEYS(state, key) {
  204. state.editKeys.push(key)
  205. // const index = state.editKeys.indexOf(key)
  206. // if (index < 0) {
  207. // state.editKeys.push(key)
  208. // }
  209. },
  210. INIT_EDIT_KEYS(state) {
  211. state.editKeys = []
  212. },
  213. // 获取子页面所有距离顶部的集合基础信息
  214. GET_ALL_OFFSETTOP(state) {
  215. const getOffsetTop = (id) => {
  216. const dom = document.getElementById(id)
  217. if (!dom) return 0.9527
  218. return dom.getBoundingClientRect().top
  219. }
  220. const list = []
  221. state.domKeys.forEach((elm) => {
  222. const top = getOffsetTop(elm)
  223. if (top > 0 && top !== 0.9527) {
  224. list.push({
  225. domKey: elm,
  226. top: getOffsetTop(elm)
  227. })
  228. }
  229. })
  230. state.offsetList = [...list]
  231. },
  232. // 子页签数据切换
  233. SUB_TABS_ACTIVE(state, { key, oldKey }) {
  234. const index = state.subTabsActive.indexOf(oldKey)
  235. if (index < 0) {
  236. state.subTabsActive.push(key)
  237. } else {
  238. state.subTabsActive.splice(index, 1, key)
  239. }
  240. },
  241. // 删除行
  242. /**
  243. * @param params.domKey String 当前表格唯一标识
  244. * @param params.btnItem Object 点击按钮的基础数据
  245. * @param params.scope Object 当前行的数据
  246. * @constructor
  247. */
  248. DELETE_TABLE_LINE(state, params) {
  249. // const { btnItem, scope } = params
  250. //
  251. // const deepDeleteArray = (arr, key) =>{
  252. // arr.forEach(elm=>{
  253. // if(elm.content && elm.content.length){
  254. // elm.content.forEach(item )
  255. // }
  256. // })
  257. // }
  258. //
  259. // state.tabPageData.children.forEach((elm) => {
  260. // elm.content.forEach((item) => {
  261. // item.domKey = uuid10(4)
  262. // if (item.type === 'table') {
  263. // setTableHeader(item.tableHeaders)
  264. // item.tableRows = arrToObj(item.tableRows, item.tableHeaders)
  265. // }
  266. // })
  267. // })
  268. },
  269. // 切换tabs之后,重新生成左侧树
  270. CREATE_TREE_DATA(state) {},
  271. // 菜单添加子项setInit
  272. ADD_MENU_CHILDREN(state, params) {},
  273. // 删除某一条数据
  274. DELETE_ITEM(state, domKey) {
  275. const tabPageData = [...state.tabPageData.children]
  276. const delDom = (arr, key) => {
  277. if (arr && _.isArray(arr) && arr.length) {
  278. for (let i = 0; i < arr.length; i++) {
  279. if (arr[i].domKey === key) {
  280. arr.splice(i, 1)
  281. return
  282. }
  283. if (arr[i].content && arr[i].content.length) {
  284. delDom(arr[i].content, key)
  285. }
  286. if (arr[i].children && arr[i].children.length) {
  287. delDom(arr[i].children, key)
  288. }
  289. }
  290. }
  291. }
  292. delDom(tabPageData, domKey)
  293. state.tabPageData.children = [...tabPageData]
  294. },
  295. /**
  296. * 添加同级或者子集
  297. * @param state Object 数据源
  298. * @param domKey String 当前点击元素的唯一标识
  299. * @param params Object 要添加的内容
  300. * @param isSub Boolean 要添加的内容(true:添加子项|false:添加同级)
  301. * @constructor
  302. */
  303. ADD_ITEM(state, { domKey, params, isSub = false }) {
  304. if (domKey && params) {
  305. const tabPageData = [...state.tabPageData.children]
  306. const addItem = (arr, key) => {
  307. if (arr && _.isArray(arr) && arr.length) {
  308. for (let i = 0; i < arr.length; i++) {
  309. if (arr[i].domKey === key) {
  310. // 添加子项
  311. if (isSub) {
  312. // params.domIndexKey = arr[i].children
  313. arr[i].children = [...arr[i].children, { ...params }]
  314. }
  315. // 添加同级
  316. if (!isSub) {
  317. // params.domIndexKey = i + 1
  318. arr.splice(i + 1, 0, params)
  319. }
  320. return
  321. }
  322. if (arr[i].content && arr[i].content.length) {
  323. addItem(arr[i].content, key)
  324. }
  325. if (arr[i].children && arr[i].children.length) {
  326. addItem(arr[i].children, key)
  327. }
  328. }
  329. }
  330. }
  331. addItem(tabPageData, domKey)
  332. state.tabPageData.children = [...tabPageData]
  333. }
  334. },
  335. // 数据初始化
  336. INIT_STATE_DATA(state) {
  337. state.pageDate = null // 页面的完整数据
  338. state.tabsList = [
  339. '上月问题跟进',
  340. '本月重点问题',
  341. '服务端详情',
  342. '客户端详情',
  343. '硬件详情',
  344. '本月优秀&持续改进'
  345. ]
  346. state.tabsActive = '' // 最上层tabs焦点
  347. state.tabPageData = null // 单个标签页数据
  348. state.reportData = [] // 所有标签页数据
  349. state.editKeys = [] // 存放需要编辑的区域的 domKey(唯一)
  350. state.subTabsActive = [] // 当前页签中所有已切换的数据
  351. state.domKeys = [] // 记录所有元素区域的唯一标识
  352. state.selectEnum = [] // 部门数据
  353. state.userNames = [] // 人员数据
  354. state.subTitle = '新建月报'
  355. state.subReportName = ''
  356. state.subReportInfo = null // 为回退时,当前页面为查看完整时,无法获取子月报数据情况设置
  357. state.offsetList = []
  358. /**
  359. * 用户身份权限编号
  360. * 100 月报发起人
  361. * 50 确认人
  362. * 30 用户
  363. * 0 管理员
  364. */
  365. state.roleCode = 50 // 默认为用户
  366. state.reportList = [] // 默认为用户
  367. state.pageType = 'edit' // edit:(月报编辑和新建); readAll:(查看月报详情)
  368. state.loading = false
  369. state.clientTypeList = []
  370. // 单业务线编辑时,数据迁移
  371. state.saveAsTargetList = []
  372. },
  373. // tabPageData
  374. SET_TAB_PAGE_DATA(state, { data, id, tabsActive }) {
  375. // 对新数据进行转换
  376. const { newObj, domKeys } = setReportData(
  377. {
  378. children: _.cloneDeep(data)
  379. },
  380. 108
  381. )
  382. // state.tabPageData = {
  383. // children: _.cloneDeep(data)
  384. // }
  385. // console.log(365, state.tabPageData)
  386. state.tabPageData = newObj
  387. state.domKeys = domKeys
  388. // 页面恢复待编辑状态
  389. state.editKeys = []
  390. // 子页面页签切换,清空原来的tabs选中状态
  391. state.subTabsActive = []
  392. state.tabsActive = '' + tabsActive
  393. },
  394. // 设置人员数据,避免重复请求 userNames
  395. SET_USER_NAME(state, { key, value }) {
  396. if (!state.userNames.hasOwnProperty(key) && !state.userNames[key]) {
  397. state.userNames[key] = value
  398. }
  399. },
  400. // 获取部门数据
  401. SET_SELECT_ENUM(state, params) {
  402. console.log(params)
  403. state.selectEnum = params
  404. console.log(state.selectEnum)
  405. // setDeptArch(state.selectEnum)
  406. },
  407. // 标记为本月重点问题
  408. MARK_ISSUES(state, { cascaderValue, normalAreaName, multiplePeople }) {
  409. let isAdd = true
  410. const run = (arr) => {
  411. arr.forEach((elm) => {
  412. if (
  413. isAdd &&
  414. elm.title === '本月重点问题' &&
  415. elm.content &&
  416. elm.content.length
  417. ) {
  418. elm.content.forEach((item) => {
  419. if (item.type === 'Table') {
  420. const row = { analyticFeedback: null }
  421. item.tableHeaders.forEach((subItem) => {
  422. if (subItem.name === '归属团队') {
  423. row[subItem.headerKey] = cascaderValue
  424. }
  425. if (subItem.name === '问题') {
  426. row[subItem.headerKey] = normalAreaName
  427. }
  428. if (subItem.name === '责任人') {
  429. row[subItem.headerKey] = multiplePeople
  430. }
  431. })
  432. if (!item.tableRows) {
  433. item.tableRows = []
  434. }
  435. item.tableRows.push(row)
  436. isAdd = false
  437. }
  438. })
  439. }
  440. if (isAdd && elm.children && elm.children.length) {
  441. run(elm.children)
  442. }
  443. })
  444. }
  445. run(state.tabPageData.children)
  446. },
  447. // 设置右侧树的提示内容
  448. SET_HEADER_TITLE(state, { domKey, headerTitle }) {
  449. let isAdd = true
  450. const run = (arr) => {
  451. arr.forEach((elm) => {
  452. if (isAdd && elm.domKey === domKey) {
  453. elm.headerTitle = headerTitle
  454. isAdd = false
  455. }
  456. if (isAdd && elm.content && elm.content.length) {
  457. run(elm.content)
  458. }
  459. if (isAdd && elm.children && elm.children.length) {
  460. run(elm.children)
  461. }
  462. })
  463. }
  464. run(state.tabPageData.children)
  465. },
  466. // 获取用户月报操作区域权限
  467. GET_USER_PERMISSION(state, { roleCode, reportList }) {
  468. state.roleCode = roleCode
  469. state.reportList = reportList
  470. },
  471. // 设置月报子标题 // 设置月报子标题 parentId: 163
  472. // 设置月报标题
  473. // (state, name) {
  474. // state.subTitle = name
  475. // },
  476. SET_SUB_TITLE(state, { id, name }) {
  477. // commit('SET_SUB_TITLE', {
  478. // parentId: res.data.parentId,
  479. // name: res.data.reportName
  480. // })
  481. state.reportList &&
  482. state.reportList.forEach((elm) => {
  483. if (`${elm.id}` === `${id}`) {
  484. if (!name) {
  485. state.pageDate = {
  486. status: elm.status
  487. }
  488. }
  489. // console.log(elm.reportName)
  490. // 如果是
  491. if (elm.status === 10) {
  492. state.subTitle = `确认月报|${elm.reportName}`
  493. } else if (elm.status === 20) {
  494. state.subTitle = `发布月报|${elm.reportName}`
  495. } else if (elm.status === 30) {
  496. state.subTitle = `查看|${elm.reportName}`
  497. } else {
  498. state.subTitle = `${elm.statueStr}|${elm.reportName}`
  499. }
  500. }
  501. })
  502. // 如果是单业务线查看
  503. if (name) {
  504. state.subReportName = `${name}`
  505. state.subTitle += `|${name}`
  506. }
  507. },
  508. // 设置页面基础数据
  509. SET_PAGE_DATA(state, params) {
  510. state.pageDate = _.cloneDeep(params)
  511. delete state.pageDate.reportCatalog
  512. delete state.pageDate.reportContent
  513. },
  514. // 设置子月报数据
  515. SET_REPORT_INFO(state, params) {
  516. state.subReportInfo = params
  517. },
  518. // 设置页面状态
  519. SET_LOADING(state, isShow) {
  520. state.loading = isShow
  521. },
  522. // 设置 页面区域 下标
  523. SET_INDEX_TITLE(state) {
  524. state.tabPageData = setIndexTitle(state.tabPageData)
  525. },
  526. // 设置拉取之后的页面数据 tabPageData
  527. // 设置`端数据`
  528. SET_CLIENT_TYPE_LIST(state, list) {
  529. state.clientTypeList = list
  530. setDeptArch(state.clientTypeList)
  531. },
  532. /**
  533. * 数据另存为
  534. *
  535. */
  536. SAVE_AS(state, { tableHeaders, tableRows, subReportid, key = 'only' }) {
  537. // setTableHeader(data.tableHeaders)
  538. const rowData = objToArr(
  539. [tableRows],
  540. tableHeaders
  541. )
  542. const find = (arr) => {
  543. arr.forEach(elm => {
  544. if (elm.title === '线上问题') {
  545. // console.log(532, elm, rowData)
  546. // console.log(elm.content[0].tableRows, rowData)
  547. elm.content[0].tableRows.push(rowData[0])
  548. }
  549. if (elm.children && elm.children.length) {
  550. find(elm.children)
  551. }
  552. })
  553. }
  554. // 多业务线转移
  555. if (state.pageType === 'editAll') {
  556. for (let i = state.reportData.length - 1; i >= 0; i--) {
  557. const elm = state.reportData[i]
  558. if (elm.id === subReportid) {
  559. find(elm.reportCatalog.children)
  560. }
  561. }
  562. } else {
  563. // 单业务线转移
  564. // 判断数据是否存在,不存在,就插入
  565. if (state.saveAsTargetList.filter(elm => elm.targetSubReportId === subReportid).length) {
  566. state.saveAsTargetList.forEach(elm => {
  567. if (elm.targetSubReportId === subReportid) {
  568. if (!elm.tableRow) {
  569. elm.tableRow = []
  570. }
  571. elm.tableRow.push(rowData[0])
  572. }
  573. })
  574. } else {
  575. state.saveAsTargetList.push({
  576. targetSubReportId: subReportid,
  577. tableRow: [rowData[0]]
  578. })
  579. }
  580. }
  581. }
  582. },
  583. actions: {
  584. // 月报数据获取
  585. async initPageData(
  586. { commit, state, dispatch },
  587. { id, subReportId, subActive }
  588. ) {
  589. dispatch('setSubReportInfo', id)
  590. const { pageType } = state
  591. if (
  592. pageType === 'readAll' ||
  593. pageType === 'read' ||
  594. pageType === 'edit'
  595. ) {
  596. commit('INIT_PAGE_DATA')
  597. dispatch('getSubReportData', {
  598. id,
  599. subReportId,
  600. tabsActive: `tab_${subActive || '上月问题跟进'}`
  601. })
  602. } else {
  603. const res = await getMonthlyReport(id)
  604. // 设置月报子标题
  605. commit('SET_SUB_TITLE', {
  606. id: id
  607. })
  608. if (res.code === 200 && res.data) {
  609. commit('INIT_PAGE_DATA', { ...res.data })
  610. commit('INIT_TAB_PAGE_DATA', subActive && `tab_${subActive}`)
  611. }
  612. }
  613. },
  614. // 页面切换 TAB_ACTIVE_CHANGE
  615. tabActiveChange({ commit, state, dispatch }, { id, tabsActive }) {
  616. const { pageType } = state
  617. if (pageType === 'editAll') {
  618. return commit('TAB_ACTIVE_CHANGE', tabsActive)
  619. }
  620. if (pageType === 'readAll') {
  621. dispatch('getSubReportData', { id, tabsActive })
  622. }
  623. },
  624. // 获取查看月报数据
  625. async getSubReportData({ commit, state }, { id, subReportId, tabsActive }) {
  626. const { pageType } = state
  627. let params = {}
  628. const method =
  629. pageType === 'readAll' ? getAllSubReportCatalog : getSubReport
  630. if (pageType === 'read' || pageType === 'edit') {
  631. params = {
  632. subReportId
  633. }
  634. }
  635. if (pageType === 'readAll') {
  636. // state.pageDate = {
  637. // status: 10
  638. // }
  639. params = {
  640. reportId: id,
  641. catalogTitle: setTabActive('tab_', tabsActive)
  642. }
  643. }
  644. const res = await method(params)
  645. if (res.code === 200) {
  646. // 单个月报与完整月报数据梳理
  647. if (pageType === 'read' || pageType === 'edit') {
  648. commit('SET_CLIENT_TYPE_LIST', res.data.dependence.clientType)
  649. // commit('SET_SELECT_ENUM', res.data.dependence.deptArch.children)
  650. commit('SET_PAGE_DATA', res.data)
  651. }
  652. console.log(res)
  653. if (pageType === 'readAll' && params.catalogTitle.search(/服务端详情|客户端详情/) > -1) {
  654. res.data.splice(0, 0, { depth: 1, fromUser: false, hiddenAncestor: null, isVisible: true, subTitles: null, title: '整体概览', type: 'Head1', content: [{ type: 'overallOverviewo' }] })
  655. console.log(params)
  656. }
  657. commit('SET_TAB_PAGE_DATA', {
  658. data:
  659. pageType === 'readAll' ? res.data : res.data.reportCatalog.children,
  660. id,
  661. tabsActive
  662. })
  663. // 设置月报子标题
  664. setTimeout(() => {
  665. commit('SET_SUB_TITLE', {
  666. id: pageType.search(/All/) > -1 ? `${id}` : `${res.data.parentId}`,
  667. name: pageType.search(/All/) > -1 ? '' : res.data.reportName
  668. })
  669. }, 700)
  670. }
  671. },
  672. // 子月报更新
  673. async upDateSubReport({ state }, callback) {
  674. const params = _.cloneDeep(state.pageDate)
  675. params.reportCatalog = {
  676. children: _.cloneDeep(state.tabPageData.children),
  677. content: [],
  678. depth: 0,
  679. fromUser: false,
  680. hiddenAncestor: null,
  681. isVisible: true,
  682. subTitles: null,
  683. title: params.reportName,
  684. type: 'Tag'
  685. }
  686. params.reportCatalog = reportDataBack(params.reportCatalog)
  687. if (state.saveAsTargetList.length) {
  688. params.saveAsTargetList = _.cloneDeep(state.saveAsTargetList)
  689. }
  690. params.dependence = null
  691. const res = await updateSubReport(params)
  692. if (res.code === 200) {
  693. callback()
  694. }
  695. },
  696. // 月报更新
  697. async upDateReport({ dispatch, state }, callback) {
  698. const params = _.cloneDeep(state.pageDate)
  699. const tabPageData = _.cloneDeep(state.tabPageData)
  700. const tabsActive = setTabActive('tab_', state.tabsActive)
  701. params.subReports = state.reportData.map((elm) => {
  702. // 将上一个被选中的页签数据赋值给源数据(reportData)
  703. if (`${elm.id}` === tabsActive) {
  704. return {
  705. ...elm,
  706. dependence: null,
  707. reportCatalog: { ...reportDataBack({ ...tabPageData }) }
  708. }
  709. }
  710. return elm
  711. })
  712. // 转换数据结构
  713. const res = await updateMonthlyReport(params)
  714. if (res.code === 200) {
  715. callback()
  716. }
  717. },
  718. // 获取部门数据
  719. async setSelectEnum({ commit }, reportId) {
  720. const depth = JSON.parse(window.localStorage.getItem('depth'))
  721. console.log(depth)
  722. if (!depth) {
  723. const res = await getDeptArch({ reportId })
  724. if (res.code === 200) {
  725. window.localStorage.setItem('depth', JSON.stringify(res.data.children))
  726. commit('SET_SELECT_ENUM', res.data.children)
  727. }
  728. } else {
  729. commit('SET_SELECT_ENUM', depth)
  730. }
  731. },
  732. // 删除月报
  733. async deleteReport(
  734. { commit, state, context },
  735. { key, callback, isMsg = true }
  736. ) {
  737. const res = await delMonthlyReport(state.pageDate.id)
  738. if (res.code === 200) {
  739. if (isMsg) {
  740. message.success('删除成功!')
  741. }
  742. callback && callback()
  743. }
  744. },
  745. // 月报发送确认
  746. async sendReport({ commit, state, context }, { id, callback }) {
  747. const params = _.cloneDeep(state.pageDate)
  748. const tabPageData = _.cloneDeep(state.tabPageData)
  749. const tabsActive = setTabActive('tab_', state.tabsActive)
  750. params.subReports = state.reportData.map((elm) => {
  751. // 将上一个被选中的页签数据赋值给源数据(reportData)
  752. if (`${elm.id}` === tabsActive) {
  753. return {
  754. ...elm,
  755. dependence: null,
  756. reportCatalog: { ...reportDataBack({ ...tabPageData }) }
  757. }
  758. }
  759. return elm
  760. })
  761. const res = await sendConfirm({
  762. ...params,
  763. id
  764. })
  765. if (res.code === 200) {
  766. message.success('发送成功!')
  767. callback()
  768. }
  769. },
  770. // 月报发布
  771. async publishAllReport({ commit, state, context }, { id, callback }) {
  772. const res = await publishReport({
  773. id
  774. })
  775. if (res.code === 200) {
  776. message.success('发布成功!')
  777. callback()
  778. }
  779. },
  780. // 月报确认
  781. async confirmReport({ state }, { id, callback }) {
  782. const res = await sendSubConfirm({
  783. subReportId: id
  784. })
  785. if (res.code === 200) {
  786. callback()
  787. }
  788. },
  789. // 月报回退
  790. async returnReport({ commit, state, context }, { data, callback }) {
  791. const res = await returnReport(data)
  792. if (res.code === 200) {
  793. callback()
  794. }
  795. },
  796. // 获取用户月报操作区域权限
  797. async getUserPermission({ commit }) {
  798. const res = await getAvaliableInfo()
  799. if (res.code === 200) {
  800. commit('GET_USER_PERMISSION', res.data)
  801. }
  802. },
  803. // 获取子月报列表数据
  804. async setSubReportInfo({ commit }, id) {
  805. const res = await getSubReportInfo(id)
  806. if (res.code === 200) {
  807. commit('SET_REPORT_INFO', res.data)
  808. }
  809. },
  810. // 重新拉取数据
  811. async refreshReport(
  812. { commit, state },
  813. { domKey, title, subReportId, callback }
  814. ) {
  815. const tabPageData = _.cloneDeep(state.tabPageData)
  816. // console.log('refreshReport', domKey, title)
  817. const [tabKey, subTabKey] = state.subTabsActive
  818. const tabDataObj = {
  819. tabKey: '',
  820. subTabKey: ''
  821. }
  822. const setValue = (item, key, value) => {
  823. if (item.domKey === value) {
  824. tabDataObj[key] = item
  825. }
  826. }
  827. const find = (arr) => {
  828. arr &&
  829. arr.length &&
  830. arr.forEach((elm) => {
  831. setValue(elm, 'tabKey', tabKey)
  832. setValue(elm, 'subTabKey', subTabKey)
  833. if (elm.content && elm.content.length) {
  834. elm.content.forEach((item) => {
  835. setValue(elm, 'tabKey', tabKey)
  836. setValue(elm, 'subTabKey', subTabKey)
  837. })
  838. }
  839. if (elm.children && elm.children.length) {
  840. find(elm.children)
  841. }
  842. })
  843. }
  844. const params = {
  845. subReportId: '',
  846. catalogTitle: title,
  847. isServer: false,
  848. clientType: ''
  849. }
  850. if (title !== '上月问题跟进') {
  851. find(tabPageData.children)
  852. if (tabDataObj.tabKey.title === '服务端') {
  853. params.isServer = true
  854. }
  855. if (!params.isServer) {
  856. params.clientType = tabDataObj.subTabKey.title
  857. }
  858. }
  859. if (state.pageType.search(/All/) > -1) {
  860. // console.log(state, setTabActive('tab_', state.tabsActive))
  861. params.subReportId = setTabActive('tab_', state.tabsActive)
  862. }
  863. if (state.pageType === 'edit') {
  864. params.subReportId = subReportId
  865. }
  866. // console.log(params)
  867. /**
  868. * 线上问题、
  869. */
  870. const res = await pullDataAgain(params)
  871. if (title !== '上月问题跟进' && title !== '线下缺陷' && title !== '线上问题') {
  872. if (res.data.type.search(/Table|TableAndRichText/) > -1) {
  873. setTableHeader(res.data.tableHeaders)
  874. res.data.tableRows = arrToObj(
  875. res.data.tableRows,
  876. res.data.tableHeaders
  877. )
  878. }
  879. }
  880. if (title.search(/上月问题跟进|发布&回滚|线上问题/) > -1) {
  881. setTableHeader(res.data.content[0].tableHeaders)
  882. res.data.content[0].tableRows = arrToObj(
  883. res.data.content[0].tableRows,
  884. res.data.content[0].tableHeaders
  885. )
  886. }
  887. const setDomData = (arr) => {
  888. arr &&
  889. arr.length &&
  890. arr.forEach((elm) => {
  891. if (elm.domKey === domKey) {
  892. // console.log(elm, res.data)
  893. if (title.search(/上月问题跟进|发布&回滚|线上问题|线上问题/) > -1) {
  894. elm.content = [{ ...res.data.content[0] }]
  895. } else if (title.search(/线下缺陷/) > -1) {
  896. elm.content = [{ ...res.data.content[0] }]
  897. elm.subTitles = [...res.data.subTitles]
  898. } else {
  899. elm.content = [{ ...res.data }]
  900. }
  901. }
  902. if (elm.content && elm.content.length) {
  903. elm.content.forEach((item) => {
  904. if (title.search(/上月问题跟进|发布&回滚|线上问题/) > -1) {
  905. item.content = [{ ...res.data.content[0] }]
  906. } else {
  907. item.content = [{ ...res.data }]
  908. }
  909. })
  910. }
  911. if (elm.children && elm.children.length) {
  912. setDomData(elm.children)
  913. }
  914. })
  915. }
  916. setDomData(tabPageData.children)
  917. state.tabPageData = tabPageData
  918. // console.log(res.data, tabPageData)
  919. if (res.code === 200) {
  920. callback && callback()
  921. }
  922. // setTimeout(() => {
  923. // callback && callback()
  924. // }, 5000)
  925. }
  926. }
  927. }