todo.vue 30 KB

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