specTrainingPlan-deal.vue 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. <template>
  2. <el-dialog
  3. width="1500px"
  4. :title="!this.taskForm.taskId == '' ? $t('处理') : $t('详情')"
  5. :visible.sync="visible">
  6. <el-form :model="taskForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="" label-width="80px">
  7. <el-form-item label="年度计划">
  8. <el-table :data="yearplanList" border>
  9. <el-table-column label="培训员工编号" align="center" prop="staffId" :show-overflow-tooltip="true"/>
  10. <el-table-column label="培训员工" align="center" prop="staffName" :show-overflow-tooltip="true"/>
  11. <el-table-column label="年度培训标题" align="center" prop="name" :show-overflow-tooltip="true"/>
  12. <el-table-column label="年份" align="center" prop="planYear" width="100">
  13. </el-table-column>
  14. <el-table-column label="部门" align="center" prop="deptName" :show-overflow-tooltip="true"/>
  15. </el-table>
  16. </el-form-item>
  17. <el-form-item label="计划列表">
  18. <div class="barchart">
  19. <el-table
  20. :data="planList"
  21. border
  22. style="width: 100%">
  23. <el-table-column label="培训员工编号" align="center" prop="staffId" :show-overflow-tooltip="true"/>
  24. <el-table-column label="培训员工" align="center" prop="staffName" :show-overflow-tooltip="true"/>
  25. <el-table-column label="培训内容" align="center" prop="plantName" :show-overflow-tooltip="true"/>
  26. <el-table-column label="开始日期" align="center" prop="startDate" width="100">
  27. <template slot-scope="scope">
  28. <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="结束日期" align="center" prop="endDate" width="100">
  32. <template slot-scope="scope">
  33. <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
  34. </template>
  35. </el-table-column>
  36. <!-- <el-table-column label="学时" align="center" prop="classHour" :show-overflow-tooltip="true"/>-->
  37. <el-table-column label="具体内容" align="center" prop="classContent" :show-overflow-tooltip="true"/>
  38. <el-table-column :label="$t('申请状态')" align="center" prop="approveStatus" :show-overflow-tooltip="true">
  39. <template slot-scope="scope">
  40. <el-tag
  41. :type="approveStatusType(scope.row.approveStatus)"
  42. disable-transitions>{{approveStatusFormat(scope.row)}}</el-tag>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="创建人" align="center" prop="createBy" :show-overflow-tooltip="true"/>
  46. <el-table-column label="创建时间" align="center" prop="createdate" width="130">
  47. <template slot-scope="scope">
  48. <span>{{ parseTime(scope.row.createdate, '{y}-{m}-{d} {h}:{i}') }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="修改人" align="center" prop="updateBy" :show-overflow-tooltip="true"/>
  52. <el-table-column label="修改时间" align="center" prop="updatedate" width="130">
  53. <template slot-scope="scope">
  54. <span>{{ parseTime(scope.row.updatedate, '{y}-{m}-{d} {h}:{i}') }}</span>
  55. </template>
  56. </el-table-column>
  57. <!-- 渲染时间(年|月) -->
  58. <el-table-column
  59. v-if="IsShowyear"
  60. v-for="(item, index) in showMonths"
  61. :label="item.year"
  62. prop="showMonths"
  63. align="center"
  64. :key="index"
  65. >
  66. <el-table-column
  67. v-for="(it, index1) in item.months"
  68. :label="it.str"
  69. prop="str"
  70. min-width="30"
  71. style="padding: 0; margin: 0;"
  72. align="center"
  73. :key="index1"
  74. >
  75. <template slot-scope="scope" class="progressCon">
  76. <div v-if="getCellDateWidth > 0">
  77. <div
  78. v-if="index === 0 && index1 === 0 && scope.$index % 2 === 0"
  79. class="progressUpon"
  80. :style="{width:optimizeCalcWidth(scope.row),left:optimizeCalcLeft(scope.row)}"
  81. ></div>
  82. <div
  83. v-else-if="index === 0 && index1 === 0 && scope.$index % 2 !== 0"
  84. class="progressDownon"
  85. :style="{width:optimizeCalcWidth(scope.row),left:optimizeCalcLeft(scope.row)}"
  86. ></div>
  87. </div>
  88. <div v-else>
  89. <div
  90. v-if="scope.$index % 2 === 0"
  91. :class="scope.row.beginTimeStamp <= it.endTimeStamp && scope.row.endTimeStamp >= it.beginTimeStamp ? 'progressUpon' : '' "
  92. :style="{width:scope.row.beginTimeStamp <= it.endTimeStamp && scope.row.endTimeStamp >= it.beginTimeStamp ? calcwidth(scope.row,it) : '0px',left:scope.row.beginTimeStamp <= it.endTimeStamp && scope.row.endTimeStamp >= it.beginTimeStamp ? calcLeft(scope.row,it) : '0px'}"
  93. ></div>
  94. <div v-else
  95. :class="scope.row.beginTimeStamp <= it.endTimeStamp && scope.row.endTimeStamp >= it.beginTimeStamp ? 'progressDownon' : '' "
  96. :style="{width:scope.row.beginTimeStamp <= it.endTimeStamp && scope.row.endTimeStamp >= it.beginTimeStamp ? calcwidth(scope.row,it) : '0px',left:scope.row.beginTimeStamp <= it.endTimeStamp && scope.row.endTimeStamp >= it.beginTimeStamp ? calcLeft(scope.row,it) : '0px'}"
  97. ></div>
  98. </div>
  99. </template>
  100. </el-table-column>
  101. </el-table-column>
  102. <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="80">
  103. <template slot-scope="scope">
  104. <el-button
  105. size="mini"
  106. type="text"
  107. icon="el-icon-edit"
  108. @click="handleUpdate(scope.row)"
  109. v-hasPermi="['spec:plan:edit']"
  110. v-if="scope.row.editFlag != 0"
  111. >修改</el-button>
  112. </template>
  113. </el-table-column>
  114. </el-table>
  115. </div>
  116. </el-form-item>
  117. <el-row>
  118. </el-row>
  119. <el-form-item :label="$t('申请时间')" prop="creattime">
  120. <el-input v-model="dataForm.creattime" disabled></el-input>
  121. </el-form-item>
  122. <el-form-item :label="$t('审核意见')" prop="comment">
  123. <el-input v-model="taskForm.comment" :placeholder="$t('审核意见')" maxlength="100" show-word-limit></el-input>
  124. </el-form-item>
  125. </el-form>
  126. <form ref="downloadForm" :action="downloadAction" target="FORMSUBMIT">
  127. <input name="approveId" v-model="dataForm.id" hidden />
  128. <input name="processId" v-model="dataForm.processId" hidden />
  129. </form>
  130. <span slot="footer" class="dialog-footer">
  131. <el-button v-if="this.taskForm.taskId == ''" @click="visible = false">{{$t('message.return')}}</el-button>
  132. <el-button v-if="!this.taskForm.taskId == ''" type="primary" @click="dataFormSubmit(1)" :disabled="submitDisabled">{{$t('批准')}}</el-button>
  133. <el-button v-if="!this.taskForm.taskId == ''" type="danger" @click="dataFormSubmit(0)" :disabled="submitDisabled">{{$t('拒绝')}}</el-button>
  134. </span>
  135. <!-- 添加或修改培训计划对话框 -->
  136. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  137. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  138. <el-form-item label="培训员工" prop="staffId" >
  139. <el-select v-model="form.staffId" placeholder="请选择学员" disabled>
  140. <el-option
  141. v-for="successor in successorOptions"
  142. :key="successor.key"
  143. :label="successor.value"
  144. :value="successor.key"
  145. ></el-option>
  146. </el-select>
  147. </el-form-item>
  148. <el-form-item label="培训内容" prop="plantName">
  149. <el-input v-model="form.plantName" placeholder="请输入培训内容" />
  150. </el-form-item>
  151. <el-form-item label="开始日期" prop="startDate">
  152. <el-date-picker clearable size="small" style="width: 200px"
  153. v-model="form.startDate"
  154. type="date"
  155. value-format="yyyy-MM-dd"
  156. placeholder="选择开始日期">
  157. </el-date-picker>
  158. </el-form-item>
  159. <el-form-item label="结束日期" prop="endDate">
  160. <el-date-picker clearable size="small" style="width: 200px"
  161. v-model="form.endDate"
  162. type="date"
  163. value-format="yyyy-MM-dd"
  164. placeholder="选择结束日期">
  165. </el-date-picker>
  166. </el-form-item>
  167. <!-- <el-form-item label="学时" prop="classHour">-->
  168. <!-- <el-input v-model="form.classHour" placeholder="请输入学时" />-->
  169. <!-- </el-form-item>-->
  170. <el-form-item label="具体内容">
  171. <el-input
  172. type="textarea"
  173. :rows="6"
  174. placeholder="请输入内容"
  175. v-model="form.classContent">
  176. </el-input>
  177. </el-form-item>
  178. </el-form>
  179. <div slot="footer" class="dialog-footer">
  180. <el-button type="primary" @click="submitForm">确 定</el-button>
  181. <el-button @click="cancel2">取 消</el-button>
  182. </div>
  183. </el-dialog>
  184. </el-dialog>
  185. </template>
  186. <script>
  187. import {getToken} from "@/utils/auth";
  188. import {getStapproveInfo, handleApprove} from "@/api/training/spec/stapprove";
  189. import {getHistorylist} from "@/api/ehs/approvedanger";
  190. import {addPlan, getPlan, updatePlan} from "@/api/training/spec/plan";
  191. export default {
  192. name: "spec-training-plan",
  193. components: {},
  194. data() {
  195. return {
  196. loading: true,
  197. // 总条数
  198. total: 0,
  199. // 是否显示弹出层
  200. open: false,
  201. title: "",
  202. approvedangerList: [],
  203. showMonths:[],
  204. minDay:"", // 最小日期
  205. maxDay:"", // 最大日期
  206. IsShowyear:true, // 显示年|月 、 月|日
  207. // 学员列表
  208. successorOptions: [],
  209. approveStatusOptions: [],
  210. recordVisible: false,
  211. // 遮罩层
  212. historyLoading: false,
  213. //流转列表
  214. historyList: [],
  215. visible: false,
  216. planList: [],
  217. yearplanList: [],
  218. dataList: [],
  219. fileTips: '',
  220. showDelay: false,
  221. submitDisabled: false,
  222. dataListLoading:true,
  223. taskName: '',
  224. dataForm: {
  225. id: 0,
  226. userId: '',
  227. devId: '',
  228. devType: '',
  229. approveType: '',
  230. content: '',
  231. fileUrls: '',
  232. reUrls: '',
  233. status: '',
  234. creattime: '',
  235. plantCode: '',
  236. unit: '',
  237. devname: '',
  238. devno: '',
  239. files: [],
  240. delayDate: '',
  241. delayReason: '',
  242. delayMeasure: '',
  243. delayNotice: ''
  244. },
  245. taskForm: {
  246. comment: '',
  247. taskId: '',
  248. files: '',
  249. govDate: '',
  250. govFileList: []
  251. },
  252. // 查询参数
  253. queryParams: {
  254. processId: null,
  255. },
  256. doc: {
  257. file: "",
  258. // 是否显示弹出层(报告附件)
  259. open: false,
  260. // 弹出层标题(报告附件)
  261. title: "",
  262. // 是否禁用上传
  263. isUploading: false,
  264. // 是否更新已经存在的用户数据
  265. updateSupport: 0,
  266. // 报告附件上传位置编号
  267. ids: 0,
  268. // 设置上传的请求头部
  269. headers: { Authorization: "Bearer " + getToken() },
  270. // 上传的地址
  271. url: process.env.VUE_APP_BASE_API + "/sems/specfile/uploadFile",
  272. commonfileList: null,
  273. pType: 'traning',
  274. pId: null
  275. },
  276. // 表单参数
  277. form: {},
  278. // 表单校验
  279. rules: {
  280. },
  281. dataRule: {
  282. approveType: [
  283. { required: true, message: this.$t('approveType') + this.$t('notEmpty'), trigger: 'blur' }
  284. ],
  285. content: [
  286. { required: true, message: this.$t('content') + this.$t('notEmpty'), trigger: 'blur' }
  287. ]
  288. },
  289. downloadAction: process.env.VUE_APP_BASE_API +'/sems/approve/exportPDF',
  290. approveOption: [],
  291. devTypeOption: [],
  292. belong: '',
  293. fileList: [],
  294. };
  295. },
  296. watch: {
  297. // 根据名称筛选部门树
  298. deptName(val) {
  299. this.$refs.tree.filter(val);
  300. }
  301. },
  302. computed:{
  303. // 获取最小日期-月开始时间戳
  304. minDayTimeStamp() {
  305. if(this.IsShowyear){
  306. return this.showMonths[0].months[0].beginTimeStamp
  307. }else{
  308. return this.showMonths[0].days[0].daysArr[0].timestamp
  309. }
  310. },
  311. // 获取最大日期时间戳
  312. maxDayTimeStamp() {
  313. let Length = this.showMonths.length // 年有多少个
  314. // 如果显示年|月 与 月|日 是不同的
  315. if(this.IsShowyear){
  316. let monthsLength = this.showMonths[Length - 1].months.length //月有多少个
  317. return this.showMonths[Length - 1].months[monthsLength - 1].endTimeStamp
  318. }else{
  319. let daysLength = this.showMonths[Length - 1].days.length
  320. let daysarrLength = this.showMonths[Length - 1].days[daysLength - 1].daysArr.length //天有多少个
  321. return this.showMonths[Length - 1].days[daysLength - 1].daysArr[daysarrLength - 1].timestamp + 86400000 //+86400000 是因为时间戳都是0点这样+1天的时间戳,就表示最晚一天的最后的时间
  322. }
  323. },
  324. // 最大日期与最小日期的时间戳差
  325. maxAndminDayTimeStamp() {
  326. return this.maxDayTimeStamp - this.minDayTimeStamp
  327. },
  328. // 获取日期单元格宽度 => 如果返回0则只用之前第一版的计算方法
  329. getCellDateWidth() {
  330. let num = 0 // 获取日期单元格数量
  331. if(this.IsShowyear){
  332. // 月数量
  333. for(let i = 0;i < this.showMonths.length;i++){
  334. num += this.showMonths[i].months.length
  335. }
  336. }else{
  337. // 天数量
  338. for(let i = 0;i < this.showMonths.length;i++){
  339. for(let j = 0;j < this.showMonths[i].days.length;j++){
  340. num += this.showMonths[i].days[j].daysArr.length
  341. }
  342. }
  343. }
  344. // 每个单元格最小30宽度
  345. let MaxWidth = window.screen.width
  346. let CellNum = MaxWidth / 30 > 0 ? MaxWidth / 30 : 0
  347. if(num >= CellNum){ // 页面宽 / 单元格最小宽度 = 最多放下的值
  348. return num * 30
  349. }else{
  350. // 单元格的值,就不能是最小值30了
  351. // 需要获取dom的宽度,在进行计算,但是dom还未渲染完成,因此这里就不考虑了,直接只用第一版的方法动态计算
  352. // TODO
  353. return 0
  354. }
  355. }
  356. },
  357. created() {
  358. this.getDicts("spec_training_approve_status").then(response => {
  359. this.approveStatusOptions = response.data;
  360. });
  361. },
  362. methods: {
  363. init (id, taskId, processId,taskName) {
  364. this.dataForm.processId = processId
  365. this.taskName = taskName
  366. this.taskForm.taskId = taskId
  367. this.dataForm.id = id || 0
  368. this.visible = true
  369. this.queryParams.processId = processId;
  370. getHistorylist(this.queryParams).then(response => {
  371. this.historyList = response.rows;
  372. this.historyLoading = false
  373. });
  374. getStapproveInfo(id).then(response => {
  375. this.taskForm.businessKey = response.data.id
  376. this.dataForm.creattime = response.data.creattime
  377. this.planList = response.data.planList
  378. this.yearplanList = [response.data.yearplan]
  379. this.setrowspans() // 设置合并
  380. this.getChartTitle() // 渲染的信息
  381. this.$nextTick(() => {
  382. this.$refs.planTable.doLayout(); // 解决表格错位
  383. });
  384. });
  385. },
  386. // 申请状态字典翻译
  387. approveStatusFormat(row, column) {
  388. return this.selectDictLabel(this.approveStatusOptions, row.approveStatus);
  389. },
  390. approveStatusType (type) {
  391. if (type == 0) {
  392. return 'danger'
  393. }else if (type == 1) {
  394. return 'success'
  395. }else if (type == 2) {
  396. return 'danger'
  397. }else {
  398. return 'info'
  399. }
  400. },
  401. // 取消按钮
  402. cancel() {
  403. this.visible = false;
  404. this.reset();
  405. },
  406. // 表单重置
  407. reset() {
  408. this.form = {
  409. id: null,
  410. userId: null,
  411. devId: null,
  412. devType: null,
  413. approveType: null,
  414. content: null,
  415. fileUrls: null,
  416. reUrls: null,
  417. status: 0,
  418. creattime: null,
  419. endtime: null,
  420. processId: null,
  421. govDate: null,
  422. delayDate: null,
  423. delayReason: null,
  424. delayMeasure: null,
  425. delayNotice: null,
  426. apNo: null,
  427. checkDate: null,
  428. reportId: null,
  429. monthId: null,
  430. delFlag: null,
  431. deptId: null
  432. };
  433. this.resetForm("form");
  434. },
  435. /** 修改按钮操作 */
  436. handleUpdate(row) {
  437. const id = row.id || this.ids
  438. getPlan(id).then(response => {
  439. this.form = response.data;
  440. this.open = true;
  441. this.title = "修改培训计划";
  442. });
  443. },
  444. /** 提交按钮 */
  445. // 表单提交
  446. dataFormSubmit (val) {
  447. this.submitDisabled = true
  448. console.log(this.taskForm.govFileList)
  449. this.dataForm.files = []
  450. if (this.taskForm.govFileList.length > 0) {
  451. for (let i = 0; i < this.taskForm.govFileList.length; i++) {
  452. let obj = {}
  453. obj.fileName = this.taskForm.govFileList[i].response.fileName
  454. obj.fileUrl = this.taskForm.govFileList[i].response.url
  455. this.dataForm.files.push(obj)
  456. }
  457. }
  458. this.taskForm.condition = val
  459. this.taskForm.govFiles = this.dataForm.files
  460. handleApprove(this.taskForm).then(response => {
  461. this.submitDisabled = false
  462. this.msgSuccess(this.$t('处理成功'));
  463. this.visible = false;
  464. this.$emit('refreshDataList')
  465. });
  466. this.$nextTick(function () {
  467. this.taskForm.comment = ''
  468. })
  469. },
  470. /** 提交按钮 */
  471. submitForm() {
  472. this.$refs["form"].validate(valid => {
  473. if (valid) {
  474. if (this.form.id != null) {
  475. updatePlan(this.form).then(response => {
  476. this.msgSuccess("修改成功");
  477. this.open = false;
  478. getStapproveInfo(this.dataForm.id).then(response => {
  479. this.taskForm.businessKey = response.data.id
  480. this.dataForm.creattime = response.data.creattime
  481. this.planList = response.data.planList
  482. this.yearplanList = [response.data.yearplan]
  483. this.setrowspans() // 设置合并
  484. this.getChartTitle() // 渲染的信息
  485. this.$nextTick(() => {
  486. this.$refs.planTable.doLayout(); // 解决表格错位
  487. });
  488. });
  489. });
  490. }
  491. }
  492. });
  493. },
  494. /** 取消按钮 */
  495. cancel2() {
  496. this.open = false;
  497. this.reset();
  498. },
  499. optimizeCalcWidth(val) {
  500. let SumNum = this.maxAndminDayTimeStamp
  501. let diffNum = this.IsShowyear ? val.endTimeStamp - val.beginTimeStamp : val.endTimeStamp + 84600000 - val.beginTimeStamp // 结束日期 - 开始日期
  502. let rate = Math.round(diffNum / SumNum * 10000) / 100.00 //得到百分比
  503. let widthPx = this.getCellDateWidth * rate / 100.00
  504. return widthPx + 'px'
  505. },
  506. optimizeCalcLeft(val) {
  507. let SumNum = this.maxAndminDayTimeStamp
  508. let diffNum = val.beginTimeStamp - this.minDayTimeStamp // 开始日期 - 整个月开始日期
  509. let rate = Math.round(diffNum / SumNum * 10000) / 100.00 //得到百分比
  510. let leftPx = this.getCellDateWidth * rate / 100.00
  511. return leftPx + 'px'
  512. },
  513. // 计算图表的Left
  514. calcLeft(val,date) {
  515. // 如果本月的最大时间戳都没有结束时间长,那么就可判断
  516. if(val.endTimeStamp > date.endTimeStamp){
  517. // 如果本月开始日期小于开始日期
  518. if(val.beginTimeStamp > date.beginTimeStamp){
  519. // 进行判断
  520. let diffNum = date.endTimeStamp - val.beginTimeStamp
  521. let SumNum = date.endTimeStamp - date.beginTimeStamp
  522. let rate = 100 - Math.round(diffNum / SumNum * 10000) / 100.00
  523. // 位置判断
  524. return rate+"%"
  525. }
  526. }else if(val.endTimeStamp > date.beginTimeStamp && val.endTimeStamp < date.endTimeStamp){
  527. // 进行判断
  528. if(val.beginTimeStamp > date.beginTimeStamp){
  529. // 都在一个单元格中
  530. let diffNum = val.beginTimeStamp - date.beginTimeStamp
  531. let SumNum = date.endTimeStamp - date.beginTimeStamp
  532. let rate = Math.round(diffNum / SumNum * 10000) / 100.00
  533. // 位置判断
  534. return rate+"%"
  535. }
  536. }
  537. return '0px'
  538. },
  539. // 计算图表的Width
  540. calcwidth(val,date) {
  541. if(this.IsShowyear){
  542. // 如果是 年|月
  543. // 1. 如果本月的最大时间戳都没有结束时间长,那么就可设置100%
  544. // 2. 如果本月的最小时间戳比结束时间长,那么设置0
  545. // 3. 如果本月的最小时间戳没有结束时间长,那么进行判断
  546. if(val.endTimeStamp > date.endTimeStamp){
  547. // 如果本月开始日期小于开始日期
  548. if(val.beginTimeStamp > date.beginTimeStamp){
  549. // 进行判断
  550. let diffNum = val.beginTimeStamp - date.beginTimeStamp
  551. let SumNum = date.endTimeStamp - date.beginTimeStamp
  552. let rate = Math.round(diffNum / SumNum * 10000) / 100.00
  553. return 'calc('+ rate +'% + 2px)' // 结束时间超过本月最大时间戳直接+2px
  554. }
  555. return 'calc(100% + 2px)'
  556. }else if(val.endTimeStamp < date.beginTimeStamp){
  557. return '0px'
  558. }else if(val.endTimeStamp > date.beginTimeStamp && val.endTimeStamp <= date.endTimeStamp){
  559. // 进行判断
  560. if(val.beginTimeStamp > date.beginTimeStamp){
  561. // 都在一个单元格中
  562. let SumNum = date.endTimeStamp - date.beginTimeStamp // 全月多少数
  563. let diffNum = val.endTimeStamp - val.beginTimeStamp // 过程多少数
  564. diffNum = diffNum === 0 ? 86400000 : diffNum
  565. let rate = Math.round(diffNum / SumNum * 10000) / 100.00
  566. return 'calc('+ rate +'%)'
  567. }else{
  568. // 不在一个单元格中,则不需要判断任何信息
  569. let diffNum = val.endTimeStamp - date.beginTimeStamp
  570. let SumNum = date.endTimeStamp - date.beginTimeStamp
  571. let rate = Math.round(diffNum / SumNum * 10000) / 100.00
  572. return 'calc('+ rate +'%)'
  573. }
  574. }
  575. }else{
  576. // 如果是 月|日
  577. // 1.如果开始时间大于 天的时间戳,则为0
  578. // 2.如果结束时间小于 天的时间戳,则为100%
  579. if(val.beginTimeStamp > date.timestamp){
  580. return '0px'
  581. }else if(val.beginTimeStamp < date.timestamp && val.endTimeStamp > date.timestamp){
  582. return 'calc(100% + 2px)'
  583. }
  584. }
  585. return '0px'
  586. },
  587. //获得数据相同的行数(网络复制)
  588. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  589. if (columnIndex === 0) {
  590. return {
  591. rowspan: row.rowspan,
  592. colspan: 1
  593. };
  594. }
  595. },
  596. // 根据id去分组(网络复制)
  597. setrowspans() {
  598. // 先给所有的数据都加一个v.rowspan = 1
  599. this.planList.forEach(v => {
  600. v.rowspan = 1;
  601. });
  602. // 双层循环
  603. for (let i = 0; i < this.planList.length; i++) {
  604. // 内层循环,上面已经给所有的行都加了v.rowspan = 1
  605. // 这里进行判断
  606. // 如果当前行的id和下一行的id相等
  607. // 就把当前v.rowspan + 1
  608. // 下一行的v.rowspan - 1
  609. for (let j = i + 1; j < this.planList.length; j++) {
  610. //此处可根据相同字段进行合并,此处是根据的id
  611. if (this.planList[i].id === this.planList[j].id) {
  612. this.planList[i].rowspan++;
  613. this.planList[j].rowspan--;
  614. }
  615. }
  616. // 这里跳过已经重复的数据
  617. i = i + this.planList[i].rowspan - 1;
  618. }
  619. },
  620. // 渲染表格头,首先是年月,如2018年11月
  621. getChartTitle(startDate, endDate){
  622. var chartTable = this.planList;
  623. // 准备日期,为了防止多次赋值属性,导致计算属性重新计算,决定只赋值一次
  624. let maxDayParams = "",minDayParams = ""
  625. for(var i = 0; i < chartTable.length; i++){
  626. var StartDate = chartTable[i].startDate;
  627. var EndDate = chartTable[i].endDate;
  628. var mainObj = chartTable[i];
  629. // 计划日期
  630. maxDayParams === "" ? maxDayParams = EndDate : ''
  631. minDayParams === "" ? minDayParams = StartDate : ""
  632. maxDayParams = this.compareDate(EndDate,maxDayParams,true)
  633. minDayParams = this.compareDate(StartDate,minDayParams,false)
  634. var days = this.GetNumberOfDays(StartDate,EndDate) // 计算工期
  635. this.planList[i].days = days + 1 // 加一是因为没算结算当天
  636. // 记录时间戳
  637. this.planList[i].beginTimeStamp = this.getTimeStamp(StartDate)
  638. this.planList[i].endTimeStamp = this.getTimeStamp(EndDate)
  639. }
  640. this.minDay = minDayParams
  641. this.maxDay = maxDayParams
  642. console.log("小:"+this.minDay)
  643. console.log("大:"+this.maxDay)
  644. this.getYearArr()
  645. console.log(this.showMonths)
  646. },
  647. // 获取需要的格式的年月日信息
  648. getYearArr(){
  649. // 如果有一个日期相差超过366天,按照年,不超过则按天
  650. var days = this.GetNumberOfDays(this.minDay,this.maxDay)
  651. if(days >= 365){
  652. //需要记录月份
  653. this.IsShowyear = true
  654. }else{
  655. //需要记录天数
  656. this.IsShowyear = true
  657. }
  658. // 获取需要格式的年月信息
  659. let yearArr = []; // 存年
  660. let minYear = new Date(this.minDay).getFullYear();
  661. let maxYear = new Date(this.maxDay).getFullYear();
  662. // 保存年
  663. if(minYear === maxYear){
  664. yearArr.push({
  665. year: minYear+"",
  666. months: [], // 放月的数组
  667. days: []
  668. })
  669. }else{
  670. for(let i = minYear;i <= maxYear;i++){
  671. yearArr.push({
  672. year: i+"",
  673. months: [], // 放月的数组
  674. days: []
  675. })
  676. }
  677. }
  678. // 保存月
  679. for(let i = 0;i < yearArr.length;i++){
  680. let minMonth = 1
  681. if(i === 0){
  682. minMonth = new Date(this.minDay).getMonth() + 1;
  683. }
  684. // 1.eg:2016年9月 至 2019年01月
  685. // 2.如果只有一个年,那么月份就是最小月到最大月
  686. if(yearArr.length > 1){
  687. // 如果是最后一年,那么就要判断是否到最后一个月
  688. if(yearArr.length - 1 === i){
  689. let maxMonth = new Date(this.maxDay).getMonth() + 1;
  690. let _maxDay = new Date(this.maxDay).getDate() // 最大日期 天数
  691. let j = 1
  692. while(j <= maxMonth){
  693. let monthsDays = this.getLastDay(yearArr[i].year, j); // 获取月份一共有多少天
  694. let timestampstr = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-" + monthsDays)
  695. let timestampstr1 = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-01")
  696. yearArr[i].months.push({str:j+"月",num:j,endTimeStamp:timestampstr,beginTimeStamp:timestampstr1});// 记录最大最小的时间戳
  697. // 如果显示月|天 才用记录天
  698. if(!this.IsShowyear){
  699. yearArr[i].days[yearArr[i].days.length] = {year: "",month: "",daysArr: {}}
  700. yearArr[i].days[yearArr[i].days.length - 1].year = yearArr[i].year // 赋值年
  701. yearArr[i].days[yearArr[i].days.length - 1].month = j; // 赋值月
  702. yearArr[i].days[yearArr[i].days.length - 1].daysArr = []
  703. // 如果结束月,不是到本月最后一天,而是截止到最
  704. if(j === maxMonth){
  705. monthsDays = _maxDay
  706. }
  707. for(let k = 1; k <= monthsDays; k++){
  708. timestampstr = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-" + (k > 9 ? k : '0'+k))
  709. yearArr[i].days[yearArr[i].days.length - 1].daysArr.push({day: k+"",timestamp:timestampstr});// 赋值天
  710. }
  711. }
  712. j++
  713. }
  714. }else{
  715. if(i === 0){
  716. let j = minMonth
  717. let _minDay = new Date(this.minDay).getDate() // 最小日期 天数
  718. while(j <= 12){
  719. let monthsDays = this.getLastDay(yearArr[i].year, j); // 获取月份一共有多少天
  720. let timestampstr = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-" + monthsDays)
  721. let timestampstr1 = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-01")
  722. yearArr[i].months.push({str:j+"月",num:j,endTimeStamp:timestampstr,beginTimeStamp:timestampstr1});// 记录最大最小的时间戳
  723. // 如果显示月|天 才用记录天
  724. if(!this.IsShowyear){
  725. yearArr[i].days[yearArr[i].days.length] = {year: "",month: "",daysArr: {}}
  726. yearArr[i].days[yearArr[i].days.length - 1].year = yearArr[i].year // 赋值月
  727. yearArr[i].days[yearArr[i].days.length - 1].month = j // 赋值月
  728. yearArr[i].days[yearArr[i].days.length - 1].daysArr = []
  729. for(let k = 1; k <= monthsDays; k++){
  730. // 如果开始月,就不从1日开始,而是从最开始的日期那天开始算起
  731. if(k === 1 && j === minMonth){
  732. k = _minDay
  733. }
  734. timestampstr = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-" + (k > 9 ? k : '0'+k))
  735. yearArr[i].days[yearArr[i].days.length - 1].daysArr.push({day: k+"",timestamp:timestampstr});// 赋值天
  736. }
  737. }
  738. j++
  739. }
  740. }else{
  741. let j = 1
  742. while(j <= 12){
  743. let monthsDays = this.getLastDay(yearArr[i].year, j); // 获取月份一共有多少天
  744. let timestampstr = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-" + monthsDays)
  745. let timestampstr1 = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-01")
  746. yearArr[i].months.push({str:j+"月",num:j,endTimeStamp:timestampstr,beginTimeStamp:timestampstr1});// 记录最大最小的时间戳
  747. // 如果显示月|天 才用记录天
  748. if(!this.IsShowyear){
  749. yearArr[i].days[yearArr[i].days.length] = {year: "",month: "",daysArr: {}}
  750. yearArr[i].days[yearArr[i].days.length - 1].year = yearArr[i].year // 赋值年
  751. yearArr[i].days[yearArr[i].days.length - 1].month = j // 赋值月
  752. yearArr[i].days[yearArr[i].days.length - 1].daysArr = []
  753. for(let k = 1; k <= monthsDays; k++){
  754. timestampstr = this.getTimeStamp(yearArr[i].year +"-"+ (j > 9 ? j : '0'+j) + "-" + (k > 9 ? k : '0'+k))
  755. yearArr[i].days[yearArr[i].days.length - 1].daysArr.push({day: k+"",timestamp:timestampstr});// 赋值天
  756. }
  757. }
  758. j++
  759. }
  760. }
  761. }
  762. }else{
  763. // 如果只有一年那么没有必要判断是否记录天
  764. let maxMonth = new Date(this.maxDay).getMonth() + 1;
  765. let _minMonth = minMonth
  766. let _minDay = new Date(this.minDay).getDate() // 最小日期 天数
  767. let _maxDay = new Date(this.maxDay).getDate() // 最大日期 天数
  768. while(_minMonth <= maxMonth){
  769. let monthsDays = this.getLastDay(yearArr[i].year, _minMonth); // 获取月份一共有多少天
  770. let timestampstr = this.getTimeStamp(yearArr[i].year +"-"+ (_minMonth > 9 ? _minMonth : '0'+_minMonth) + "-" + monthsDays)
  771. let timestampstr1 = this.getTimeStamp(yearArr[i].year +"-"+ (_minMonth > 9 ? _minMonth : '0'+_minMonth) + "-01")
  772. yearArr[i].months.push({str:_minMonth+"月",num:_minMonth,endTimeStamp:timestampstr,beginTimeStamp:timestampstr1});// 记录最大最小的时间戳
  773. yearArr[i].days[yearArr[i].days.length] = {year: "",month: "",daysArr: {}}
  774. yearArr[i].days[yearArr[i].days.length - 1].year = yearArr[i].year // 赋值月
  775. yearArr[i].days[yearArr[i].days.length - 1].month = _minMonth // 赋值月
  776. yearArr[i].days[yearArr[i].days.length - 1].daysArr = []
  777. // 如果结束月,不是到本月最后一天,而是截止到最
  778. if(_minMonth === maxMonth){
  779. monthsDays = _maxDay
  780. }
  781. for(let k = 1; k <= monthsDays; k++){
  782. // 如果开始月,就不从1日开始,而是从最开始的日期那天开始算起
  783. if(k === 1 && _minMonth === minMonth){
  784. k = _minDay
  785. }
  786. timestampstr = this.getTimeStamp(yearArr[i].year +"-"+ (_minMonth > 9 ? _minMonth : '0'+_minMonth) + "-" + (k > 9 ? k : '0'+k))
  787. yearArr[i].days[yearArr[i].days.length - 1].daysArr.push({day: k+"",timestamp:timestampstr});// 赋值天
  788. }
  789. _minMonth++
  790. }
  791. }
  792. }
  793. this.showMonths = yearArr
  794. },
  795. // 获取月的最后一天
  796. getLastDay(myyear, mymonth){
  797. var new_date = new Date(myyear, mymonth, 0);
  798. return new_date.getDate();
  799. },
  800. // 获得天数
  801. GetNumberOfDays(date1,date2){
  802. //date1:开始日期,date2结束日期
  803. var a1 = Date.parse(new Date(date1));
  804. var a2 = Date.parse(new Date(date2));
  805. var day = parseInt((a2-a1)/ 86400000);//核心:时间戳相减,然后除以天数
  806. return day
  807. },
  808. // 时间比较 true 比大
  809. compareDate(dateTime1,dateTime2,condition = true)
  810. {
  811. var formatDate1 = new Date(dateTime1)
  812. var formatDate2 = new Date(dateTime2)
  813. if(formatDate1 >= formatDate2)
  814. {
  815. return condition ? dateTime1 : dateTime2
  816. }
  817. else
  818. {
  819. return condition ? dateTime2 : dateTime1
  820. }
  821. },
  822. // 获取时间戳
  823. getTimeStamp(val){
  824. return new Date(val).getTime()
  825. },
  826. }
  827. }
  828. </script>
  829. <style>
  830. /* 单元格padding */
  831. .barchart .el-table--border th:first-child .cell, .el-table--border td:first-child .cell{
  832. padding: 0px;
  833. }
  834. .barchart .el-table th > .cell{
  835. padding: 0px;
  836. }
  837. /* 单元格高度 */
  838. .barchart .el-table--medium th,.barchart .el-table--medium td {
  839. padding: 0px 0px !important;
  840. height: 25px !important;
  841. }
  842. .barchart .progressCon{
  843. padding: 0;
  844. margin: 0;
  845. position: relative;
  846. }
  847. .barchart .progressUpon{
  848. background: rgb(38, 84, 124);
  849. height: 1em;
  850. /* width: calc(100% + 2px); // +2是因为边框线为2px*/
  851. z-index: 2;
  852. position: absolute;
  853. top: 25%;
  854. left:0px
  855. }
  856. .barchart .progressDownon{
  857. background: rgb(255,209,102);
  858. height: 1em;
  859. /* width: calc(100% + 2px); // +2是因为边框线为2px*/
  860. z-index: 2;
  861. position: absolute;
  862. top: 25%;
  863. left:0px
  864. }
  865. </style>