index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <div class="project-gstc-gantt">
  3. <GanttView :lists="lists" :menuWidth="windowMax768 ? 180 : 260" :itemWidth="80" @on-change="updateTime" @on-click="clickItem"/>
  4. <Dropdown class="project-gstc-dropdown-filtr" :style="windowMax768?{left:'142px'}:{}" @on-click="tapProject">
  5. <Icon class="project-gstc-dropdown-icon" :class="{filtr:filtrProjectId>0}" type="md-funnel" />
  6. <DropdownMenu slot="list">
  7. <DropdownItem :name="0" :class="{'dropdown-active':filtrProjectId==0}">{{$L('全部')}}</DropdownItem>
  8. <DropdownItem v-for="(item, index) in projectLabel" :key="index" :name="item.id" :class="{'dropdown-active':filtrProjectId==item.id}">{{item.title}} ({{item.taskLists.length}})</DropdownItem>
  9. </DropdownMenu>
  10. </Dropdown>
  11. <div class="project-gstc-close" @click="$emit('on-close')"><Icon type="md-close" /></div>
  12. <div class="project-gstc-edit" :class="{info:editShowInfo, visible:editData.length > 0}">
  13. <div class="project-gstc-edit-info">
  14. <Table class="tableFill" size="small" max-height="600" :columns="editColumns" :data="editData"></Table>
  15. <div class="project-gstc-edit-btns">
  16. <Button :loading="editLoad > 0" size="small" type="text" @click="editSubmit(false)">{{$L('取消')}}</Button>
  17. <Button :loading="editLoad > 0" size="small" type="primary" @click="editSubmit(true)">{{$L('保存')}}</Button>
  18. <Icon type="md-arrow-dropright" class="zoom" @click="editShowInfo=false"/>
  19. </div>
  20. </div>
  21. <div class="project-gstc-edit-small">
  22. <div class="project-gstc-edit-text" @click="editShowInfo=true">{{$L('未保存计划时间')}}: {{editData.length}}</div>
  23. <Button :loading="editLoad > 0" size="small" type="text" @click="editSubmit(false)">{{$L('取消')}}</Button>
  24. <Button :loading="editLoad > 0" size="small" type="primary" @click="editSubmit(true)">{{$L('保存')}}</Button>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <style lang="scss">
  30. .project-gstc-gantt {
  31. position: absolute;
  32. top: 15px;
  33. left: 15px;
  34. right: 15px;
  35. bottom: 15px;
  36. z-index: 1;
  37. transform: translateZ(0);
  38. background-color: #fdfdfd;
  39. border-radius: 3px;
  40. overflow: hidden;
  41. .project-gstc-dropdown-filtr {
  42. position: absolute;
  43. top: 38px;
  44. left: 222px;
  45. .project-gstc-dropdown-icon {
  46. cursor: pointer;
  47. color: #999;
  48. font-size: 20px;
  49. &.filtr {
  50. color: #058ce4;
  51. }
  52. }
  53. }
  54. .project-gstc-close {
  55. position: absolute;
  56. top: 8px;
  57. left: 12px;
  58. cursor: pointer;
  59. &:hover {
  60. i {
  61. transform: scale(1) rotate(45deg);
  62. }
  63. }
  64. i {
  65. color: #666666;
  66. font-size: 28px;
  67. transform: scale(0.92);
  68. transition: all .2s;
  69. }
  70. }
  71. .project-gstc-edit {
  72. position: absolute;
  73. bottom: 6px;
  74. right: 6px;
  75. background: #ffffff;
  76. border-radius: 4px;
  77. opacity: 0;
  78. transform: translate(120%, 0);
  79. transition: all 0.2s;
  80. &.visible {
  81. opacity: 1;
  82. transform: translate(0, 0);
  83. }
  84. &.info {
  85. .project-gstc-edit-info {
  86. display: block;
  87. }
  88. .project-gstc-edit-small {
  89. display: none;
  90. }
  91. }
  92. .project-gstc-edit-info {
  93. display: none;
  94. border: 1px solid #e4e4e4;
  95. background: #ffffff;
  96. padding: 6px;
  97. border-radius: 4px;
  98. width: 500px;
  99. .project-gstc-edit-btns {
  100. margin: 12px 6px 4px;
  101. display: flex;
  102. align-items: center;
  103. justify-content: flex-end;
  104. .ivu-btn {
  105. margin-right: 8px;
  106. font-size: 13px;
  107. }
  108. .zoom {
  109. font-size: 20px;
  110. color: #444444;
  111. cursor: pointer;
  112. &:hover {
  113. color: #57a3f3;
  114. }
  115. }
  116. }
  117. }
  118. .project-gstc-edit-small {
  119. border: 1px solid #e4e4e4;
  120. background: #ffffff;
  121. padding: 6px 12px;
  122. display: flex;
  123. align-items: center;
  124. .project-gstc-edit-text {
  125. cursor: pointer;
  126. text-decoration: underline;
  127. color: #444444;
  128. margin-right: 8px;
  129. &:hover {
  130. color: #57a3f3;
  131. }
  132. }
  133. .ivu-btn {
  134. margin-left: 4px;
  135. font-size: 13px;
  136. }
  137. }
  138. }
  139. }
  140. </style>
  141. <script>
  142. import GanttView from "../../gantt/index";
  143. /**
  144. * 甘特图
  145. */
  146. export default {
  147. name: 'ProjectGantt',
  148. components: {GanttView },
  149. props: {
  150. projectLabel: {
  151. default: []
  152. },
  153. },
  154. data () {
  155. return {
  156. loadFinish: false,
  157. lists: [],
  158. editColumns: [],
  159. editData: [],
  160. editShowInfo: false,
  161. editLoad: 0,
  162. filtrProjectId: 0,
  163. }
  164. },
  165. mounted() {
  166. this.editColumns = [
  167. {
  168. title: this.$L('任务名称'),
  169. key: 'label',
  170. minWidth: 150,
  171. ellipsis: true,
  172. }, {
  173. title: this.$L('原计划时间'),
  174. minWidth: 135,
  175. align: 'center',
  176. render: (h, params) => {
  177. if (params.row.notime === true) {
  178. return h('span', '-');
  179. }
  180. return h('div', {
  181. style: {},
  182. }, [
  183. h('div', $A.formatDate('Y-m-d H:i', Math.round(params.row.backTime.start / 1000))),
  184. h('div', $A.formatDate('Y-m-d H:i', Math.round(params.row.backTime.end / 1000)))
  185. ]);
  186. }
  187. }, {
  188. title: this.$L('新计划时间'),
  189. minWidth: 135,
  190. align: 'center',
  191. render: (h, params) => {
  192. return h('div', {
  193. style: {},
  194. }, [
  195. h('div', $A.formatDate('Y-m-d H:i', Math.round(params.row.newTime.start / 1000))),
  196. h('div', $A.formatDate('Y-m-d H:i', Math.round(params.row.newTime.end / 1000)))
  197. ]);
  198. }
  199. }
  200. ];
  201. //
  202. this.initData();
  203. this.loadFinish = true;
  204. },
  205. watch:{
  206. projectLabel: {
  207. handler() {
  208. this.initData();
  209. },
  210. deep: true,
  211. }
  212. },
  213. methods: {
  214. initData() {
  215. this.lists = [];
  216. this.projectLabel.forEach((item) => {
  217. if (this.filtrProjectId > 0) {
  218. if (item.id != this.filtrProjectId) {
  219. return;
  220. }
  221. }
  222. item.taskLists.forEach((taskData) => {
  223. let notime = taskData.startdate == 0 || taskData.enddate == 0;
  224. let times = this.getTimeObj(taskData);
  225. let start = times.start;
  226. let end = times.end;
  227. //
  228. let color = '#058ce4';
  229. if (taskData.complete) {
  230. color = '#c1c1c1';
  231. } else {
  232. if (taskData.level === 1) {
  233. color = '#ff0000';
  234. }else if (taskData.level === 2) {
  235. color = '#BB9F35';
  236. }else if (taskData.level === 3) {
  237. color = '#449EDD';
  238. }else if (taskData.level === 4) {
  239. color = '#84A83B';
  240. }
  241. }
  242. //
  243. let tempTime = { start, end };
  244. let findData = this.editData.find((t) => { return t.id == taskData.id });
  245. if (findData) {
  246. findData.backTime = $A.cloneData(tempTime)
  247. tempTime = $A.cloneData(findData.newTime);
  248. }
  249. //
  250. this.lists.push({
  251. id: taskData.id,
  252. label: taskData.title,
  253. time: tempTime,
  254. notime: notime,
  255. style: { background: color },
  256. });
  257. });
  258. });
  259. //
  260. if (this.lists.length == 0 && this.filtrProjectId == 0) {
  261. this.$Modal.warning({
  262. title: this.$L("温馨提示"),
  263. content: this.$L('任务列表为空,请先添加任务。'),
  264. onOk: () => {
  265. this.$emit('on-close');
  266. },
  267. });
  268. }
  269. },
  270. updateTime(item) {
  271. let original = this.getRawTime(item.id);
  272. if (Math.abs(original.end - item.time.end) > 1000 || Math.abs(original.start - item.time.start) > 1000) {
  273. //修改时间(变化超过1秒钟)
  274. let backTime = $A.cloneData(original);
  275. let newTime = $A.cloneData(item.time);
  276. let findData = this.editData.find(({id}) => id == item.id);
  277. if (findData) {
  278. findData.newTime = newTime;
  279. } else {
  280. this.editData.push({
  281. id: item.id,
  282. label: item.label,
  283. notime: item.notime,
  284. backTime,
  285. newTime,
  286. })
  287. }
  288. }
  289. },
  290. clickItem(item) {
  291. this.taskDetail(item.id);
  292. },
  293. editSubmit(save) {
  294. let triggerTask = [];
  295. this.editData.forEach((item) => {
  296. if (save) {
  297. this.editLoad++;
  298. let timeStart = $A.formatDate('Y-m-d H:i', Math.round(item.newTime.start / 1000));
  299. let timeEnd = $A.formatDate('Y-m-d H:i', Math.round(item.newTime.end / 1000));
  300. let ajaxData = {
  301. act: 'plannedtime',
  302. taskid: item.id,
  303. content: timeStart + "," + timeEnd,
  304. };
  305. $A.apiAjax({
  306. url: 'project/task/edit',
  307. method: 'post',
  308. data: ajaxData,
  309. error: () => {
  310. this.lists.some((task) => {
  311. if (task.id == item.id) {
  312. this.$set(task, 'time', item.backTime);
  313. return true;
  314. }
  315. });
  316. },
  317. success: (res) => {
  318. if (res.ret === 1) {
  319. triggerTask.push({
  320. status: 'await',
  321. act: ajaxData.act,
  322. taskid: ajaxData.taskid,
  323. data: res.data,
  324. })
  325. } else {
  326. this.lists.some((task) => {
  327. if (task.id == item.id) {
  328. this.$set(task, 'time', item.backTime);
  329. return true;
  330. }
  331. });
  332. }
  333. },
  334. afterComplete: () => {
  335. this.editLoad--;
  336. if (this.editLoad <= 0) {
  337. triggerTask.forEach((info) => {
  338. if (info.status == 'await') {
  339. info.status = 'trigger';
  340. $A.triggerTaskInfoListener(info.act, info.data);
  341. $A.triggerTaskInfoChange(info.taskid);
  342. }
  343. });
  344. }
  345. },
  346. });
  347. } else {
  348. this.lists.some((task) => {
  349. if (task.id == item.id) {
  350. this.$set(task, 'time', item.backTime);
  351. return true;
  352. }
  353. })
  354. }
  355. });
  356. this.editData = [];
  357. },
  358. getRawTime(taskId) {
  359. let times = null;
  360. this.projectLabel.some((item) => {
  361. item.taskLists.some((taskData) => {
  362. if (taskData.id == taskId) {
  363. times = this.getTimeObj(taskData);
  364. return true;
  365. }
  366. });
  367. if (times) {
  368. return true;
  369. }
  370. });
  371. return times;
  372. },
  373. getTimeObj(taskData) {
  374. let start = taskData.startdate || taskData.indate;
  375. let end = taskData.enddate || (taskData.indate + 86400);
  376. if (end == start) {
  377. end = Math.round(new Date($A.formatDate('Y-m-d 23:59:59', end)).getTime()/1000);
  378. }
  379. end = Math.max(end, start + 60);
  380. start*= 1000;
  381. end*= 1000;
  382. return {start, end};
  383. },
  384. tapProject(e) {
  385. this.filtrProjectId = $A.runNum(e);
  386. this.initData();
  387. },
  388. }
  389. }
  390. </script>