Gantt.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. {{ src/components/Gantt.vue }}
  2. <template>
  3. <div>
  4. <div ref="gantt" style="height:600px;"></div>
  5. </div>
  6. </template>
  7. <script>
  8. import {gantt} from 'dhtmlx-gantt';
  9. import { notification } from 'ant-design-vue';
  10. import {getDeviceList, getJhList, getManagerList, getCgqList, saveProject} from '@/api/api'
  11. export default {
  12. name: 'gantt',
  13. // props: {
  14. // tasks: {
  15. // type: Object,
  16. // default () {
  17. // return {data: [], links: [], collections:{}}
  18. // }
  19. // }
  20. // },
  21. data () {
  22. return {
  23. tasks: {
  24. data: [
  25. ],
  26. collections: {
  27. staff:[],
  28. manager:[],
  29. chuanganqi:[],
  30. },
  31. queryParam:{
  32. weituoNo: undefined
  33. }
  34. },
  35. }
  36. },
  37. created() {
  38. // 清空数据
  39. gantt.clearAll();
  40. this.getDevicelist();
  41. this.getCgqlist();
  42. this.getManagerList();
  43. console.log(1112,this.tasks)
  44. },
  45. methods: {
  46. // 获取设备下拉列表
  47. getDevicelist(){
  48. getDeviceList().then((res) => {
  49. this.tasks.collections.staff = res.map(response =>{
  50. return {
  51. value: response.id,
  52. label: response.deviceName
  53. }
  54. })
  55. gantt.init(this.$refs.gantt);
  56. })
  57. },
  58. // 获取项目经理下拉列表
  59. getManagerList(){
  60. var query ={
  61. position: "项目经理"
  62. }
  63. getManagerList(query).then((res) => {
  64. this.tasks.collections.manager = res.map(response =>{
  65. return {
  66. key: response.name,
  67. value: response.id,
  68. label: response.name
  69. }
  70. })
  71. gantt.init(this.$refs.gantt);
  72. })
  73. },
  74. // 获取传感器下拉列表
  75. getCgqlist(){
  76. getCgqList().then((res) => {
  77. console.log(111111,res)
  78. this.tasks.collections.chuanganqi = res.map(response =>{
  79. return {
  80. key: response.id,
  81. value: response.id,
  82. label: response.xuliehao
  83. }
  84. })
  85. this.initData()
  86. })
  87. },
  88. // 通过委托编号查询检测项目
  89. getinit(queryParam){
  90. this.tasks.queryParam = queryParam
  91. getJhList(queryParam).then((res) => {
  92. console.log(17,res)
  93. this.tasks.data = []
  94. gantt.clearAll();
  95. if (res.result.length > 0 ) {
  96. this.tasks.data = res.result.map(res => {
  97. return {
  98. id: res.testItemsId,
  99. weituoId: res.weituoId,
  100. testItemsId: res.testItemsId,
  101. yangpinId:res.yangpinId,
  102. shebeiId:res.shebeiId,
  103. pm: res.pm,
  104. reportNo: res.reportNo,
  105. chuanganqi:res.chuanganqi,
  106. testPlanId:res.testPlanId,
  107. status:res.status,
  108. // text:res.reportNo,
  109. start_date: res.jihuaStartDate,
  110. // jihuaEndDate: res.jihuaEndDate,
  111. duration: res.lastTime,
  112. sampleName: res.sampleName,
  113. testItems: res.testItems,
  114. deviceName: res.deviceName,
  115. status: res.status,
  116. statusC: res.statusC
  117. }
  118. })
  119. // gantt.init(this.$refs.gantt);
  120. // // gantt.parse(this.$props.tasks);
  121. // gantt.parse(this.tasks);
  122. } else {
  123. notification.open({
  124. message: '注意',
  125. description: '该委托编号不存在',
  126. });
  127. }
  128. gantt.init(this.$refs.gantt);
  129. // gantt.parse(this.$props.tasks);
  130. gantt.parse(this.tasks);
  131. })
  132. },
  133. // 提交
  134. searchReset() {
  135. var json = gantt.serialize();
  136. console.log(json)
  137. var data = json.data.map( res => {
  138. return{
  139. weituoId: res.weituoId,
  140. testItemsId: res.testItemsId,
  141. yangpinId:res.yangpinId,
  142. shebeiId:res.shebeiId,
  143. pm: res.pm,
  144. jihuaStartDate: res.start_date,
  145. lastTime: res.duration,
  146. // jihuaEndDate: res.jihuaEndDate,
  147. reportNo: res.reportNo,
  148. chuanganqi:res.chuanganqi,
  149. testPlanId:res.testPlanId,
  150. status:res.status,
  151. testItems: res.testItems,
  152. }
  153. })
  154. console.log(data.length)
  155. if (data.length > 0) {
  156. saveProject(data).then((res) => {
  157. console.log(res)
  158. notification.open({
  159. message: '注意',
  160. description: res.message,
  161. });
  162. this.getinit(this.tasks.queryParam)
  163. })
  164. }else {
  165. notification.open({
  166. message: '注意',
  167. description: '数据为空,提交失败',
  168. });
  169. }
  170. },
  171. // // 今日线
  172. // createTodayLine() {
  173. // var dateToStr = gantt.date.date_to_str("%Y年%M%d日");
  174. // var markerId = gantt.addMarker({
  175. // id: 'markerLine',
  176. // start_date: new Date(),
  177. // css: "today",
  178. // text: "今日",
  179. // title: dateToStr(new Date())
  180. // });
  181. // gantt.updateMarker(markerId);
  182. // },
  183. // //定位到今日线
  184. // changeToday() {
  185. // this.$nextTick(() => {
  186. // let ganTT = document.getElementsByClassName('gantt_marker today')
  187. // gantt.scrollTo(ganTT[0].offsetLeft-300, null);
  188. // })
  189. // },
  190. initData(){
  191. // 启用动态加载
  192. gantt.config.branch_loading = true
  193. //日期格式化
  194. gantt.config.xml_date = "%Y-%m-%d";
  195. gantt.config.order_branch = true;
  196. gantt.config.order_branch_free = true;
  197. //左侧是否自适应
  198. gantt.config.autofit = true;
  199. gantt.config.drag_links = false;//连线
  200. gantt.config.readonly = false; //只读
  201. gantt.config.date_scale = "%m月%d日"; //右侧显示列名
  202. gantt.config.layout = {//拖拽布局
  203. css: "gantt_container",
  204. rows: [
  205. {
  206. cols: [
  207. { view: "grid", id: "grid", scrollX: "scrollHor", scrollY: "scrollVer" },
  208. { resizer: true, width: 1 },
  209. { view: "timeline", id: "timeline", scrollX: "scrollHor", scrollY: "scrollVer" },
  210. { view: "scrollbar", scroll: "y", id: "scrollVer" }
  211. ]
  212. },
  213. { view: "scrollbar", scroll: "x", id: "scrollHor", height: 20 }
  214. ],
  215. // rows: [
  216. // {
  217. // cols: [
  218. // {
  219. // width:400,
  220. // min_width: 300,
  221. // rows:[
  222. // {view: "grid", scrollX: "gridScroll", scrollable: true, scrollY: "scrollVer"},
  223. // {view: "scrollbar", id: "gridScroll", group:"horizontal"} ]
  224. // },
  225. // {resizer: true, width: 1},
  226. // {
  227. // rows:[
  228. // {view: "timeline", scrollX: "scrollHor", scrollY: "scrollVer"},
  229. // {view: "scrollbar", id: "scrollHor", group:"horizontal"} ]
  230. // },
  231. // {view: "scrollbar", id: "scrollVer"}
  232. // ]
  233. // },
  234. // ],
  235. // cols: [
  236. // {
  237. // width:400,
  238. // min_width: 300,
  239. // rows:[
  240. // {view: "grid", scrollX: "gridScroll", scrollable: true, scrollY: "scrollVer"},
  241. // {view: "scrollbar", id: "gridScroll", group:"horizontal"} ]
  242. // },
  243. // {resizer: true, width: 1},
  244. // {
  245. // rows:[
  246. // {view: "timeline", scrollX: "scrollHor", scrollY: "scrollVer"},
  247. // {view: "scrollbar", id: "scrollHor", group:"horizontal"} ]
  248. // },
  249. // {view: "scrollbar", id: "scrollVer"}
  250. // ]
  251. };
  252. // 重置布局
  253. gantt.resetLayout();
  254. gantt.config.start_on_monday = true;
  255. // 注意取消工作日!!!!(gantt.config.work_time = false;)
  256. gantt.config.work_time = false;
  257. gantt.config.fit_tasks = true; //自动调整图表坐标轴区间用于适配task的长度
  258. // 甘特图汉化
  259. gantt.locale = {
  260. date: {
  261. month_full: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
  262. month_short: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
  263. day_full: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
  264. day_short: ["日", "一", "二", "三", "四", "五", "六"]
  265. },
  266. labels: {
  267. dhx_cal_today_button: "今天",
  268. day_tab: "日",
  269. week_tab: "周",
  270. month_tab: "月",
  271. new_event: "新建日程",
  272. icon_save: "保存",
  273. icon_cancel: "关闭",
  274. icon_details: "详细",
  275. icon_edit: "编辑",
  276. icon_delete: "删除",
  277. confirm_closing: "请确认是否撤销修改!", //Your changes will be lost, are your sure?
  278. confirm_deleting: "是否删除计划?",
  279. section_description: "描述:",
  280. section_time: "时间范围:",
  281. section_type: "类型:",
  282. section_text: "计划名称:",
  283. section_test: "测试:",
  284. section_projectClass: "项目类型:",
  285. taskProjectType_0: "项目任务",
  286. taskProjectType_1: "普通任务",
  287. section_head: "项目经理:",
  288. section_device: "试验设备:",
  289. section_sensor: "传感器:",
  290. section_reportNo: "报告编号:",
  291. section_priority: '优先级:',
  292. status: '任务状态',
  293. status_0: "未确认",
  294. status_1: "已确认",
  295. status_2: "完成",
  296. status_3: "已延期",
  297. status_4: "搁置中",
  298. section_template: 'Details',
  299. /* grid columns */
  300. column_text: "计划名称",
  301. column_sampleName: "样品名称",
  302. column_testItems: "检测项目",
  303. column_start_date: "开始时间",
  304. column_duration: "持续时间",
  305. column_lastTime: "持续时间",
  306. column_add: "",
  307. column_priority: "难度",
  308. /* link confirmation */
  309. link: "关联",
  310. confirm_link_deleting: "将被删除",
  311. link_start: " (开始)",
  312. link_end: " (结束)",
  313. type_task: "任务",
  314. type_project: "项目",
  315. type_milestone: "里程碑",
  316. minutes: "分钟",
  317. hours: "小时",
  318. days: "天",
  319. weeks: "周",
  320. months: "月",
  321. years: "年"
  322. }
  323. };
  324. //定义各种编辑器及类型(可直接双击左侧进行编辑,不需要弹窗)
  325. // var textEditor = {type: "text", map_to: "text"};
  326. // var startDateEditor = {type: "date", map_to: "start_date"};
  327. // var endDateEditor = {type: "date", map_to: "end_date"};
  328. //设置甘特图中各个列相关配置
  329. // gantt.config.columns = [
  330. // {
  331. // name: 'text',
  332. // label: '项目名称',
  333. // editor: textEditor,
  334. // resize: true,
  335. // tree: true,
  336. // width: '100',
  337. // },
  338. // {
  339. // name: 'start_date',
  340. // label: '项目开始时间',
  341. // align: "center",
  342. // editor: startDateEditor,
  343. // resize:true,
  344. // tree: false,
  345. // width: '130',
  346. // },
  347. // {
  348. // name: 'end_date',
  349. // label: '项目结束时间',
  350. // width: '130',
  351. // align: 'center',
  352. // editor: endDateEditor,
  353. // resize: true,
  354. // },
  355. // ];
  356. // 左侧列表内容
  357. gantt.config.columns = [
  358. // { name: "text", min_width:100,max_width:200, label:"任务", align: "left",resize: true, tree: true },
  359. { name: "testItems", label: "检测项目", width: 130, resize: true, align: "left",resize: true, tree: true },
  360. { name: "sampleName", label: "样品名称", width: 90, resize: true, align: "center" },
  361. { name: "start_date", label: "开始时间", width: 90, resize: true, align: "center" },
  362. { name: "end_date", label: "结束时间", width: 90, resize: true, align: "center" },
  363. { name: "statusC", label: "状态", width: 60, resize: true, align: "center" },
  364. // { name: "status", label: "状态", width: 130, resize: true, align: "center",
  365. // // options: [
  366. // // { key: "0", label: gantt.locale.labels.status_0 },
  367. // // { key: "1", label: gantt.locale.labels.status_1 },
  368. // // { key: "2", label: gantt.locale.labels.status_2 },
  369. // // ],
  370. // // template:function(obj){
  371. // // console.log(obj)
  372. // // console.log(obj.status)
  373. // // let re = '';
  374. // // switch (obj.status) {
  375. // // case "0":
  376. // // re = `<b>未开始</b>`
  377. // // break;
  378. // // case "1":
  379. // // re = `<b >进行中</b>`
  380. // // break;
  381. // // case "2":
  382. // // re = `<b>已完成</b>`
  383. // // break;
  384. // // }
  385. // // return re
  386. // // }
  387. // },
  388. // { name: "add", label:"", width: 30 }
  389. ];
  390. // 更改左侧显示的结束日期时间
  391. gantt.templates.task_end_date = function(date){
  392. return gantt.templates.task_date(new Date(date.valueOf() - 1));
  393. };
  394. var gridDateToStr = gantt.date.date_to_str("%Y-%m-%d");
  395. gantt.templates.grid_date_format = function(date, column){
  396. if(column === "end_date"){
  397. return gridDateToStr(new Date(date.valueOf() - 1));
  398. }else{
  399. return gridDateToStr(date);
  400. }
  401. }
  402. // 右侧项目展示
  403. gantt.templates.task_text = function (start, end, task) {
  404. console.log(task)
  405. // return "<b>设备:</b> " + task.shebeiId + ",<b> 项目经理:</b> " + task.pm;
  406. // return "<b> 项目经理:</b> " + task.pm;
  407. // return "<b>项目经理:</b> "+ task.pm + ", <b>设备:</b> " + task.deviceName;
  408. return task.pm + ", " + task.deviceName;
  409. };
  410. //弹出层(灯箱)
  411. gantt.config.lightbox.sections = [
  412. // { name: "text", height: 30, map_to: "text", type: "textarea", focus: true, width: "*" },
  413. {
  414. name: "time", height: 40, map_to: "auto", type: "duration",
  415. time_format: ["%Y", "%m", "%d"],
  416. },
  417. {
  418. name: "reportNo", height: 30, map_to: "reportNo", type: "text", type: "textarea",focus: true,
  419. },
  420. { name: "head", height: 30, map_to: "pm", type: "select", options:gantt.serverList("manager") },
  421. {
  422. name: "device", height: 30, map_to: "shebeiId", type: "select", options: gantt.serverList('staff',[]),
  423. },
  424. {
  425. name: "sensor", height: 30, map_to: "chuanganqi", type: "checkbox", options: gantt.serverList('chuanganqi',[]),
  426. },
  427. // {
  428. // name: "sensor", height: 30, map_to: "chuanganqi", type: "multiselect", options: gantt.serverList('chuanganqi'), unassigned_value:5 ,
  429. // },
  430. // { name: "description", height: 70, map_to: "description", type: "textarea" },
  431. // {
  432. // name: "priority", height: 40, map_to: "priority", type: "radio", options: gantt.serverList("priority")
  433. // },
  434. ];
  435. // 删除灯箱中的删除按钮
  436. gantt.config.buttons_right = [];
  437. gantt.init(this.$refs.gantt);
  438. // gantt.parse(this.$props.tasks);
  439. gantt.parse(this.tasks);
  440. }
  441. }
  442. }
  443. </script>
  444. <style>
  445. @import "~dhtmlx-gantt/codebase/dhtmlxgantt.css";
  446. html, body {
  447. padding: 0px;
  448. margin: 0px;
  449. height: 100%;
  450. }
  451. #gantt_here {
  452. width:100%;
  453. height:100%;
  454. }
  455. .gantt_grid_scale .gantt_grid_head_cell,
  456. .gantt_task .gantt_task_scale .gantt_scale_cell {
  457. /* font-weight: bold; */
  458. font-size: 14px;
  459. color: rgba(0, 0, 0, 0.7);
  460. }
  461. .owner-label{
  462. width: 20px;
  463. height: 20px;
  464. line-height: 20px;
  465. font-size: 12px;
  466. display: inline-block;
  467. border: 1px solid #cccccc;
  468. border-radius: 25px;
  469. background: #e6e6e6;
  470. color: #6f6f6f;
  471. margin: 0 3px;
  472. font-weight: bold;
  473. }
  474. .gantt_cal_larea{
  475. overflow:visible;
  476. }
  477. .gantt_cal_chosen,
  478. .gantt_cal_chosen select{
  479. width: 400px;
  480. }
  481. .status{
  482. margin: 0 auto;
  483. margin-top: 5px;
  484. height: 24px;
  485. width: 65px;
  486. font-size: 12px;
  487. line-height: 24px;
  488. font-weight: bold;
  489. color: #f7fbfe;
  490. border-radius: 20px;
  491. }
  492. .color_bg_1{
  493. background-color:#60a3bc ;
  494. }
  495. .color_bg_2{
  496. background-color:#079992 ;
  497. }
  498. .color_bg_3{
  499. background-color:#78e08f ;
  500. }
  501. </style>