addPage.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. <template>
  2. <div class="timingExhaustAirAddPage">
  3. <div class="top-title-box">
  4. <p>{{propsData.id?'编辑':'新增'}}定时排风任务 </p>
  5. <p class="add-button-one-90" @click="backPage">返回</p>
  6. </div>
  7. <div class="content-max-big-box scrollbar-box">
  8. <el-form :model="formData" ref="upForm" :rules="rules">
  9. <el-form-item label="任务名称" prop="taskName" class="form-item" label-width="80px">
  10. <el-input
  11. style="width:500px;"
  12. maxlength="20"
  13. show-word-limit
  14. v-model="formData.taskName"
  15. placeholder="输入定时排风任务名称"
  16. clearable
  17. size="small"
  18. />
  19. </el-form-item>
  20. <div class="form-time-box" v-for="(item,index) in formData.exhaustPeriodVoList" :key="index">
  21. <el-form-item :label="index == 0 ?'排风时段':''" class="form-item" label-width="80px"
  22. :rules="rules.beginTime" :prop="'exhaustPeriodVoList.'+ index +'.beginTime'">
  23. <el-time-select
  24. style="width:200px;"
  25. placeholder="请选择"
  26. v-model="item.beginTime"
  27. :picker-options="{
  28. start: '00:00',
  29. step: '00:30',
  30. end: '24:00'
  31. }">
  32. </el-time-select>
  33. </el-form-item>
  34. <p style="width:48px;text-align: center">至</p>
  35. <el-form-item label="" class="form-item" label-width="0px"
  36. :rules="rules.endTime" :prop="'exhaustPeriodVoList.'+ index +'.endTime'">
  37. <el-time-select
  38. style="width:200px;"
  39. placeholder="请选择"
  40. v-model="item.endTime"
  41. :picker-options="{
  42. start: '00:00',
  43. step: '00:30',
  44. end: '24:00'
  45. }">
  46. </el-time-select>
  47. </el-form-item>
  48. <el-form-item label="" class="form-item" label-width="0px" style="margin:0 40px;">
  49. <el-radio-group v-model="item.timedType">
  50. <el-radio :label="1">工作日(周一至周五)</el-radio>
  51. <el-radio :label="2">周(周一至周日)</el-radio>
  52. <el-radio :label="3">自定义</el-radio>
  53. </el-radio-group>
  54. </el-form-item>
  55. <el-form-item label="" class="form-item" label-width="0px" v-if="item.timedType==3" style="margin-right:20px;"
  56. :rules="rules.customTime" :prop="'exhaustPeriodVoList.'+ index +'.customTime'">
  57. <el-select v-model="item.customTime" multiple placeholder="请选择"
  58. style="width: 350px;">
  59. <el-option
  60. v-for="item in options"
  61. :key="item.value"
  62. :label="item.label"
  63. :value="item.value">
  64. </el-option>
  65. </el-select>
  66. </el-form-item>
  67. <i class="el-icon-delete del-button-i" v-if="formData.exhaustPeriodVoList[1]" @click="timeListDelObj(index)"></i>
  68. </div>
  69. <p class="add-button-on" @click="timeListAddObj">+ 新增排风时段</p>
  70. <div class="form-time-box">
  71. <div class="form-title-box">
  72. <span v-show="formData.executionDateVoList[1]">*</span>
  73. <span v-show="!formData.executionDateVoList[1]"></span>
  74. <p class="form-title-p">执行日期</p>
  75. <div class="festival-box" @click="festivalButton" v-if="festival[0]">
  76. <img src="@/assets/ZDimages/personnelManagement/icon_xzqx_zc.png" v-if="formData.executionDateType!=1">
  77. <img src="@/assets/ZDimages/personnelManagement/icon_xzqx_xz.png" v-if="formData.executionDateType==1">
  78. <p>节假日不执行排风</p>
  79. </div>
  80. <p class="form-title-text" v-if="festival[0]">不指定排风日期表示所有日期均执行排风</p>
  81. <p class="form-title-text" v-if="!festival[0]">无法通过网络获取节假日,请手动填写排风日期并排除节假日。</p>
  82. </div>
  83. </div>
  84. <div class="form-period-max-box">
  85. <div class="form-period-box" v-for="(item,index) in formData.executionDateVoList">
  86. <div class="form-period-min-box">
  87. <el-form-item label="" class="form-item" label-width="0px" style="margin-right:8px;"
  88. :rules="rules.dateRange" :prop="'executionDateVoList.'+ index +'.dateRange'">
  89. <el-date-picker
  90. @change="festivalButtonPicker"
  91. :clearable="false"
  92. v-model="item.dateRange"
  93. style="width: 448px;height:40px;"
  94. value-format="yyyy-MM-dd"
  95. type="daterange"
  96. range-separator="-"
  97. start-placeholder="开始日期"
  98. end-placeholder="结束日期"
  99. ></el-date-picker>
  100. </el-form-item>
  101. <i class="el-icon-circle-plus-outline i-add-button"
  102. v-if="index == formData.executionDateVoList.length-1"
  103. @click="periodListAddObj"></i>
  104. <i class="el-icon-delete i-del-button"
  105. v-if="formData.executionDateVoList[1]"
  106. @click="periodListDelObj(index)"></i>
  107. </div>
  108. </div>
  109. <div class="form-period-box" v-if="!formData.executionDateVoList[0]">
  110. <div class="form-period-min-box" style="height:79px;">
  111. <i class="el-icon-circle-plus-outline i-add-button" style="margin-top:17px;"
  112. @click="periodListAddObj"></i>
  113. </div>
  114. </div>
  115. </div>
  116. <el-form-item label="状态" prop="exhaustType" class="form-item" label-width="80px">
  117. <el-switch
  118. @click.native="changeIsNeedCaptcha"
  119. class="switch"
  120. v-model="formData.exhaustType"
  121. :active-value="1"
  122. :inactive-value="0"
  123. active-color="#0183FA"
  124. inactive-color="#E0E0E0"
  125. active-text="启用"
  126. inactive-text="停用"
  127. disabled
  128. ></el-switch>
  129. </el-form-item>
  130. </el-form>
  131. <div class="button-max-box">
  132. <p></p>
  133. <p @click="backPage">取消</p>
  134. <p @click="subButton">确认</p>
  135. <p></p>
  136. </div>
  137. </div>
  138. </div>
  139. </template>
  140. <script>
  141. import { exhaust,getHoliday,putExhaust } from "@/api/laboratory/exhaustTime";
  142. export default {
  143. name: 'addPage',
  144. props:{
  145. propsData:{},
  146. },
  147. data() {
  148. //验证时间段时候重复
  149. const timeVerification = (rule, value, callback) => {
  150. let self = this;
  151. let index = rule.field.split('.')[1];
  152. let type = rule.field.split('.')[2]=='beginTime'?'1':(rule.field.split('.')[2]=='endTime'?'2':'');
  153. let oneList = [];
  154. let towList = [];
  155. for(let i=0;i<self.PeriodVerificationProcessing.length;i++){
  156. if(i == index){
  157. oneList = oneList.concat(self.PeriodVerificationProcessing[i])
  158. }else{
  159. towList = towList.concat(self.PeriodVerificationProcessing[i]);
  160. }
  161. }
  162. //验证时间顺序
  163. let age = 0;
  164. for(let i=0;i<oneList.length;i++){
  165. if(oneList[i].beginTime >= oneList[i].endTime){
  166. age++
  167. }
  168. }
  169. if(age != 0){
  170. callback(new Error("开始时间不能大于等于结束时间"));
  171. }
  172. //验证时间重复
  173. if(self.PeriodVerificationProcessing[1]){
  174. let num = 0;
  175. for(let i=0;i<oneList.length;i++){
  176. for(let o=0;o<towList.length;o++){
  177. if (type == 1){
  178. if(oneList[i].beginTime >= towList[o].beginTime &&
  179. oneList[i].beginTime <= towList[o].endTime ){
  180. num++
  181. }
  182. }else if(type == 2){
  183. if(oneList[i].endTime >= towList[o].beginTime &&
  184. oneList[i].endTime <= towList[o].endTime ){
  185. num++
  186. }
  187. }
  188. }
  189. }
  190. if(num != 0){
  191. callback(new Error("时间段不能重复"));
  192. }else{
  193. callback()
  194. }
  195. }else{
  196. callback()
  197. }
  198. };
  199. const dateVerification = (rule, value, callback) =>{
  200. let self = this;
  201. if(self.formData.executionDateVoList[1]){
  202. if(value[1]){
  203. callback()
  204. }else{
  205. callback(new Error("请选择执行日期"));
  206. }
  207. }
  208. let index = rule.field.split('.')[1];
  209. if(!self.DateVerificationProcessing[0]){
  210. callback()
  211. }
  212. let oneList = [];
  213. let towList = [];
  214. for(let i=0;i<self.DateVerificationProcessing.length;i++){
  215. if(i == index){
  216. oneList.push(self.DateVerificationProcessing[i])
  217. }else{
  218. towList.push(self.DateVerificationProcessing[i]);
  219. }
  220. }
  221. //验证时间重复
  222. if(self.DateVerificationProcessing[1]){
  223. let num = 0;
  224. for(let i=0;i<oneList.length;i++){
  225. for(let o=0;o<towList.length;o++){
  226. if(oneList[i].beginTime >= towList[o].beginTime &&
  227. oneList[i].beginTime <= towList[o].endTime ){
  228. num++
  229. }
  230. if(oneList[i].endTime >= towList[o].beginTime &&
  231. oneList[i].endTime <= towList[o].endTime ){
  232. num++
  233. }
  234. }
  235. }
  236. if(num != 0){
  237. callback(new Error("执行日期不能重复"));
  238. }else{
  239. callback()
  240. }
  241. }else{
  242. callback()
  243. }
  244. };
  245. return {
  246. // 表单校验
  247. rules: {
  248. taskName: [
  249. { required: true, message: "请输入任务名称", trigger: "blur" },
  250. { required: true, message: "请输入任务名称", validator: this.spaceJudgment, trigger: "blur" },
  251. ],
  252. beginTime: [
  253. { required: true, message: "请选择开始时间", trigger: "blur" },
  254. { required: true, validator: timeVerification, trigger: "blur" },
  255. ],
  256. endTime: [
  257. { required: true, message: "请选择结束时间", trigger: "blur" },
  258. { required: true, validator: timeVerification, trigger: "blur" },
  259. ],
  260. timedType: [
  261. { required: true, message: "请选择排风时段", trigger: "blur" }
  262. ],
  263. customTime: [
  264. { required: true, message: "请选择自定义时间", trigger: "blur" },
  265. ],
  266. dateRange: [
  267. { required: true, validator: dateVerification, trigger: "blur" },
  268. ],
  269. },
  270. //周数据
  271. options: [
  272. {
  273. value: '1',
  274. label: '周一'
  275. }, {
  276. value: '2',
  277. label: '周二'
  278. }, {
  279. value: '3',
  280. label: '周三'
  281. }, {
  282. value: '4',
  283. label: '周四'
  284. }, {
  285. value: '5',
  286. label: '周五'
  287. }, {
  288. value: '6',
  289. label: '周六'
  290. }, {
  291. value: '7',
  292. label: '周日'
  293. }
  294. ],
  295. //表单数据
  296. formData:{
  297. taskName:"",
  298. exhaustType:1,
  299. exhaustPeriodVoList:[
  300. {
  301. beginTime:"",
  302. endTime:"",
  303. timedType:1,
  304. customTime:"",
  305. },
  306. ],
  307. executionDateVoList:[
  308. {
  309. dateRange:[],
  310. }
  311. ]
  312. },
  313. //节日数据
  314. festival:[],
  315. //时间段验证数据
  316. PeriodVerificationProcessing:[],
  317. //不执行日期验证数据
  318. DateVerificationProcessing:[],
  319. }
  320. },
  321. created() {
  322. this.getHoliday();
  323. if(this.propsData.id){
  324. let obj = JSON.parse(JSON.stringify(this.propsData))
  325. let list = [];
  326. if(obj.executionDateVoList){
  327. for(let i=0;i<obj.executionDateVoList.length;i++){
  328. list.push({dateRange:[obj.executionDateVoList[i].beginDate,obj.executionDateVoList[i].endDate]})
  329. }
  330. }else{
  331. list = [{dateRange:[]}];
  332. }
  333. obj.executionDateVoList = list;
  334. this.$set(this,'formData',obj);
  335. }
  336. },
  337. mounted() {
  338. },
  339. methods: {
  340. //时间验证
  341. timeVerificationProcessing(){
  342. let self = this;
  343. let timeNum = 1440;
  344. let exhaustPeriodVoList = [];
  345. let executionDateVoList = [];
  346. //处理时间段验证数据
  347. for(let i=0;i<self.formData.exhaustPeriodVoList.length;i++){
  348. let newList = [];
  349. if(self.formData.exhaustPeriodVoList[i].timedType == 1){
  350. //周一至周五
  351. let beginHH = self.accMul(parseInt(self.formData.exhaustPeriodVoList[i].beginTime.split(':')[0]),60);
  352. let beginMM = parseInt(self.formData.exhaustPeriodVoList[i].beginTime.split(':')[1]);
  353. let endHH = self.accMul(parseInt(self.formData.exhaustPeriodVoList[i].endTime.split(':')[0]),60);
  354. let endMM = parseInt(self.formData.exhaustPeriodVoList[i].endTime.split(':')[1]);
  355. for(let o=0;o<5;o++){
  356. newList.push({
  357. beginTime:self.accMul(o,timeNum)+beginHH+beginMM,
  358. endTime:self.accMul(o,timeNum)+endHH+endMM,
  359. })
  360. }
  361. exhaustPeriodVoList.push(newList);
  362. }else if(self.formData.exhaustPeriodVoList[i].timedType == 2){
  363. //周一至周日
  364. let beginHH = self.accMul(parseInt(self.formData.exhaustPeriodVoList[i].beginTime.split(':')[0]),60);
  365. let beginMM = parseInt(self.formData.exhaustPeriodVoList[i].beginTime.split(':')[1]);
  366. let endHH = self.accMul(parseInt(self.formData.exhaustPeriodVoList[i].endTime.split(':')[0]),60);
  367. let endMM = parseInt(self.formData.exhaustPeriodVoList[i].endTime.split(':')[1]);
  368. for(let o=0;o<7;o++){
  369. newList.push({
  370. beginTime:self.accMul(o,timeNum)+beginHH+beginMM,
  371. endTime:self.accMul(o,timeNum)+endHH+endMM,
  372. })
  373. }
  374. exhaustPeriodVoList.push(newList);
  375. }else if(self.formData.exhaustPeriodVoList[i].timedType == 3){
  376. //自定义时间
  377. let beginHH = self.accMul(parseInt(self.formData.exhaustPeriodVoList[i].beginTime.split(':')[0]),60);
  378. let beginMM = parseInt(self.formData.exhaustPeriodVoList[i].beginTime.split(':')[1]);
  379. let endHH = self.accMul(parseInt(self.formData.exhaustPeriodVoList[i].endTime.split(':')[0]),60);
  380. let endMM = parseInt(self.formData.exhaustPeriodVoList[i].endTime.split(':')[1]);
  381. for(let o=0;o<self.formData.exhaustPeriodVoList[i].customTime.length;o++){
  382. newList.push({
  383. beginTime:self.accMul(parseInt(self.formData.exhaustPeriodVoList[i].customTime[o])-1,timeNum)+beginHH+beginMM,
  384. endTime:self.accMul(parseInt(self.formData.exhaustPeriodVoList[i].customTime[o])-1,timeNum)+endHH+endMM,
  385. })
  386. }
  387. exhaustPeriodVoList.push(newList);
  388. }
  389. }
  390. this.$set(this,'PeriodVerificationProcessing',exhaustPeriodVoList);
  391. //处理不执行日期验证数据
  392. for(let i=0;i<self.formData.executionDateVoList.length;i++){
  393. if (self.formData.executionDateVoList[i].dateRange[1]){
  394. executionDateVoList.push({
  395. beginTime : Date.parse(new Date(self.formData.executionDateVoList[i].dateRange[0]+' '+'00:00:00'))/1000,
  396. endTime : Date.parse(new Date(self.formData.executionDateVoList[i].dateRange[1]+' '+'23:59:59'))/1000
  397. })
  398. }
  399. }
  400. this.$set(this,'DateVerificationProcessing',executionDateVoList);
  401. return true;
  402. },
  403. //提交
  404. subButton(){
  405. let self = this;
  406. if(self.timeVerificationProcessing()){
  407. self.$refs["upForm"].validate(valid => {
  408. if (valid) {
  409. this.$confirm('确认提交?', "警告", {
  410. confirmButtonText: "确定",
  411. cancelButtonText: "取消",
  412. type: "warning"
  413. }).then(function() {
  414. self.upDataButton();
  415. }).then(() => {
  416. }).catch(() => {});
  417. }
  418. })
  419. }
  420. },
  421. upDataButton(){
  422. let newObj = {
  423. taskName:this.formData.taskName,
  424. exhaustType:this.formData.exhaustType,
  425. executionDateType:this.formData.executionDateType,
  426. exhaustPeriodVoList:this.formData.exhaustPeriodVoList,
  427. executionDateVoList:this.formData.executionDateVoList
  428. }
  429. if(this.formData.id){
  430. newObj.id = this.formData.id;
  431. }
  432. let obj = JSON.parse(JSON.stringify(newObj));
  433. if(newObj.executionDateVoList[0].dateRange[0]){
  434. let list = [];
  435. for(let i=0;i<newObj.executionDateVoList.length;i++){
  436. list.push({
  437. beginDate:newObj.executionDateVoList[i].dateRange[0],
  438. endDate:newObj.executionDateVoList[i].dateRange[1],
  439. })
  440. }
  441. obj.executionDateVoList = list;
  442. }else{
  443. obj.executionDateVoList = [];
  444. }
  445. for(let i=0;i<obj.exhaustPeriodVoList.length;i++){
  446. obj.exhaustPeriodVoList[i].customTime = obj.exhaustPeriodVoList[i].customTime+'';
  447. }
  448. if(obj.id){
  449. putExhaust(obj).then( response => {
  450. this.msgSuccess(response.msg);
  451. this.$parent.goPage(4,response.data.id);
  452. });
  453. }else{
  454. exhaust(obj).then( response => {
  455. this.msgSuccess(response.msg);
  456. this.$parent.goPage(4,response.data.id);
  457. });
  458. }
  459. },
  460. //启用停用状态切换
  461. changeIsNeedCaptcha(){
  462. this.formData.exhaustType = this.formData.exhaustType==1?0:1
  463. },
  464. //节日按钮
  465. festivalButton(){
  466. let self = this;
  467. if(this.formData.executionDateType==1){
  468. this.$set(this.formData,'executionDateType',0)
  469. this.$set(this.formData,'executionDateVoList',[{dateRange:[]}]);
  470. }else{
  471. let num = 0;
  472. for(let i=0;i<self.formData.executionDateVoList.length;i++){
  473. if(self.formData.executionDateVoList[i].dateRange[1]){
  474. num++
  475. }
  476. }
  477. if(num!=0){
  478. this.$confirm('确认后将覆盖下方录入的排风日期', "警告", {
  479. confirmButtonText: "确定",
  480. cancelButtonText: "取消",
  481. type: "warning"
  482. }).then(function() {
  483. self.$set(self.formData,'executionDateType',1)
  484. self.dateFormatting();
  485. }).then(() => {
  486. }).catch(() => {});
  487. }else{
  488. self.$set(this.formData,'executionDateType',1)
  489. self.dateFormatting();
  490. }
  491. }
  492. },
  493. //时间变更后重置节假日
  494. festivalButtonPicker(){
  495. this.$set(this.formData,'executionDateType',0)
  496. },
  497. //添加时段
  498. periodListAddObj(){
  499. if(this.formData.executionDateVoList.length<10){
  500. this.formData.executionDateVoList.push({
  501. dateRange:[]
  502. })
  503. this.$set(this.formData,'executionDateType',0)
  504. }else{
  505. this.msgError('最多可以增加10个执行日期')
  506. }
  507. },
  508. //删除时段
  509. periodListDelObj(index){
  510. this.formData.executionDateVoList.splice(index,1)
  511. this.$set(this.formData,'executionDateType',0)
  512. if(!this.formData.executionDateVoList[1]){
  513. this.$refs['upForm'].clearValidate('executionDateVoList.'+ '0' +'.dateRange');
  514. }
  515. },
  516. //添加时间
  517. timeListAddObj(){
  518. if(this.formData.exhaustPeriodVoList.length<6){
  519. this.formData.exhaustPeriodVoList.push({
  520. beginTime:"",
  521. endTime:"",
  522. timedType:1,
  523. customTime:"",
  524. })
  525. }else{
  526. this.msgError('最多可以增加6个排风时段')
  527. }
  528. },
  529. //删除时间
  530. timeListDelObj(index){
  531. this.formData.exhaustPeriodVoList.splice(index,1)
  532. },
  533. backPage(){
  534. this.$parent.goPage(1);
  535. },
  536. //生成排除节假日后的日期
  537. dateFormatting(){
  538. let self = this;
  539. let myDate = new Date();
  540. let year = myDate.getFullYear()
  541. let yearTow = year + 1;
  542. let age = true;
  543. let timeList = [];
  544. let beginTime = "";
  545. let endTime = "";
  546. for(let timeStamp = Date.parse(new Date(year+'/1/1'+' '+'00:00:00'))/1000;(new Date(self.accMul(timeStamp,1000)).getFullYear())<yearTow; timeStamp = timeStamp + 86400){
  547. let num = 0;
  548. for(let i=0;i<self.festival.length;i++){
  549. if(timeStamp >= self.festival[i].beginTime && timeStamp <= self.festival[i].endTime){
  550. num++
  551. }
  552. }
  553. if(num == 0){
  554. if(age){
  555. let obj = {beginTime:timeStamp}
  556. obj = JSON.parse(JSON.stringify(obj))
  557. beginTime = obj.beginTime;
  558. age = false;
  559. }
  560. endTime = timeStamp;
  561. }else{
  562. if(beginTime != ""){
  563. timeList.push(JSON.parse(JSON.stringify({dateRange:[self.timestampToTimeD(beginTime),self.timestampToTimeD(timeStamp - 1)]})));
  564. beginTime = "";
  565. age = true;
  566. }
  567. }
  568. }
  569. if(beginTime != ""){
  570. timeList.push(JSON.parse(JSON.stringify({dateRange:[self.timestampToTimeD(beginTime),self.timestampToTimeD(endTime)]})));
  571. }
  572. this.$set(this.formData,'executionDateVoList',timeList);
  573. },
  574. timestampToTimeD(timestamp) {
  575. let date = new Date(this.accMul(timestamp,1000)); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  576. let Y = date.getFullYear() + "-";//年
  577. let M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";//月
  578. let D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());//日
  579. return Y + M + D;
  580. },
  581. //获取节假日数据
  582. getHoliday(){
  583. getHoliday().then( response => {
  584. let self = this;
  585. let list = response.data
  586. for(let i=0;i<list.length;i++){
  587. list[i] = list[i]+'';
  588. list[i] = list[i].replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3")
  589. }
  590. let bigList = [];
  591. let minList = [];
  592. for(let i=0;i<list.length;i++){
  593. if(i+1 < list.length){
  594. minList.push(list[i])
  595. if(!self.daysRet(list[i],list[i+1])){
  596. if(minList[1]){
  597. // let newList = [minList[0],minList[minList.length-1]];
  598. let newList = {
  599. beginTime : Date.parse(new Date(minList[0]+' '+'00:00:00'))/1000,
  600. endTime : Date.parse(new Date(minList[minList.length-1]+' '+'23:59:59'))/1000
  601. };
  602. bigList.push(newList)
  603. }else{
  604. // let newList = [minList[0],minList[0]];
  605. let newList = {
  606. beginTime : Date.parse(new Date(minList[0]+' '+'00:00:00'))/1000,
  607. endTime : Date.parse(new Date(minList[0]+' '+'23:59:59'))/1000
  608. };
  609. bigList.push(newList)
  610. }
  611. minList = [];
  612. if(i+2 == list.length){
  613. // bigList.push([list[i+1],list[i+1]]);
  614. bigList.push({
  615. beginTime : Date.parse(new Date(list[i+1]+' '+'00:00:00'))/1000,
  616. endTime : Date.parse(new Date(list[i+1]+' '+'23:59:59'))/1000
  617. });
  618. }
  619. }else{
  620. if(i+2 == list.length){
  621. minList.push(list[i+1])
  622. // let newList = [minList[0],minList[minList.length-1]];
  623. let newList = {
  624. beginTime : Date.parse(new Date(minList[0]+' '+'00:00:00'))/1000,
  625. endTime : Date.parse(new Date(minList[minList.length-1]+' '+'23:59:59'))/1000
  626. };
  627. bigList.push(newList)
  628. minList = [];
  629. }
  630. }
  631. }
  632. }
  633. this.$set(this,'festival',bigList);
  634. });
  635. },
  636. //节假日连续判断
  637. daysRet(timeOne,timeTow){
  638. let list = [timeOne,timeTow]
  639. let days = list.sort().map((d, i) => {
  640. let dt = new Date(d)
  641. dt.setDate(dt.getDate() + 4 - i) // 处理为相同日期
  642. // 抹去 时 分 秒 毫秒
  643. dt.setHours(0)
  644. dt.setMinutes(0)
  645. dt.setSeconds(0)
  646. dt.setMilliseconds(0)
  647. return +dt
  648. })
  649. let ret = true
  650. days.forEach(d => {
  651. if (days[0] !== d) {
  652. ret = false
  653. }
  654. })
  655. return ret
  656. },
  657. //乘法
  658. accMul(arg1,arg2){
  659. var m=0,s1=arg1.toString(),s2=arg2.toString();
  660. try{m+=s1.split(".")[1].length}catch(e){}
  661. try{m+=s2.split(".")[1].length}catch(e){}
  662. return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
  663. },
  664. }
  665. }
  666. </script>
  667. <style scoped lang="scss">
  668. .timingExhaustAirAddPage{
  669. flex:1;
  670. display: flex;
  671. flex-direction: column;
  672. font-weight:500;
  673. overflow: hidden;
  674. .top-title-box{
  675. display: flex;
  676. padding:20px 0;
  677. border-bottom:1px #E0E0E0 solid;
  678. p:nth-child(1){
  679. margin-left:20px;
  680. flex:1;
  681. font-size:18px;
  682. line-height:40px;
  683. color:#0045AF;
  684. }
  685. p:nth-child(2){
  686. margin-right:20px;
  687. width:80px;
  688. }
  689. }
  690. .content-max-big-box{
  691. flex:1;
  692. display: flex;
  693. flex-direction: column;
  694. padding:40px 0 40px 80px;
  695. .form-time-box{
  696. display: flex;
  697. line-height:40px;
  698. .form-title-box{
  699. display: flex;
  700. font-size:14px;
  701. margin-top:20px;
  702. span{
  703. width:10px;
  704. color:#ff4949;
  705. margin-left:3px
  706. }
  707. .form-title-p{
  708. color:#333;
  709. margin-right:10px;
  710. }
  711. .festival-box{
  712. display: flex;
  713. margin:0 20px 0 11px;
  714. cursor: pointer;
  715. img{
  716. width:14px;
  717. height:14px;
  718. margin:13px 4px;
  719. }
  720. p{
  721. line-height:40px;
  722. }
  723. }
  724. .form-title-text{
  725. color:#CCCCCC;
  726. }
  727. }
  728. }
  729. .form-period-max-box{
  730. padding-left:80px;
  731. .form-period-box{
  732. width:544px;
  733. display: inline-block;
  734. line-height:40px;
  735. .form-period-min-box{
  736. display: flex;
  737. .i-add-button{
  738. width:40px;
  739. height:40px;
  740. line-height:40px;
  741. text-align: center;
  742. font-size:14px;
  743. cursor: pointer;
  744. color:#0183FA;
  745. }
  746. .i-del-button{
  747. width:40px;
  748. height:40px;
  749. line-height:40px;
  750. text-align: center;
  751. font-size:14px;
  752. cursor: pointer;
  753. color:#999;
  754. }
  755. }
  756. }
  757. }
  758. .add-button-on{
  759. margin-left:80px;
  760. width:448px;
  761. line-height:40px;
  762. border:1px dashed #0183FA;
  763. border-radius:4px;
  764. text-align: center;
  765. color:#0183FA;
  766. font-size:16px;
  767. cursor: pointer;
  768. }
  769. .del-button-i{
  770. width:40px;
  771. height:40px;
  772. line-height:40px;
  773. text-align: center;
  774. font-size:14px;
  775. color:#999;
  776. cursor: pointer;
  777. }
  778. .button-max-box{
  779. margin:50px 0;
  780. display: flex;
  781. p:nth-child(1){
  782. flex:1;
  783. }
  784. p:nth-child(2){
  785. width:70px;
  786. height:30px;
  787. line-height:30px;
  788. margin-right:13px;
  789. font-size:12px;
  790. color:#999999;
  791. background: #E0E0E0;
  792. border-radius:6px;
  793. text-align: center;
  794. cursor: pointer;
  795. }
  796. p:nth-child(3){
  797. width:70px;
  798. height:30px;
  799. line-height:30px;
  800. font-size:12px;
  801. color:#ffffff;
  802. background: #0045AF;
  803. border-radius:6px;
  804. text-align: center;
  805. cursor: pointer;
  806. }
  807. p:nth-child(4){
  808. flex:1;
  809. }
  810. }
  811. }
  812. }
  813. </style>