todo.vue 28 KB

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