project_gantt.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. <span v-if="!reqpar1">
  28. <el-select ref="screenchg1" v-model="valuex" placeholder="请选择" size="small" style="margin-left:9px;width:200px" @change="optupdata()">
  29. <el-option
  30. v-for="item in screenList"
  31. :key="item.id"
  32. :label="item.name"
  33. :value="item.id"
  34. >
  35. </el-option>
  36. </el-select>
  37. </span>
  38. <span v-if="reqpar1">
  39. <el-select ref="screenchg2" v-model="valuex" placeholder="请选择" size="small" style="margin-left:9px;width:200px" @change="optupdata()">
  40. <el-option
  41. v-for="item in screenList"
  42. :key="item.id"
  43. :label="item.projectName"
  44. :value="item.id"
  45. >
  46. </el-option>
  47. </el-select>
  48. </span>
  49. </div>
  50. </div>
  51. <gantt v-if="isDataLoaded" ref="ganttTable1" class="left-container" :tasks="tasks"
  52. :stafforpro="radio1"
  53. :valueDate="valueDate"
  54. :key="updatakey1"></gantt>
  55. <!-- <gantt v-show="!isDataLoaded" ref="ganttTable2" class="left-container" :tasks="tasks2"
  56. :stafforpro="radio1"
  57. :valueDate="valueDate"
  58. :key="updatakey2"></gantt> -->
  59. </div>
  60. </template>
  61. <script>
  62. import { error } from 'dingtalk-jsapi';
  63. import Gantt from './gantt.vue';
  64. export default {
  65. name: 'project_gantt',
  66. components: {Gantt},
  67. data () {
  68. return {
  69. isDataLoaded:false,
  70. tasks: {
  71. data : [],
  72. // 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"}],
  73. links: [
  74. // {id: 1, source: 1, target: 2, type: '0'}
  75. ]
  76. },
  77. tasks1: {links:[]},
  78. tasks2: {links:[]},
  79. updatakey1: 1,
  80. updatakey2: -1,
  81. radio1:"按人员查看",
  82. valueDate:[],
  83. options:[{value:"选项1",label:"全部"},{value:"选项2",label:"人员1"}],
  84. valuex:'',
  85. screenList:[],
  86. // 请求参数
  87. reqpar1:0,
  88. reqpar2:[],
  89. reqpar3:"人员范围/项目范围",
  90. }
  91. },
  92. methods: {
  93. setGroup() {
  94. this.$refs.ganttTable1.setGroup();
  95. // this.$refs.ganttTable2.setGroup();
  96. },
  97. // 人员/项目切换
  98. selChange(){
  99. console.log("切换按钮");
  100. if (this.radio1 == "按人员查看") {
  101. this.reqpar1 = 0
  102. this.getList()
  103. this.getScreen()
  104. // this.tasks1 = this.tasks
  105. // this.updatakey1 += 1
  106. // this.isDataLoaded = true
  107. }else{
  108. this.reqpar1 = 1
  109. this.getList()
  110. this.getXmScreen()
  111. // this.tasks2 = this.tasks
  112. // this.updatakey2 -= 1
  113. // this.isDataLoaded = false
  114. }
  115. // console.log(this.valuex1);
  116. this.valuex == ''
  117. },
  118. // 时间段改变
  119. dateupdata(){
  120. this.reqpar2 = this.valueDate
  121. this.getList()
  122. // if (this.reqpar1 = 0) {
  123. // this.getList()
  124. // // this.tasks1 = this.tasks
  125. // // this.updatakey1 += 1
  126. // } else {
  127. // this.getList()
  128. // // this.tasks2 = this.tasks
  129. // // this.updatakey2 -= 1
  130. // }
  131. },
  132. // 人员/项目筛选改变
  133. optupdata(){
  134. this.reqpar3 = this.valuex
  135. console.log("reqpar3",this.valuex);
  136. this.getList()
  137. // if (this.reqpar1 = 0) {
  138. // console.log(this.valuex);
  139. // this.getList()
  140. // // this.updatakey1 += 1
  141. // } else {
  142. // // this.updatakey2 -= 1
  143. // }
  144. },
  145. // 获取人员项目筛选列表
  146. getScreen(){
  147. this.http.get('/project/getMyUsers',
  148. res => {
  149. if (res.code == "ok") {
  150. this.screenList = res.data
  151. }else{
  152. this.$message({
  153. message: res.msg,
  154. type: "error"
  155. });
  156. }
  157. },
  158. error => {
  159. this.$message({
  160. message : error,
  161. type : "error"
  162. })
  163. }
  164. )
  165. },
  166. getXmScreen(){
  167. this.http.get('/project/getProjectList',
  168. res => {
  169. if (res.code == "ok") {
  170. this.screenList = res.data
  171. console.log("screen",this.screenList);
  172. }else{
  173. this.$message({
  174. message: res.msg,
  175. type: "error"
  176. });
  177. }
  178. },
  179. error => {
  180. this.$message({
  181. message : error,
  182. type : "error"
  183. })
  184. }
  185. )
  186. },
  187. getList() {
  188. let getlistcs = {}
  189. if (this.valuex != ''){
  190. if (!this.reqpar1) {
  191. getlistcs = {type : 0 , startDate : this.reqpar2[0] , endDate : this.reqpar2[1], userId : this.reqpar3}
  192. }else{
  193. getlistcs = {type : 1 , startDate : this.reqpar2[0] , endDate : this.reqpar2[1], projectId : this.reqpar3}
  194. }
  195. }else{
  196. getlistcs = {type : this.reqpar1 , startDate : this.reqpar2[0] , endDate : this.reqpar2[1]}
  197. }
  198. this.http.post('/project/getGanttData', getlistcs ,
  199. res => {
  200. if (res.code == "ok") {
  201. this.tasks = {data:res.data};
  202. this.isDataLoaded = true;
  203. // console.log("getlist",res.data);
  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>