TaskItem.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <div>
  3. <CollapseTransition>
  4. <div v-show="isShow">
  5. <div class="taskBox" v-if="projects.length>0">
  6. <div v-for="(item,index) in projects" :key="index" class="flex-box-ce isSimpleShow" @click.prevent.stop="openDetail2(item)">
  7. <div class="flex-1 clamp2" style="padding-right: 30px;">
  8. <i class="el-icon-s-finance" style="margin-right: 10px;"></i>
  9. <Tooltip :preHtml="item.name" class="hoverBlue"><span>{{item.name}}</span></Tooltip>
  10. </div>
  11. <template v-if="isParent">
  12. <div class="hover-border2"> <svg-icon icon-class="#icon-biaoqian_wode" class="svgIcon"></svg-icon><span>{{$getEmployeeMapItem(item.owner_id).name}}</span></div>
  13. <div class="hover-border2" style="margin: 0 30px;text-align: center;width: 52px;">
  14. <span>{{$moment(item.end_date).format('MM/DD')}}</span>
  15. </div>
  16. <div class="flex-box-ce" v-if="item.process">
  17. <el-progress :stroke-width="3" v-if="item.process>100" color="#2879ff" :show-text="false" :width="20" type="circle" :percentage="100"></el-progress>
  18. <el-progress :stroke-width="3" v-else :show-text="false" color="#2879ff" :width="20" type="circle" :percentage="Number(item.process)"></el-progress>
  19. <span style="padding-left: 5px;">{{item.process}}%</span>
  20. </div>
  21. <div v-if="item.can_edit" style="width: 20px;height: 20px;margin-left: 30px;cursor: pointer;" @click.prevent.stop="qxGl(item)">
  22. <Tooltip preHtml="取消关联"><i class="el-icon-link"></i></Tooltip>
  23. </div>
  24. <div v-else style="width: 20px;height: 20px;margin-left: 30px;"></div>
  25. </template>
  26. </div>
  27. </div>
  28. <div class="taskBox">
  29. <template v-if="parentList.length>0">
  30. <div v-for="(item,index) in parentList" :key="index">
  31. <div class="flex-box-ce isSimpleShow">
  32. <template v-if="isParent">
  33. <i class="caret" v-if="item.statistics.plan_total>0" :class="item.isShow? 'el-icon-caret-bottom':'el-icon-caret-right'" @click="showTask(item)"></i>
  34. </template>
  35. <template v-else>
  36. <i class="caret" v-if="item.child&&item.child.length>0" :class="item.isShow? 'el-icon-caret-bottom':'el-icon-caret-right'" @click="showTask(item)"></i>
  37. </template>
  38. <Tooltip :preHtml="item.stateInfo.name"><i :class="item.stateInfo.icon" style="margin-right: 10px;"></i></Tooltip>
  39. <!-- 可操作 -->
  40. <template v-if="isSimpleShow==1">
  41. <div class="flex-1 clamp2" style="padding-right: 30px;">
  42. <Tooltip :preHtml="item.name"><span class="hoverBlue" @click.prevent.stop="openDetail(item)">{{item.name}}</span></Tooltip>
  43. </div>
  44. <div class="hover-border" @click="openSelectTime(item,2)"> <svg-icon icon-class="#icon-biaoqian_wode" class="svgIcon"></svg-icon><span>{{item.userInfo.name}}</span></div>
  45. <div class="hover-border" style="margin: 0 30px;text-align: center;width: 52px;" @click="openSelectTime(item,1)">
  46. <span>{{$moment(item.end_date).format('MM/DD')}}</span>
  47. </div>
  48. <div class="flex-box-ce" v-if="item.process">
  49. <el-progress :stroke-width="3" v-if="item.process>100" :color="customColorMethod(item.level)" :show-text="false" :width="20" type="circle" :percentage="100"></el-progress>
  50. <el-progress :stroke-width="3" v-else :show-text="false" :color="customColorMethod(item.level)" :width="20" type="circle" :percentage="Number(item.process)"></el-progress>
  51. <span style="padding-left: 5px;">{{item.process}}%</span>
  52. </div>
  53. <template v-if="item.can_stop==1||item.can_cancel==1||item.can_finish==1||item.can_reset==1||isShowBinding">
  54. <el-dropdown @command="handleCommand($event,item)" trigger="click" class="hoverBlue">
  55. <i class="el-icon-more"></i>
  56. <el-dropdown-menu slot="dropdown">
  57. <el-dropdown-item :command="1" v-if="item.can_stop==1">暂停任务</el-dropdown-item>
  58. <el-dropdown-item :command="2" v-if="item.can_cancel==1">取消任务</el-dropdown-item>
  59. <el-dropdown-item :command="3" v-if="item.can_finish==1">完成任务</el-dropdown-item>
  60. <el-dropdown-item :command="4" v-if="item.can_reset==1">重置任务</el-dropdown-item>
  61. <el-dropdown-item :command="5" v-if="isShowBinding&&item.can_edit_normal==1">取消关联</el-dropdown-item>
  62. </el-dropdown-menu>
  63. </el-dropdown>
  64. </template>
  65. <div v-else style="width: 20px;height: 20px;margin-left: 30px;"></div>
  66. </template>
  67. <!-- 不可操作 -->
  68. <template v-if="isSimpleShow==2">
  69. <div class="flex-1 clamp2" style="padding-right: 30px;">
  70. <Tooltip :preHtml="item.name"><span class="hoverBlue" @click.prevent.stop="openDetail(item)">{{item.name}}</span></Tooltip>
  71. </div>
  72. <div class="hover-border2"> <svg-icon icon-class="#icon-biaoqian_wode" class="svgIcon"></svg-icon><span>{{item.userInfo.name}}</span></div>
  73. <div class="hover-border2" style="margin: 0 30px;text-align: center;width: 52px;">
  74. <span>{{$moment(item.end_date).format('MM/DD')}}</span>
  75. </div>
  76. <div class="flex-box-ce" v-if="item.process">
  77. <el-progress :stroke-width="3" v-if="item.process>100" :color="customColorMethod(item.level)" :show-text="false" :width="20" type="circle" :percentage="100"></el-progress>
  78. <el-progress :stroke-width="3" v-else :show-text="false" :color="customColorMethod(item.level)" :width="20" type="circle" :percentage="Number(item.process)"></el-progress>
  79. <span style="padding-left: 5px;">{{item.process}}%</span>
  80. </div>
  81. <div style="width: 20px;height: 20px;margin-left: 30px;"></div>
  82. </template>
  83. <!-- 已结束 -->
  84. <template v-if="isSimpleShow==3">
  85. <div class="flex-1 clamp2 hoverBlue" @click.prevent.stop="openDetail(item)">
  86. <Tooltip :preHtml="item.name"><span>{{item.name}}</span></Tooltip>
  87. </div>
  88. <div class="hover-border2" v-if="item.composite_state==2||item.composite_state==3">
  89. <span v-if="item.day>0">剩余<span class="green">{{item.day}}</span>天</span>
  90. <span v-if="item.day<0">过期<span class="red">{{Math.abs(item.day)}}</span>天</span>
  91. </div>
  92. </template>
  93. </div>
  94. <template v-if="isParent">
  95. <TaskItem v-if="item.statistics.plan_total>0" :isShowBinding="false" :isShow="item.isShow" :isParent="isParent" :taskId="item.id" :isSimpleShow="isSimpleShow" @confirm="openDetail"></TaskItem>
  96. </template>
  97. <template v-else>
  98. <TaskItem v-if="item.child&&item.child.length>0" :isShowBinding="false" :isShow="item.isShow" :list="item.child" :isSimpleShow="isSimpleShow" @confirm="openDetail"></TaskItem>
  99. </template>
  100. </div>
  101. </template>
  102. <div v-else>
  103. <template v-if="isParent&&projects.length==0">
  104. <div class="zhu"></div>
  105. <div class="zhu"></div>
  106. </template>
  107. <template v-else>
  108. <div class="orange" v-if="projects.length==0&&parentList.length==0" style="margin-bottom: 8px;font-size: 13px;">用“项目/任务”推动目标达成,合理规划安排工作</div>
  109. </template>
  110. </div>
  111. </div>
  112. </div>
  113. </CollapseTransition>
  114. <TaskDetail v-if="isShowTaskDetail2" :visible.sync="isShowTaskDetail" :taskId="selectTaskItem.id" @confirm="closeDetail"></TaskDetail>
  115. <!-- 修改起止时间 -->
  116. <el-dialog title="修改起止时间" :visible.sync="isShowDqMyTarget" :append-to-body="true" width="600px">
  117. <div>
  118. <el-form ref="form" label-width="80px" class="form">
  119. <el-form-item label="起止时间">
  120. <el-date-picker :picker-options="instantPickerOptions" v-model="time"
  121. :clearable="false" type="datetimerange" range-separator="至" value-format="yyyy-MM-dd HH:mm:ss"
  122. start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['8:00:00', '18:00:00']"></el-date-picker>
  123. </el-form-item>
  124. </el-form>
  125. </div>
  126. <div class="flex-box-end" style="margin-top: 50px;">
  127. <el-button size="small" @click="isShowDqMyTarget = false">取 消</el-button>
  128. <el-button size="small" type="primary" @click="confirmTime">确 定</el-button>
  129. </div>
  130. </el-dialog>
  131. <!-- 选择负责人 -->
  132. <EmployeeSelector :is_filtration_creator="false" title="选择人员" :isChecKedAll="false" :isRequired="true" :multi="false" :selected="employee_selected" :visible.sync="show_employee_selector" @confirm="employee_confirm"/>
  133. </div>
  134. </template>
  135. <script>
  136. import Tooltip from '@/components/Tooltip'; //鼠标悬浮显示文字
  137. import TaskDetail from '@/okr/components/public/TaskDetail'; //任务详情
  138. import CollapseTransition from '@/okr/utils/collapse-transition';
  139. import {taskStatus} from '@/okr/utils/auth';
  140. import EmployeeSelector from '@/components/EmployeeSelector';
  141. import Progress from '@/okr/components/public/Progress'; //进度条
  142. import moment from 'moment' // 时间库
  143. export default {
  144. name:'TaskItem',
  145. components:{CollapseTransition,Tooltip,TaskDetail,EmployeeSelector,Progress},
  146. props:{
  147. isParent:{ //是否 一层层请求任务
  148. type: Boolean,
  149. default: false,
  150. },
  151. krId:{ //KrID
  152. type: Number,
  153. default: 0,
  154. },
  155. taskId:{ //任务ID
  156. type: Number,
  157. default: 0,
  158. },
  159. isShow:{
  160. type: Boolean,
  161. default: false,
  162. },
  163. isSimpleShow:{ // 1.任务里面的都可以点击操作 2.任务内容不可点击 3.只显示名称与时间
  164. type: Number,
  165. default: 1,
  166. },
  167. isShowBinding:{ //是否显示解绑
  168. type: Boolean,
  169. default: true,
  170. },
  171. list:{
  172. type:Array,
  173. default: function(){
  174. return []
  175. }
  176. },
  177. projectsList:{
  178. type:Array,
  179. default: function(){
  180. return []
  181. }
  182. },
  183. isShowChild:{ //项目的详情任务有用到
  184. type: Boolean,
  185. default: false,
  186. }
  187. },
  188. data() {
  189. return {
  190. userInfo: this.$userInfo(),
  191. parentList:[],
  192. time:[],
  193. selectTaskItem:{},
  194. isShowTaskDetail:false,
  195. isShowDqMyTarget:false,
  196. statusArr:taskStatus(),
  197. employee_selected: { dept: [], employee: [] },
  198. show_employee_selector: false,
  199. instantPickerOptions: {
  200. shortcuts: [
  201. {
  202. text: "今天",
  203. onClick(picker) {
  204. picker.$emit("pick", [`${moment().format('YYYY-MM-DD')} 08:00:00`,`${moment().format('YYYY-MM-DD')} 18:00:00`]);
  205. }
  206. },
  207. {
  208. text: "明天",
  209. onClick(picker) {
  210. picker.$emit("pick", [`${moment().add(1, "days").format('YYYY-MM-DD')} 08:00:00`,`${moment().add(1, "days").format('YYYY-MM-DD')} 18:00:00`]);
  211. }
  212. },
  213. {
  214. text: "本周",
  215. onClick(picker) {
  216. let start_date=moment().week(moment().week()).startOf('isoweek').format('YYYY-MM-DD 08:00:00')
  217. let end_date=moment().week(moment().week()).endOf('isoweek').format('YYYY-MM-DD 18:00:00')
  218. picker.$emit("pick", [start_date, end_date]);
  219. }
  220. },
  221. {
  222. text: "下周",
  223. onClick(picker) {
  224. let start_date=moment().week(moment().week() + 1).startOf('isoweek').format('YYYY-MM-DD 08:00:00')
  225. let end_date=moment().week(moment().week() + 1).endOf('isoweek').format('YYYY-MM-DD 18:00:00')
  226. picker.$emit("pick", [start_date, end_date]);
  227. }
  228. },
  229. {
  230. text: "本月",
  231. onClick(picker) {
  232. let start_date=moment().startOf('month').format('YYYY-MM-DD 08:00:00')
  233. let end_date=moment().endOf('month').format('YYYY-MM-DD 18:00:00')
  234. picker.$emit("pick", [start_date, end_date]);
  235. }
  236. },
  237. {
  238. text: "下个月",
  239. onClick(picker) {
  240. let start_date=moment().add(1, "month").startOf('month').format('YYYY-MM-DD 08:00:00')
  241. let end_date=moment().add(1, "month").endOf('month').format('YYYY-MM-DD 18:00:00')
  242. picker.$emit("pick", [start_date, end_date]);
  243. }
  244. }
  245. ]
  246. },
  247. isShowTaskDetail2:false,
  248. projects:[],
  249. };
  250. },
  251. watch: {
  252. isShow(val){
  253. if(val){
  254. this.parentList=[];
  255. if(this.isParent){ //KR进来
  256. if(!this.isShowChild){
  257. this.getTask();
  258. }else{
  259. let list=this.list;
  260. list.forEach(item=>{
  261. item.stateInfo=taskStatus(item.composite_state);
  262. item.userInfo=this.$getEmployeeMapItem(item.owner_id);
  263. item.day=this.$moment(item.end_date).diff(this.$moment().format('YYYY-MM-DD'), 'day');
  264. item.isShow=false;
  265. })
  266. // console.log("渲染了",list,this.isParent,this.isShowChild)
  267. this.parentList=list;
  268. }
  269. }else{
  270. let list=this.list;
  271. list.forEach(item=>{
  272. item.stateInfo=taskStatus(item.composite_state);
  273. item.userInfo=this.$getEmployeeMapItem(item.owner_id);
  274. item.day=this.$moment(item.end_date).diff(this.$moment().format('YYYY-MM-DD'), 'day');
  275. item.isShow=false;
  276. })
  277. this.parentList=list;
  278. this.projects=this.projectsList
  279. }
  280. }
  281. },
  282. isShowTaskDetail(val){
  283. if(!val){
  284. this.isShowTaskDetail2=false;
  285. }
  286. }
  287. },
  288. methods: {
  289. customColorMethod(index) {
  290. // if (index ==1) {
  291. return '#2879ff';
  292. // } else if (index ==2) {
  293. // return '#FF9600';
  294. // } else {
  295. // return '#F16060';
  296. // }
  297. },
  298. closeDetail(){
  299. this.$emit('confirm',{});
  300. },
  301. //取消关联
  302. deleteFeedback(item){
  303. let params={plan_id:item.id,type:2,target_type:2,target_id:item.kr_id};
  304. if(item.others.length>0&&this.krId!=item.kr_id){
  305. params.type=3;
  306. params.target_id=this.krId;
  307. }
  308. this.$axiosUser('POST', 'api/pro/okr/plan/relate/delete', params).then(res => {
  309. this.closeDetail();
  310. })
  311. },
  312. qxGl(item){
  313. this.$confirm('确定取消关联吗?','提示', {
  314. confirmButtonText: '确定',
  315. cancelButtonText: '取消',
  316. type: 'warning'
  317. }).then(() => {
  318. this.$axiosUser('POST', 'api/pro/okr/project/unbind', {project_id:item.id,kr_id:this.krId}).then(res => {
  319. this.closeDetail();
  320. })
  321. }).catch(() => {});
  322. },
  323. handleCommand(e,item){
  324. let url="";
  325. if(e==1){//暂停任务
  326. url="api/pro/okr/plan/state/stop";
  327. }else if(e==2){//取消任务
  328. url="api/pro/okr/plan/state/cancel";
  329. }else if(e==3){//完成任务
  330. url="api/pro/okr/plan/state/finish";
  331. }else if(e==4){//重置任务
  332. url="api/pro/okr/plan/state/reset";
  333. }else if(e==5){//取消关联
  334. this.$confirm('确定取消关联吗?','提示', {
  335. confirmButtonText: '确定',
  336. cancelButtonText: '取消',
  337. type: 'warning'
  338. }).then(() => {
  339. this.deleteFeedback(item);
  340. }).catch(() => {});
  341. return false
  342. }
  343. this.$axiosUser('post', url, {plan_id:item.id}).then(res => {
  344. this.closeDetail();
  345. })
  346. },
  347. employee_confirm(val){
  348. let user=val.employee[0]
  349. let params={plan_id:this.selectTaskItem.id,owner_id:user.id};
  350. this.$axiosUser('POST', 'api/pro/okr/plan/owner', params).then(res => {
  351. this.selectTaskItem.userInfo=user
  352. this.$forceUpdate();
  353. })
  354. },
  355. confirmTime(){
  356. if(!this.time||this.time.length==0){
  357. this.$message.error("请选择时间");
  358. return false
  359. }
  360. let params={
  361. plan_id:this.selectTaskItem.id,
  362. start_date:this.time[0],
  363. end_date:this.time[1],
  364. }
  365. this.$axiosUser('post', 'api/pro/okr/plan/time', params).then(res => {
  366. this.selectTaskItem.start_date=params.start_date
  367. this.selectTaskItem.end_date=params.end_date
  368. }).finally(()=>{
  369. this.isShowDqMyTarget=false;
  370. })
  371. },
  372. openSelectTime(item,index){
  373. this.selectTaskItem=item;
  374. if(index==1){
  375. this.time=[item.start_date,item.end_date]
  376. this.isShowDqMyTarget=true;
  377. }else if(index==2){
  378. this.employee_selected.employee=[item.userInfo];
  379. this.show_employee_selector=true;
  380. }
  381. },
  382. getTask(){
  383. let data={};
  384. let url={};
  385. if(this.krId){
  386. data.kr_id=this.krId
  387. url="api/pro/okr/kr/sub/list"
  388. }else{
  389. data.plan_id=this.taskId
  390. url="api/pro/okr/plan/list/sub"
  391. }
  392. this.$axiosUser('get',url,data).then(res => {
  393. let list=this.krId? res.data.data.plans:res.data.data.list;
  394. list.forEach(item=>{
  395. item.isShow=false;
  396. item.stateInfo=taskStatus(item.composite_state);
  397. item.userInfo=this.$getEmployeeMapItem(item.owner_id)
  398. })
  399. this.parentList=list;
  400. if(this.krId){
  401. this.projects=res.data.data.projects;
  402. }
  403. })
  404. },
  405. openDetail2(item){
  406. this.$router.push({path:'/projectDetail',query:{id:item.id}})
  407. },
  408. openDetail(item){
  409. if(!item.id){
  410. return false
  411. }
  412. this.selectTaskItem=item;
  413. this.isShowTaskDetail2=true;
  414. this.$nextTick(()=>{
  415. this.isShowTaskDetail=true;
  416. })
  417. },
  418. showTask(item){
  419. item.isShow=!item.isShow;
  420. },
  421. inputBlur(){
  422. this.is=!this.is
  423. }
  424. }
  425. };
  426. </script>
  427. <style scoped="scoped" lang="scss">
  428. .hover-border2{
  429. padding: 3px;
  430. border-radius: 5px;
  431. // cursor: pointer;
  432. }
  433. .isSimpleShow{
  434. padding: 4px 0;
  435. position: relative;
  436. margin-bottom: 8px;
  437. border-radius: 5px;
  438. }
  439. .isSimpleShow:hover {
  440. background-color: #f4f6f9;
  441. }
  442. .zhu{
  443. height: 14px;
  444. width: 160px;
  445. background-color: #F0F4FA;
  446. margin-bottom: 10px;
  447. border-radius: 5px;
  448. }
  449. .taskBox{
  450. padding-left: 24px;
  451. }
  452. .caret{
  453. position: absolute;
  454. width: 30px;
  455. height: 30px;
  456. text-align: center;
  457. line-height: 30px;
  458. left: -30px;
  459. top: 50%;
  460. margin-top: -15px;
  461. box-sizing: border-box;
  462. cursor: pointer;
  463. }
  464. .el-icon-more{
  465. width: 20px;
  466. height: 20px;
  467. box-sizing: border-box;
  468. text-align: center;
  469. line-height: 20px;
  470. margin-left: 30px;
  471. cursor: pointer;
  472. }
  473. .el-icon-more:hover{
  474. background-color: #606266;
  475. border-radius: 25px;
  476. color: #fff;
  477. }
  478. .dialog-task-detail ::v-deep .el-dialog__header,.dialog-task-detail ::v-deep .el-dialog__body {
  479. padding: 0px;
  480. border: none;
  481. }
  482. </style>