todo.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <template>
  2. <div class="w-main todo">
  3. <v-title>{{$L('待办')}}-{{$L('轻量级的团队在线协作')}}</v-title>
  4. <div class="w-nav">
  5. <div class="nav-row">
  6. <div class="w-nav-left">
  7. <div class="page-nav-left">
  8. <span><i class="ft icon">&#xE787;</i> {{$L('我的待办')}}</span>
  9. <div v-if="loadIng > 0" class="page-nav-loading"><w-loading></w-loading></div>
  10. <div v-else class="page-nav-refresh"><em @click="refreshTask">{{$L('刷新')}}</em></div>
  11. </div>
  12. </div>
  13. <div class="w-nav-flex"></div>
  14. <div class="w-nav-right">
  15. <span class="ft hover" @click="handleTodo('calendar')"><i class="ft icon">&#xE706;</i> {{$L('待办日程')}}</span>
  16. <span class="ft hover" @click="handleTodo('complete')"><i class="ft icon">&#xE73D;</i> {{$L('已完成的任务')}}</span>
  17. <span class="ft hover" @click="handleTodo('attention')"><i class="ft icon">&#xE748;</i> {{$L('我关注的任务')}}</span>
  18. <span class="ft hover" @click="handleTodo('report')"><i class="ft icon">&#xE743;</i> {{$L('周报/日报')}}</span>
  19. </div>
  20. </div>
  21. </div>
  22. <w-content>
  23. <div class="todo-main">
  24. <div v-for="subs in [['1', '2'], ['3', '4']]" class="todo-ul">
  25. <div v-for="index in subs" class="todo-li">
  26. <div class="todo-card">
  27. <div class="todo-card-head" :class="['p' + index]">
  28. <i class="ft icon flag">&#xE753;</i>
  29. <div class="todo-card-title">{{pTitle(index)}}</div>
  30. <label class="todo-input-box" :class="{active: !!taskDatas[index].focus}" @click="()=>{$set(taskDatas[index],'focus',true)}">
  31. <div class="todo-input-ibox" @click.stop="">
  32. <Input v-model="taskDatas[index].title" class="todo-input-enter" :placeholder="$L('在这里输入事项,回车即可保存')" @on-enter="addTask(index)"></Input>
  33. <div class="todo-input-close" @click="()=>{$set(taskDatas[index],'focus',false)}"><i class="ft icon">&#xE710;</i></div>
  34. </div>
  35. <div class="todo-input-pbox">
  36. <div class="todo-input-placeholder">{{$L('点击可快速添加需要处理的事项')}}</div>
  37. <div class="todo-input-close"><i class="ft icon">&#xE740;</i></div>
  38. </div>
  39. </label>
  40. </div>
  41. <div class="todo-card-content">
  42. <draggable
  43. v-if="taskDatas[index].lists.length > 0"
  44. v-model="taskDatas[index].lists"
  45. class="content-ul"
  46. group="task"
  47. draggable=".task-draggable"
  48. :animation="150"
  49. :disabled="taskSortDisabled"
  50. @sort="taskSortUpdate"
  51. @remove="taskSortUpdate">
  52. <div v-for="task in taskDatas[index].lists" class="content-li task-draggable" :key="task.id" :class="{complete:task.complete}" @click="openTaskModal(task)">
  53. <Icon v-if="task.complete" class="task-check" type="md-checkbox-outline" @click.stop="taskComplete(task, false)"/>
  54. <Icon v-else class="task-check" type="md-square-outline" @click.stop="taskComplete(task, true)"/>
  55. <div v-if="!!task.loadIng" class="task-loading"><w-loading></w-loading></div>
  56. <div v-if="task.overdue" class="task-overdue">[{{$L('超期')}}]</div>
  57. <div class="task-title">{{task.title}}</div>
  58. </div>
  59. <div v-if="taskDatas[index].hasMorePages === true" class="content-li more" @click="getTaskLists(index, true)">{{$L('加载更多')}}</div>
  60. </draggable>
  61. <div v-else-if="taskDatas[index].loadIng == 0" class="content-empty">{{$L('恭喜你!已完成了所有待办')}}</div>
  62. <div v-if="taskDatas[index].loadIng > 0" class="content-loading"><w-loading></w-loading></div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </w-content>
  69. <WDrawer v-model="todoDrawerShow" maxWidth="1000">
  70. <Tabs v-if="todoDrawerShow" v-model="todoDrawerTab">
  71. <TabPane :label="$L('待办日程')" name="calendar">
  72. <todo-calendar :canload="todoDrawerShow && todoDrawerTab == 'calendar'"></todo-calendar>
  73. </TabPane>
  74. <TabPane :label="$L('已完成的任务')" name="complete">
  75. <todo-complete :canload="todoDrawerShow && todoDrawerTab == 'complete'"></todo-complete>
  76. </TabPane>
  77. <TabPane :label="$L('我关注的任务')" name="attention">
  78. <todo-attention :canload="todoDrawerShow && todoDrawerTab == 'attention'"></todo-attention>
  79. </TabPane>
  80. </Tabs>
  81. </WDrawer>
  82. <WDrawer v-model="todoReportDrawerShow" maxWidth="1000">
  83. <Tabs v-if="todoReportDrawerShow" v-model="todoReportDrawerTab">
  84. <TabPane :label="$L('我的汇报')" name="my">
  85. <report-my :canload="todoReportDrawerShow && todoReportDrawerTab == 'my'"></report-my>
  86. </TabPane>
  87. <TabPane :label="$L('收到的汇报')" name="receive">
  88. <report-receive :canload="todoReportDrawerShow && todoReportDrawerTab == 'receive'"></report-receive>
  89. </TabPane>
  90. </Tabs>
  91. </WDrawer>
  92. </div>
  93. </template>
  94. <style lang="scss">
  95. .todo-input-enter {
  96. .ivu-input {
  97. border: 0;
  98. background-color: rgba(255, 255, 255, 0.9);
  99. }
  100. }
  101. </style>
  102. <style lang="scss" scoped>
  103. .todo {
  104. .todo-main {
  105. display: flex;
  106. flex-direction: column;
  107. align-items: center;
  108. justify-content: center;
  109. width: 100%;
  110. height: 100%;
  111. min-height: 500px;
  112. padding: 5px;
  113. .todo-ul {
  114. flex: 1;
  115. display: flex;
  116. flex-direction: row;
  117. align-items: center;
  118. justify-content: center;
  119. width: 100%;
  120. .todo-li {
  121. flex: 1;
  122. height: 100%;
  123. position: relative;
  124. .todo-card {
  125. position: absolute;
  126. top: 10px;
  127. left: 10px;
  128. right: 10px;
  129. bottom: 10px;
  130. display: flex;
  131. flex-direction: column;
  132. .todo-card-head {
  133. display: flex;
  134. align-items: center;
  135. padding: 0 10px;
  136. height: 38px;
  137. border-radius: 4px 4px 0 0;
  138. color: #ffffff;
  139. .ft.icon {
  140. transform: scale(1);
  141. }
  142. .flag {
  143. font-weight: bold;
  144. font-size: 14px;
  145. margin-right: 5px;
  146. min-width: 16px;
  147. }
  148. .todo-card-title {
  149. font-weight: bold;
  150. }
  151. .todo-input-box {
  152. flex: 1;
  153. display: flex;
  154. flex-direction: row;
  155. align-items: center;
  156. justify-content: flex-end;
  157. height: 100%;
  158. cursor: pointer;
  159. &:hover {
  160. .todo-input-placeholder {
  161. opacity: 1;
  162. }
  163. }
  164. &.active {
  165. .todo-input-pbox {
  166. display: none;
  167. }
  168. .todo-input-ibox {
  169. display: flex;
  170. }
  171. }
  172. .todo-input-placeholder {
  173. color: rgba(255, 255, 255, 0.6);
  174. padding-right: 6px;
  175. transition: all 0.2s;
  176. opacity: 0;
  177. }
  178. .todo-input-pbox,
  179. .todo-input-ibox {
  180. flex: 1;
  181. display: flex;
  182. flex-direction: row;
  183. align-items: center;
  184. justify-content: flex-end;
  185. padding-left: 14px;
  186. height: 100%;
  187. }
  188. .todo-input-ibox {
  189. display: none;
  190. }
  191. .todo-input-close {
  192. height: 100%;
  193. display: flex;
  194. align-items: center;
  195. padding-left: 8px;
  196. i {
  197. font-size: 18px;
  198. font-weight: normal;
  199. }
  200. }
  201. }
  202. &.p1 {
  203. background: rgba(248, 14, 21, 0.6);
  204. }
  205. &.p2 {
  206. background: rgba(236, 196, 2, 0.5);
  207. }
  208. &.p3 {
  209. background: rgba(0, 159, 227, 0.7);
  210. }
  211. &.p4 {
  212. background: rgba(121, 170, 28, 0.7);
  213. }
  214. }
  215. .todo-card-content {
  216. flex: 1;
  217. background-color: #f5f6f7;
  218. border-radius: 0 0 4px 4px;
  219. overflow: auto;
  220. transform: translateZ(0);
  221. .content-ul {
  222. display: flex;
  223. flex-direction: column;
  224. .content-li {
  225. display: flex;
  226. flex-direction: row;
  227. align-items: flex-start;
  228. width: 100%;
  229. padding: 8px;
  230. color: #444444;
  231. border-bottom: dotted 1px rgba(153, 153, 153, 0.25);
  232. position: relative;
  233. cursor: pointer;
  234. &.complete {
  235. color: #999999;
  236. .task-title {
  237. text-decoration: line-through;
  238. }
  239. }
  240. &.more {
  241. color: #666;
  242. justify-content: center;
  243. }
  244. .task-check {
  245. font-size: 16px;
  246. padding-right: 6px;
  247. padding-top: 3px;
  248. }
  249. .task-loading {
  250. width: 15px;
  251. height: 15px;
  252. margin-right: 6px;
  253. margin-top: 3px;
  254. }
  255. .task-overdue {
  256. color: #ff0000;
  257. padding-right: 2px;
  258. }
  259. .task-title {
  260. flex: 1;
  261. word-break: break-all;
  262. &:hover {
  263. color: #000000;
  264. }
  265. }
  266. }
  267. }
  268. .content-loading {
  269. width: 100%;
  270. height: 22px;
  271. text-align: center;
  272. margin-top: 8px;
  273. margin-bottom: 8px;
  274. }
  275. .content-empty {
  276. margin: 20px auto;
  277. text-align: center;
  278. color: #666;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. @media (max-width: 780px) {
  286. .todo-main {
  287. height: auto;
  288. .todo-ul {
  289. flex-direction: column;
  290. .todo-li {
  291. width: 100%;
  292. .todo-card {
  293. position: static;
  294. top: 0;
  295. right: 0;
  296. left: 0;
  297. bottom: 0;
  298. margin: 10px;
  299. display: flex;
  300. flex-direction: column;
  301. min-height: 320px;
  302. max-height: 520px;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. </style>
  310. <script>
  311. import draggable from 'vuedraggable'
  312. import WContent from "../components/WContent";
  313. import TodoCalendar from "../components/project/todo/calendar";
  314. import TodoComplete from "../components/project/todo/complete";
  315. import TodoAttention from "../components/project/todo/attention";
  316. import Task from "../mixins/task";
  317. import ReportMy from "../components/report/my";
  318. import ReportReceive from "../components/report/receive";
  319. import WDrawer from "../components/iview/WDrawer";
  320. export default {
  321. components: {
  322. WDrawer,
  323. ReportReceive,
  324. ReportMy, draggable, TodoAttention, TodoComplete, TodoCalendar, WContent},
  325. mixins: [
  326. Task
  327. ],
  328. data () {
  329. return {
  330. loadIng: 0,
  331. userInfo: {},
  332. taskDatas: {
  333. "1": {lists: [], hasMorePages: false},
  334. "2": {lists: [], hasMorePages: false},
  335. "3": {lists: [], hasMorePages: false},
  336. "4": {lists: [], hasMorePages: false},
  337. },
  338. taskSortData: '',
  339. taskSortDisabled: false,
  340. todoDrawerShow: false,
  341. todoDrawerTab: 'calendar',
  342. todoReportDrawerShow: false,
  343. todoReportDrawerTab: 'my',
  344. }
  345. },
  346. mounted() {
  347. this.refreshTask();
  348. this.userInfo = $A.getUserInfo((res, isLogin) => {
  349. if (this.userInfo.id != res.id) {
  350. this.userInfo = res;
  351. isLogin && this.refreshTask();
  352. }
  353. }, false);
  354. //
  355. $A.setOnTaskInfoListener('pages/todo',(act, detail) => {
  356. if (detail.username != $A.getUserName()) {
  357. for (let level in this.taskDatas) {
  358. this.taskDatas[level].lists.some((task, i) => {
  359. if (task.id == detail.id) {
  360. this.taskDatas[level].lists.splice(i, 1);
  361. this.taskSortData = this.getTaskSort();
  362. return true;
  363. }
  364. });
  365. }
  366. return;
  367. }
  368. //
  369. switch (act) {
  370. case 'deleteproject': // 删除项目
  371. case 'deletelabel': // 删除分类
  372. this.refreshTask();
  373. return;
  374. case 'tasklevel': // 调整级别
  375. return;
  376. }
  377. //
  378. for (let level in this.taskDatas) {
  379. this.taskDatas[level].lists.some((task, i) => {
  380. if (task.id == detail.id) {
  381. this.taskDatas[level].lists.splice(i, 1, detail);
  382. return true;
  383. }
  384. });
  385. }
  386. //
  387. switch (act) {
  388. case "title": // 标题
  389. case "desc": // 描述
  390. case "plannedtime": // 设置计划时间
  391. case "unplannedtime": // 取消计划时间
  392. case "complete": // 标记完成
  393. case "unfinished": // 标记未完成
  394. case "comment": // 评论
  395. // 这些都不用处理
  396. break;
  397. case "level": // 优先级
  398. for (let level in this.taskDatas) {
  399. this.taskDatas[level].lists.some((task, i) => {
  400. if (task.id == detail.id) {
  401. this.taskDatas[level].lists.splice(i, 1);
  402. return true;
  403. }
  404. });
  405. if (level == detail.level) {
  406. let index = this.taskDatas[level].lists.length;
  407. this.taskDatas[level].lists.some((task, i) => {
  408. if (detail.userorder > task.userorder || (detail.userorder == task.userorder && detail.id > task.id)) {
  409. index = i;
  410. return true;
  411. }
  412. });
  413. this.taskDatas[level].lists.splice(index, 0, detail);
  414. }
  415. }
  416. this.taskSortData = this.getTaskSort();
  417. break;
  418. case "username": // 负责人
  419. case "delete": // 删除任务
  420. case "archived": // 归档
  421. for (let level in this.taskDatas) {
  422. this.taskDatas[level].lists.some((task, i) => {
  423. if (task.id == detail.id) {
  424. this.taskDatas[level].lists.splice(i, 1);
  425. return true;
  426. }
  427. });
  428. }
  429. this.taskSortData = this.getTaskSort();
  430. break;
  431. case "unarchived": // 取消归档
  432. for (let level in this.taskDatas) {
  433. if (level == detail.level) {
  434. let index = this.taskDatas[level].lists.length;
  435. this.taskDatas[level].lists.some((task, i) => {
  436. if (detail.userorder > task.userorder || (detail.userorder == task.userorder && detail.id > task.id)) {
  437. index = i;
  438. return true;
  439. }
  440. });
  441. this.taskDatas[level].lists.splice(index, 0, detail);
  442. }
  443. }
  444. this.taskSortData = this.getTaskSort();
  445. break;
  446. }
  447. }, true);
  448. },
  449. deactivated() {
  450. this.todoDrawerShow = false;
  451. this.todoReportDrawerShow = false;
  452. },
  453. computed: {
  454. },
  455. watch: {
  456. },
  457. methods: {
  458. pTitle(p) {
  459. switch (p) {
  460. case "1":
  461. return this.$L("重要且紧急");
  462. case "2":
  463. return this.$L("重要不紧急");
  464. case "3":
  465. return this.$L("紧急不重要");
  466. case "4":
  467. return this.$L("不重要不紧急");
  468. }
  469. },
  470. refreshTask() {
  471. this.taskDatas = {
  472. "1": {lists: [], hasMorePages: false},
  473. "2": {lists: [], hasMorePages: false},
  474. "3": {lists: [], hasMorePages: false},
  475. "4": {lists: [], hasMorePages: false},
  476. };
  477. for (let i = 1; i <= 4; i++) {
  478. this.getTaskLists(i.toString());
  479. }
  480. },
  481. getTaskLists(index, isNext) {
  482. let taskData = this.taskDatas[index];
  483. let currentPage = 1;
  484. let pagesize = 20;
  485. let withNextPage = false;
  486. //
  487. if (isNext === true) {
  488. if (taskData.hasMorePages !== true) {
  489. return;
  490. }
  491. currentPage = Math.max(1, $A.runNum(taskData['currentPage']));
  492. let tempLists = this.taskDatas[detail.level].lists.filter((item) => { return item.complete == 0; });
  493. if (tempLists.length >= currentPage * pagesize) {
  494. currentPage++;
  495. } else {
  496. withNextPage = true;
  497. }
  498. }
  499. this.$set(taskData, 'hasMorePages', false);
  500. this.$set(taskData, 'loadIng', $A.runNum(taskData.loadIng) + 1);
  501. this.taskSortDisabled = true;
  502. this.loadIng++;
  503. $A.aAjax({
  504. url: 'project/task/lists',
  505. data: {
  506. level: index,
  507. sorts: {key:'userorder', order:'desc'},
  508. page: currentPage,
  509. pagesize: pagesize,
  510. },
  511. complete: () => {
  512. this.loadIng--;
  513. this.taskSortDisabled = false;
  514. this.$set(taskData, 'loadIng', $A.runNum(taskData.loadIng) - 1);
  515. },
  516. success: (res) => {
  517. if (res.ret === 1) {
  518. let inLists;
  519. res.data.lists.forEach((data) => {
  520. inLists = false;
  521. taskData.lists.some((item, i) => {
  522. if (item.id == data.id) {
  523. taskData.lists.splice(i, 1, data);
  524. return inLists = true;
  525. }
  526. });
  527. if (!inLists) {
  528. taskData.lists.push(data);
  529. }
  530. });
  531. this.taskSortData = this.getTaskSort();
  532. this.$set(taskData, 'currentPage', res.data.currentPage);
  533. this.$set(taskData, 'hasMorePages', res.data.hasMorePages);
  534. if (res.data.currentPage && withNextPage) {
  535. this.getTaskLists(index, true);
  536. }
  537. } else {
  538. this.$set(taskData, 'lists', []);
  539. this.$set(taskData, 'hasMorePages', false);
  540. }
  541. }
  542. });
  543. },
  544. addTask(index) {
  545. let taskData = this.taskDatas[index];
  546. let title = $A.trim(taskData.title);
  547. if ($A.count(title) == 0) {
  548. return;
  549. }
  550. this.$set(taskData, 'focus', false);
  551. this.$set(taskData, 'title', '');
  552. //
  553. let tempId = $A.randomString(16);
  554. taskData.lists.unshift({
  555. id: tempId,
  556. title: title,
  557. loadIng: true,
  558. });
  559. this.taskSortDisabled = true;
  560. $A.aAjax({
  561. url: 'project/task/add',
  562. data: {
  563. title: title,
  564. level: index,
  565. },
  566. complete: () => {
  567. this.taskSortDisabled = false;
  568. },
  569. error: () => {
  570. taskData.lists.some((item, i) => {
  571. if (item.id == tempId) {
  572. taskData.lists.splice(i, 1);
  573. return true;
  574. }
  575. });
  576. alert(this.$L('网络繁忙,请稍后再试!'));
  577. },
  578. success: (res) => {
  579. if (res.ret === 1) {
  580. this.$Message.success(res.msg);
  581. } else {
  582. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  583. }
  584. taskData.lists.some((item, i) => {
  585. if (item.id == tempId) {
  586. if (res.ret === 1) {
  587. taskData.lists.splice(i, 1, res.data);
  588. } else {
  589. taskData.lists.splice(i, 1);
  590. }
  591. return true;
  592. }
  593. });
  594. this.taskSortData = this.getTaskSort();
  595. }
  596. });
  597. },
  598. getTaskSort() {
  599. let sortData = "",
  600. taskData = "";
  601. for (let level in this.taskDatas) {
  602. taskData = "";
  603. this.taskDatas[level].lists.forEach((task) => {
  604. if (taskData) taskData += "-";
  605. taskData += task.id;
  606. });
  607. if (sortData) sortData += ";";
  608. sortData += level + ":" + taskData;
  609. }
  610. return sortData;
  611. },
  612. handleTodo(event) {
  613. switch (event) {
  614. case 'calendar':
  615. case 'complete':
  616. case 'attention': {
  617. this.todoDrawerShow = true;
  618. this.todoDrawerTab = event;
  619. break;
  620. }
  621. case 'report': {
  622. this.todoReportDrawerShow = true;
  623. break;
  624. }
  625. }
  626. },
  627. taskSortUpdate() {
  628. let oldSort = this.taskSortData;
  629. let newSort = this.getTaskSort();
  630. if (oldSort == newSort) {
  631. return;
  632. }
  633. this.taskSortData = newSort;
  634. this.taskSortDisabled = true;
  635. $A.aAjax({
  636. url: 'project/sort/todo',
  637. data: {
  638. oldsort: oldSort,
  639. newsort: newSort,
  640. },
  641. complete: () => {
  642. this.taskSortDisabled = false;
  643. },
  644. error: () => {
  645. this.refreshTask();
  646. alert(this.$L('网络繁忙,请稍后再试!'));
  647. },
  648. success: (res) => {
  649. if (res.ret === 1) {
  650. this.$Message.success(res.msg);
  651. $A.triggerTaskInfoListener('tasklevel', res.data.taskLevel);
  652. } else {
  653. this.refreshTask();
  654. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  655. }
  656. }
  657. });
  658. },
  659. openTaskModal(taskDetail) {
  660. this.taskDetail(taskDetail);
  661. },
  662. },
  663. }
  664. </script>