todo.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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">{{$L('刷新')}}</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">{{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">[{{$L('超期')}}]</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)">{{$L('加载更多')}}</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. userInfo: {},
  333. taskDatas: {
  334. "1": {lists: [], hasMorePages: false},
  335. "2": {lists: [], hasMorePages: false},
  336. "3": {lists: [], hasMorePages: false},
  337. "4": {lists: [], hasMorePages: false},
  338. },
  339. taskSortData: '',
  340. taskSortDisabled: false,
  341. todoDrawerShow: false,
  342. todoDrawerTab: 'calendar',
  343. todoReportDrawerShow: false,
  344. todoReportDrawerTab: 'my',
  345. }
  346. },
  347. mounted() {
  348. this.refreshTask();
  349. this.userInfo = $A.getUserInfo((res, isLogin) => {
  350. if (this.userInfo.id != res.id) {
  351. this.userInfo = res;
  352. isLogin && this.refreshTask();
  353. }
  354. }, false);
  355. //
  356. $A.setOnTaskInfoListener('pages/todo',(act, detail) => {
  357. if (detail.username != $A.getUserName()) {
  358. for (let level in this.taskDatas) {
  359. this.taskDatas[level].lists.some((task, i) => {
  360. if (task.id == detail.id) {
  361. this.taskDatas[level].lists.splice(i, 1);
  362. this.taskSortData = this.getTaskSort();
  363. return true;
  364. }
  365. });
  366. }
  367. return;
  368. }
  369. //
  370. switch (act) {
  371. case 'deleteproject': // 删除项目
  372. case 'deletelabel': // 删除分类
  373. this.refreshTask();
  374. return;
  375. case 'tasklevel': // 调整级别
  376. return;
  377. }
  378. //
  379. for (let level in this.taskDatas) {
  380. this.taskDatas[level].lists.some((task, i) => {
  381. if (task.id == detail.id) {
  382. this.taskDatas[level].lists.splice(i, 1, detail);
  383. return true;
  384. }
  385. });
  386. }
  387. //
  388. switch (act) {
  389. case "title": // 标题
  390. case "desc": // 描述
  391. case "plannedtime": // 设置计划时间
  392. case "unplannedtime": // 取消计划时间
  393. case "complete": // 标记完成
  394. case "unfinished": // 标记未完成
  395. case "comment": // 评论
  396. // 这些都不用处理
  397. break;
  398. case "level": // 优先级
  399. for (let level in this.taskDatas) {
  400. this.taskDatas[level].lists.some((task, i) => {
  401. if (task.id == detail.id) {
  402. this.taskDatas[level].lists.splice(i, 1);
  403. return true;
  404. }
  405. });
  406. if (level == detail.level) {
  407. let index = this.taskDatas[level].lists.length;
  408. this.taskDatas[level].lists.some((task, i) => {
  409. if (detail.userorder > task.userorder || (detail.userorder == task.userorder && detail.id > task.id)) {
  410. index = i;
  411. return true;
  412. }
  413. });
  414. this.taskDatas[level].lists.splice(index, 0, detail);
  415. }
  416. }
  417. this.taskSortData = this.getTaskSort();
  418. break;
  419. case "username": // 负责人
  420. case "delete": // 删除任务
  421. case "archived": // 归档
  422. for (let level in this.taskDatas) {
  423. this.taskDatas[level].lists.some((task, i) => {
  424. if (task.id == detail.id) {
  425. this.taskDatas[level].lists.splice(i, 1);
  426. return true;
  427. }
  428. });
  429. }
  430. this.taskSortData = this.getTaskSort();
  431. break;
  432. case "unarchived": // 取消归档
  433. for (let level in this.taskDatas) {
  434. if (level == detail.level) {
  435. let index = this.taskDatas[level].lists.length;
  436. this.taskDatas[level].lists.some((task, i) => {
  437. if (detail.userorder > task.userorder || (detail.userorder == task.userorder && detail.id > task.id)) {
  438. index = i;
  439. return true;
  440. }
  441. });
  442. this.taskDatas[level].lists.splice(index, 0, detail);
  443. }
  444. }
  445. this.taskSortData = this.getTaskSort();
  446. break;
  447. }
  448. }, true);
  449. },
  450. deactivated() {
  451. this.todoDrawerShow = false;
  452. this.todoReportDrawerShow = false;
  453. },
  454. computed: {
  455. },
  456. watch: {
  457. },
  458. methods: {
  459. pTitle(p) {
  460. switch (p) {
  461. case "1":
  462. return this.$L("重要且紧急");
  463. case "2":
  464. return this.$L("重要不紧急");
  465. case "3":
  466. return this.$L("紧急不重要");
  467. case "4":
  468. return this.$L("不重要不紧急");
  469. }
  470. },
  471. refreshTask() {
  472. this.taskDatas = {
  473. "1": {lists: [], hasMorePages: false},
  474. "2": {lists: [], hasMorePages: false},
  475. "3": {lists: [], hasMorePages: false},
  476. "4": {lists: [], hasMorePages: false},
  477. };
  478. for (let i = 1; i <= 4; i++) {
  479. this.getTaskLists(i.toString());
  480. }
  481. },
  482. getTaskLists(index, isNext) {
  483. let taskData = this.taskDatas[index];
  484. let currentPage = 1;
  485. let pagesize = 20;
  486. let withNextPage = false;
  487. //
  488. if (isNext === true) {
  489. if (taskData.hasMorePages !== true) {
  490. return;
  491. }
  492. currentPage = Math.max(1, $A.runNum(taskData['currentPage']));
  493. let tempLists = this.taskDatas[detail.level].lists.filter((item) => { return item.complete == 0; });
  494. if (tempLists.length >= currentPage * pagesize) {
  495. currentPage++;
  496. } else {
  497. withNextPage = true;
  498. }
  499. }
  500. this.$set(taskData, 'hasMorePages', false);
  501. this.$set(taskData, 'loadIng', $A.runNum(taskData.loadIng) + 1);
  502. this.taskSortDisabled = true;
  503. this.loadIng++;
  504. $A.aAjax({
  505. url: 'project/task/lists',
  506. data: {
  507. level: index,
  508. sorts: {key:'userorder', order:'desc'},
  509. page: currentPage,
  510. pagesize: pagesize,
  511. },
  512. complete: () => {
  513. this.loadIng--;
  514. this.taskSortDisabled = false;
  515. this.$set(taskData, 'loadIng', $A.runNum(taskData.loadIng) - 1);
  516. },
  517. success: (res) => {
  518. if (res.ret === 1) {
  519. let inLists;
  520. res.data.lists.forEach((data) => {
  521. inLists = false;
  522. taskData.lists.some((item, i) => {
  523. if (item.id == data.id) {
  524. taskData.lists.splice(i, 1, data);
  525. return inLists = true;
  526. }
  527. });
  528. if (!inLists) {
  529. taskData.lists.push(data);
  530. }
  531. });
  532. this.taskSortData = this.getTaskSort();
  533. this.$set(taskData, 'currentPage', res.data.currentPage);
  534. this.$set(taskData, 'hasMorePages', res.data.hasMorePages);
  535. if (res.data.currentPage && withNextPage) {
  536. this.getTaskLists(index, true);
  537. }
  538. } else {
  539. this.$set(taskData, 'lists', []);
  540. this.$set(taskData, 'hasMorePages', false);
  541. }
  542. }
  543. });
  544. },
  545. addTask(index) {
  546. let taskData = this.taskDatas[index];
  547. let title = $A.trim(taskData.title);
  548. if ($A.count(title) == 0) {
  549. return;
  550. }
  551. this.$set(taskData, 'focus', false);
  552. this.$set(taskData, 'title', '');
  553. //
  554. let tempId = $A.randomString(16);
  555. taskData.lists.unshift({
  556. id: tempId,
  557. title: title,
  558. loadIng: true,
  559. });
  560. this.taskSortDisabled = true;
  561. $A.aAjax({
  562. url: 'project/task/add',
  563. data: {
  564. title: title,
  565. level: index,
  566. },
  567. complete: () => {
  568. this.taskSortDisabled = false;
  569. },
  570. error: () => {
  571. taskData.lists.some((item, i) => {
  572. if (item.id == tempId) {
  573. taskData.lists.splice(i, 1);
  574. return true;
  575. }
  576. });
  577. alert(this.$L('网络繁忙,请稍后再试!'));
  578. },
  579. success: (res) => {
  580. if (res.ret === 1) {
  581. this.$Message.success(res.msg);
  582. } else {
  583. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  584. }
  585. taskData.lists.some((item, i) => {
  586. if (item.id == tempId) {
  587. if (res.ret === 1) {
  588. taskData.lists.splice(i, 1, res.data);
  589. } else {
  590. taskData.lists.splice(i, 1);
  591. }
  592. return true;
  593. }
  594. });
  595. this.taskSortData = this.getTaskSort();
  596. }
  597. });
  598. },
  599. getTaskSort() {
  600. let sortData = "",
  601. taskData = "";
  602. for (let level in this.taskDatas) {
  603. taskData = "";
  604. this.taskDatas[level].lists.forEach((task) => {
  605. if (taskData) taskData += "-";
  606. taskData += task.id;
  607. });
  608. if (sortData) sortData += ";";
  609. sortData += level + ":" + taskData;
  610. }
  611. return sortData;
  612. },
  613. handleTodo(event) {
  614. switch (event) {
  615. case 'calendar':
  616. case 'complete':
  617. case 'attention': {
  618. this.todoDrawerShow = true;
  619. this.todoDrawerTab = event;
  620. break;
  621. }
  622. case 'report': {
  623. this.todoReportDrawerShow = true;
  624. break;
  625. }
  626. }
  627. },
  628. taskSortUpdate() {
  629. let oldSort = this.taskSortData;
  630. let newSort = this.getTaskSort();
  631. if (oldSort == newSort) {
  632. return;
  633. }
  634. this.taskSortData = newSort;
  635. this.taskSortDisabled = true;
  636. $A.aAjax({
  637. url: 'project/sort/todo',
  638. data: {
  639. oldsort: oldSort,
  640. newsort: newSort,
  641. },
  642. complete: () => {
  643. this.taskSortDisabled = false;
  644. },
  645. error: () => {
  646. this.refreshTask();
  647. alert(this.$L('网络繁忙,请稍后再试!'));
  648. },
  649. success: (res) => {
  650. if (res.ret === 1) {
  651. this.$Message.success(res.msg);
  652. $A.triggerTaskInfoListener('tasklevel', res.data.taskLevel);
  653. } else {
  654. this.refreshTask();
  655. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  656. }
  657. }
  658. });
  659. },
  660. openTaskModal(taskDetail) {
  661. this.taskDetail(taskDetail);
  662. },
  663. },
  664. }
  665. </script>