project_gantt.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. {{ src/App.vue }}
  2. <template>
  3. <div class="container">
  4. <div class="gantt_head">
  5. <div class="head_RorX">
  6. <el-radio-group v-model="radio1" @change="selChange()" size="small" style="margin-right:9px">
  7. <el-radio-button label="按人员查看" value="renyuan"></el-radio-button>
  8. <el-radio-button label="按项目查看" value="xiangmu"></el-radio-button>
  9. </el-radio-group>
  10. </div>
  11. <div class="head_date">
  12. <span>时间段</span>
  13. <el-date-picker
  14. style="margin-left:9px"
  15. size="small"
  16. v-model="valueDate"
  17. type="daterange"
  18. range-separator="至"
  19. start-placeholder="开始日期"
  20. end-placeholder="结束日期"
  21. value-format="yyyy-MM-dd"
  22. @change="dateupdata()">
  23. </el-date-picker>
  24. </div>
  25. <div class="head_select">
  26. <span>{{(this.radio1 == "按人员查看" ? "人员" : "项目")}}</span>
  27. <el-select clearable filterable v-model="valuex" placeholder="请选择" size="small" style="margin-left:9px;width:200px" @change="optupdata()">
  28. <el-option
  29. v-for="item in screenList"
  30. :key="item.id"
  31. :label="reqpar1 ? item.projectName : item.name"
  32. :value="item.id"
  33. >
  34. </el-option>
  35. </el-select>
  36. </div>
  37. </div>
  38. <gantt v-if="isDataLoaded" ref="ganttTable1" class="left-container" :tasks="tasks"
  39. :stafforpro="radio1"
  40. :valueDate="valueDate"
  41. :key="updatakey1"></gantt>
  42. <!-- <gantt v-show="!isDataLoaded" ref="ganttTable2" class="left-container" :tasks="tasks2"
  43. :stafforpro="radio1"
  44. :valueDate="valueDate"
  45. :key="updatakey2"></gantt> -->
  46. </div>
  47. </template>
  48. <script>
  49. import { error } from 'dingtalk-jsapi';
  50. import Gantt from './gantt.vue';
  51. export default {
  52. name: 'project_gantt',
  53. components: {Gantt},
  54. data () {
  55. return {
  56. isDataLoaded:false,
  57. tasks: {
  58. data : [],
  59. // data:[{"id":"7913998191517310976","userId":"7913998191517310976","text":"杨峰","duration":-19,"start_date":"2021-04-01","end_date":"2021-07-29","parent":null},{"id":"7913998191517310976_328","userId":"7913998191517310976","text":"体育场订场项目","duration":464826496,"start_date":"2021-04-01","end_date":"2021-05-31","parent":"7913998191517310976"},{"id":"7913998191517310976_363","userId":"7913998191517310976","text":"hs001","duration":24,"start_date":"2021-07-05","end_date":"2021-07-29","parent":"7913998191517310976"},{"id":"7913998535412490240","userId":"7913998535412490240","text":"吴子旭","duration":-19,"start_date":"2021-04-01","end_date":"2021-07-29","parent":null},{"id":"7913998535412490240_328","userId":"7913998535412490240","text":"体育场订场项目","duration":464826496,"start_date":"2021-04-01","end_date":"2021-05-31","parent":"7913998535412490240"},{"id":"7913998535412490240_269","userId":"7913998535412490240","text":"民族印象平面设计","duration":25,"start_date":"2021-05-05","end_date":"2021-05-30","parent":"7913998535412490240"},{"id":"7913998535412490240_363","userId":"7913998535412490240","text":"hs001","duration":24,"start_date":"2021-07-05","end_date":"2021-07-29","parent":"7913998535412490240"},{"id":"7913998867093856256","userId":"7913998867093856256","text":"张林霄","duration":-19,"start_date":"2021-04-01","end_date":"2021-07-29","parent":null},{"id":"7913998867093856256_328","userId":"7913998867093856256","text":"体育场订场项目","duration":464826496,"start_date":"2021-04-01","end_date":"2021-05-31","parent":"7913998867093856256"},{"id":"7913998867093856256_269","userId":"7913998867093856256","text":"民族印象平面设计","duration":25,"start_date":"2021-05-05","end_date":"2021-05-30","parent":"7913998867093856256"},{"id":"7913998867093856256_363","userId":"7913998867093856256","text":"hs001","duration":24,"start_date":"2021-07-05","end_date":"2021-07-29","parent":"7913998867093856256"},{"id":"7913999017669369856","userId":"7913999017669369856","text":"张海彦","duration":14,"start_date":"2021-05-05","end_date":"2021-07-29","parent":null},{"id":"7913999017669369856_269","userId":"7913999017669369856","text":"民族印象平面设计","duration":554491648,"start_date":"2021-05-05","end_date":"2021-05-30","parent":"7913999017669369856"},{"id":"7913999017669369856_363","userId":"7913999017669369856","text":"hs001","duration":24,"start_date":"2021-07-05","end_date":"2021-07-29","parent":"7913999017669369856"},{"id":"8051384341375688704","userId":"8051384341375688704","text":"徐乐","duration":14,"start_date":"2021-05-05","end_date":"2021-07-29","parent":null},{"id":"8051384341375688704_269","userId":"8051384341375688704","text":"民族印象平面设计","duration":554491648,"start_date":"2021-05-05","end_date":"2021-05-30","parent":"8051384341375688704"},{"id":"8051384341375688704_363","userId":"8051384341375688704","text":"hs001","duration":24,"start_date":"2021-07-05","end_date":"2021-07-29","parent":"8051384341375688704"},{"id":"8051387850351386624","userId":"8051387850351386624","text":"任一葱","duration":14,"start_date":"2021-05-05","end_date":"2021-07-29","parent":null},{"id":"8051387850351386624_269","userId":"8051387850351386624","text":"民族印象平面设计","duration":554491648,"start_date":"2021-05-05","end_date":"2021-05-30","parent":"8051387850351386624"},{"id":"8051387850351386624_363","userId":"8051387850351386624","text":"hs001","duration":24,"start_date":"2021-07-05","end_date":"2021-07-29","parent":"8051387850351386624"},{"id":"8051388052521033728","userId":"8051388052521033728","text":"陈润福","duration":-24,"start_date":"2021-05-05","end_date":"2021-05-30","parent":null},{"id":"8051388052521033728_269","userId":"8051388052521033728","text":"民族印象平面设计","duration":554491648,"start_date":"2021-05-05","end_date":"2021-05-30","parent":"8051388052521033728"}],
  60. links: [
  61. // {id: 1, source: 1, target: 2, type: '0'}
  62. ]
  63. },
  64. tasks1: {links:[]},
  65. tasks2: {links:[]},
  66. updatakey1: 1,
  67. updatakey2: -1,
  68. radio1:"按人员查看",
  69. valueDate:[],
  70. options:[{value:"选项1",label:"全部"},{value:"选项2",label:"人员1"}],
  71. valuex:null,
  72. screenList:[],
  73. // 请求参数
  74. reqpar1:0,
  75. reqpar2:[],
  76. // reqpar3:"人员范围/项目范围",
  77. }
  78. },
  79. methods: {
  80. setGroup() {
  81. this.$refs.ganttTable1.setGroup();
  82. // this.$refs.ganttTable2.setGroup();
  83. },
  84. // 人员/项目切换
  85. selChange(){
  86. this.valuex = null
  87. console.log("切换按钮");
  88. if (this.radio1 == "按人员查看") {
  89. this.reqpar1 = 0
  90. this.getList()
  91. this.getScreen()
  92. // this.tasks1 = this.tasks
  93. // this.updatakey1 += 1
  94. // this.isDataLoaded = true
  95. }else{
  96. this.reqpar1 = 1
  97. this.getList()
  98. this.getXmScreen()
  99. // this.tasks2 = this.tasks
  100. // this.updatakey2 -= 1
  101. // this.isDataLoaded = false
  102. }
  103. // console.log(this.valuex1);
  104. },
  105. // 时间段改变
  106. dateupdata(){
  107. this.reqpar2 = this.valueDate
  108. this.getList()
  109. // if (this.reqpar1 = 0) {
  110. // this.getList()
  111. // // this.tasks1 = this.tasks
  112. // // this.updatakey1 += 1
  113. // } else {
  114. // this.getList()
  115. // // this.tasks2 = this.tasks
  116. // // this.updatakey2 -= 1
  117. // }
  118. },
  119. // 人员/项目筛选改变
  120. optupdata(){
  121. // this.reqpar3 = this.valuex
  122. // console.log("reqpar3",this.valuex);
  123. this.getList()
  124. // if (this.reqpar1 = 0) {
  125. // console.log(this.valuex);
  126. // this.getList()
  127. // // this.updatakey1 += 1
  128. // } else {
  129. // // this.updatakey2 -= 1
  130. // }
  131. },
  132. // 获取人员项目筛选列表
  133. getScreen(){
  134. this.http.get('/project/getMyUsers',
  135. res => {
  136. if (res.code == "ok") {
  137. this.screenList = res.data
  138. }else{
  139. this.$message({
  140. message: res.msg,
  141. type: "error"
  142. });
  143. }
  144. },
  145. error => {
  146. this.$message({
  147. message : error,
  148. type : "error"
  149. })
  150. }
  151. )
  152. },
  153. getXmScreen(){
  154. this.http.get('/project/getProjectList',
  155. res => {
  156. if (res.code == "ok") {
  157. this.screenList = res.data
  158. console.log("screen",this.screenList);
  159. }else{
  160. this.$message({
  161. message: res.msg,
  162. type: "error"
  163. });
  164. }
  165. },
  166. error => {
  167. this.$message({
  168. message : error,
  169. type : "error"
  170. })
  171. }
  172. )
  173. },
  174. getList() {
  175. let getlistcs = {}
  176. if (this.valuex != null && this.valuex != ''){
  177. if (!this.reqpar1) {
  178. getlistcs = {type : 0 , startDate : this.reqpar2[0] , endDate : this.reqpar2[1], userId : this.valuex}
  179. }else{
  180. getlistcs = {type : 1 , startDate : this.reqpar2[0] , endDate : this.reqpar2[1], projectId : this.valuex}
  181. }
  182. }else{
  183. getlistcs = {type : this.reqpar1 , startDate : this.reqpar2[0] , endDate : this.reqpar2[1]}
  184. }
  185. this.http.post('/project/getGanttData', getlistcs ,
  186. res => {
  187. if (res.code == "ok") {
  188. // var list = JSON.parse(JSON.stringify(res.data));
  189. // for (let index = 0; index < list.length; index++) {
  190. // list[index].time123 = list[index].duration
  191. // }
  192. // console.log("list",list);
  193. for(var i in res.data) {
  194. if(res.data[i].id.indexOf('出差') != '-1') {
  195. res.data[i].color = '#E6A23C'
  196. }
  197. if(res.data[i].id.indexOf('请假') != '-1') {
  198. res.data[i].color = '#F56C6C'
  199. }
  200. }
  201. this.tasks = {data:res.data};
  202. this.isDataLoaded = true;
  203. // console.log("getlist",this.tasks);
  204. this.$nextTick(()=>{
  205. // if (this.reqpar1 = 0) {
  206. // this.tasks1 = this.tasks
  207. this.updatakey1 += 1
  208. // this.$refs.ganttTable1.doLayout()
  209. // } else {
  210. // this.tasks2 = this.tasks
  211. // this.updatakey2 -= 1
  212. // this.$refs.ganttTable1.doLayout()
  213. // }
  214. })
  215. } else {
  216. this.$message({
  217. message: res.msg,
  218. type: "error"
  219. });
  220. }
  221. },
  222. error => {
  223. this.$message({
  224. message: error,
  225. type: "error"
  226. });
  227. }
  228. );
  229. }
  230. },
  231. mounted: function () {
  232. let nowdate = new Date()
  233. let nowmonth = nowdate.getMonth() + 1
  234. let startdate = nowdate.getFullYear() + "-" + (nowmonth < 10 ? "0" + nowmonth : nowmonth) + "-" + (nowdate.getDate() < 10 ? "0" + nowdate.getDate() : nowdate.getDate())
  235. let udate = new Date(nowdate.getFullYear(),nowdate.getMonth(),nowdate.getDate() + 30)
  236. let endmonth = udate.getMonth() + 1
  237. let enddate = udate.getFullYear() + "-" + (endmonth < 10 ? "0" + endmonth : endmonth) + "-" + (udate.getDate() < 10 ? "0" + udate.getDate() : udate.getDate())
  238. this.valueDate = [startdate,enddate]
  239. this.reqpar2 = this.valueDate
  240. console.log("date",this.valueDate);
  241. this.getList();
  242. this.getScreen()
  243. // this.tasks1 = this.tasks
  244. this.isDataLoaded = true
  245. }
  246. }
  247. </script>
  248. <style>
  249. /* html, body {
  250. height: 100%;
  251. margin: 0;
  252. padding: 0;
  253. } */
  254. .container {
  255. height: 100%;
  256. width: 100%;
  257. }
  258. .left-container {
  259. overflow: hidden;
  260. position: relative;
  261. height: 90%;
  262. }
  263. .gantt_head{
  264. width: 100%;
  265. height: 60px;
  266. display: flex;
  267. justify-content: left;
  268. align-items: center;
  269. }
  270. .gantt_head .head_RorX{
  271. height: 60px;
  272. line-height: 60px;
  273. width: 30%;
  274. display: flex;
  275. align-items: center;
  276. justify-content: left;
  277. }
  278. .gantt_head .head_date{
  279. height: 60px;
  280. line-height: 60px;
  281. width: 35%;
  282. display: flex;
  283. align-items: center;
  284. justify-content: left;
  285. }
  286. .gantt_head .head_select{
  287. height: 60px;
  288. line-height: 60px;
  289. width: 30%;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. }
  294. </style>