deviceSubtableDialog.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <el-dialog ref="dialog" :visible.sync="dialogVisible" :close-on-click-modal="false" class="form-renderer-dialog" :width="width" :top="top" :title="this.dynamicParams.editFromType" :custom-class="customClass" append-to-body @close="closeDialog">
  3. <div class="maintenanceCycle">
  4. <div class="maintenanceFont">维护周期:</div>
  5. <el-select v-model="cycleValue" clearable placeholder="请选择">
  6. <el-option
  7. v-for="item in cycleOptions"
  8. :key="item.value"
  9. :label="item.label"
  10. :value="item.value">
  11. </el-option>
  12. </el-select>
  13. </div>
  14. <div v-if="judgeShow>0" class="maintenanceCycle" style="align-items: baseline;">
  15. <div class="maintenanceFont">{{cycleOptions[judgeShow].label}}日期:</div>
  16. <div>
  17. <div v-if="judgeShow==1" class="maintenanceCycle marginNone">
  18. <el-checkbox-group style="margin-right:1%;" v-model="dayCheckList" v-for="(item,i) in weekList" :key="i">
  19. <el-checkbox class="rightMargin" :label="item"></el-checkbox>
  20. </el-checkbox-group>
  21. </div>
  22. <el-select v-if="judgeShow==2" v-model="monthDateValue" clearable placeholder="请选择">
  23. <el-option
  24. v-for="item in monthDateOptions"
  25. :key="item.value"
  26. :label="item.label"
  27. :value="item.value">
  28. </el-option>
  29. </el-select>
  30. <el-radio-group v-if="judgeShow==3" v-model="weekDateValue" >
  31. <el-radio v-for="(item,i) in weekList" :key="i" :label="item">{{item}}</el-radio>
  32. </el-radio-group>
  33. <el-select v-if="judgeShow==4" v-model="quarterDateValue" clearable placeholder="请选择">
  34. <el-option
  35. v-for="item in qmonthDateOptions"
  36. :key="item.value"
  37. :label="item.label"
  38. :value="item.value">
  39. </el-option>
  40. </el-select>
  41. <el-select v-if="judgeShow==5" v-model="midyearDateValue" clearable placeholder="请选择">
  42. <el-option
  43. v-for="item in mymonthDateOptions"
  44. :key="item.value"
  45. :label="item.label"
  46. :value="item.value">
  47. </el-option>
  48. </el-select>
  49. <el-select v-if="judgeShow==6" v-model="yearDateValue" clearable placeholder="请选择">
  50. <el-option
  51. v-for="item in ymonthDateOptions"
  52. :key="item.value"
  53. :label="item.label"
  54. :value="item.value">
  55. </el-option>
  56. </el-select>
  57. <div v-if="periodDayDate!=''&&judgeShow==1" class="describe">下次维护日期为 <span class="fontColor">{{periodDayDate}}</span></div>
  58. <div v-if="periodWeekDate!=''&&judgeShow==3" class="describe">下次维护日期为 <span class="fontColor">{{periodWeekDate}}</span></div>
  59. <div v-if="periodMonthDate!=''&&judgeShow==2" class="describe">下次维护日期为 <span class="fontColor">{{periodMonthDate}}</span></div>
  60. <div v-if="periodQuarterDate!=''&&judgeShow==4" class="describe">下次维护日期为 <span class="fontColor">{{periodQuarterDate}}</span></div>
  61. <div v-if="periodMidYearDate!=''&&judgeShow==5" class="describe">下次维护日期为 <span class="fontColor">{{periodMidYearDate}}</span></div>
  62. <div v-if="periodYearDate!=''&&judgeShow==6" class="describe">下次维护日期为 <span class="fontColor">{{periodYearDate}}</span></div>
  63. </div>
  64. </div>
  65. <div class="maintenanceCycle" style="align-items: normal;">
  66. <div class="maintenanceFont">维护项目:</div>
  67. <el-input
  68. style="width:50%;"
  69. type="textarea"
  70. placeholder="请输入内容"
  71. v-model="maintenanceTextarea"
  72. maxlength="500"
  73. show-word-limit
  74. >
  75. </el-input>
  76. </div>
  77. <div slot="footer" class="el-dialog--center">
  78. <ibps-toolbar :actions="editFromType != 'consult' ? toolbars : toolbarsConsult" @action-event="handleActionEvent" />
  79. </div>
  80. </el-dialog>
  81. </template>
  82. <script>
  83. import ActionUtils from '@/utils/action'
  84. import Vue from 'vue'
  85. // Vue.component('ibps-formrender', () => import('@/business/platform/form/formrender/index.vue'))
  86. export default {
  87. props: {
  88. visible: {
  89. type: Boolean,
  90. default: false
  91. },
  92. title: {
  93. type: String
  94. },
  95. customClass: {
  96. type: String
  97. },
  98. width: {
  99. type: String,
  100. default: '80%'
  101. },
  102. top: {
  103. type: String,
  104. default: '10%'
  105. },
  106. editFromType: {
  107. type: String,
  108. default: 'add'
  109. },
  110. dynamicParams:{
  111. type: Object
  112. },
  113. templateKey:{
  114. type: String,
  115. default: ''
  116. }
  117. },
  118. data() {
  119. const lunarGeneration = (sum)=>{
  120. let arr = []
  121. for (let i = 1; i < sum; i++) {
  122. let mid = {value:'',label:''}
  123. mid.value = '第'+i+'日'
  124. mid.label = '第'+i+'日'
  125. arr.push(mid)
  126. }
  127. return arr
  128. }
  129. const monthLunarGeneration = (sum)=>{
  130. let arr = []
  131. for (let i = 1; i < sum; i++) {
  132. let mid = {value:'',label:''}
  133. mid.value = '第'+i+'个月'
  134. mid.label = '第'+i+'个月'
  135. arr.push(mid)
  136. }
  137. return arr
  138. }
  139. const formatCurrentDate = ()=> {
  140. const today = new Date();
  141. const year = today.getFullYear();
  142. const month = (today.getMonth() + 1).toString().padStart(2, '0');
  143. const day = today.getDate().toString().padStart(2, '0');
  144. return `${year}-${month}-${day}`;
  145. }
  146. return {
  147. qrCode: '',
  148. dialogVisible: this.visible,
  149. cycleOptions: [{
  150. value: '按需保养',
  151. label: '按需保养',
  152. }, {
  153. value: '日保养',
  154. label: '日保养',
  155. }, {
  156. value: '月保养',
  157. label: '月保养'
  158. }, {
  159. value: '周保养',
  160. label: '周保养'
  161. }, {
  162. value: '季度保养',
  163. label: '季度保养'
  164. }, {
  165. value: '半年保养',
  166. label: '半年保养'
  167. }, {
  168. value: '年保养',
  169. label: '年保养'
  170. }],
  171. cycleValue: '',
  172. qmonthDateOptions:monthLunarGeneration(4),
  173. ymonthDateOptions:monthLunarGeneration(13),
  174. mymonthDateOptions:monthLunarGeneration(7),
  175. monthDateOptions: lunarGeneration(29),
  176. monthDateValue: '',
  177. weekList:['周一','周二','周三','周四','周五','周六','周日'],
  178. quarterList:[[1,2,3],[4,5,6],[7,8,9],[10,11,12]],
  179. midList:[[1,2,3,4,5,6],[7,8,9,10,11,12]],
  180. dayCheckList:['周一','周二','周三','周四','周五','周六','周日'],
  181. maintenanceTextarea:'',
  182. toolbars: [
  183. { key: 'confirm', label: '确定'},
  184. { key: 'cancel'}
  185. ],
  186. toolbarsConsult: [{ key: 'cancel' }],
  187. weekDateValue: '',
  188. quarterDateValue: '',
  189. midyearDateValue: '',
  190. yearDateValue: '',
  191. periodDayDate:'',
  192. periodWeekDate:'',
  193. periodMonthDate:'',
  194. periodQuarterDate:'',
  195. periodMidYearDate:'',
  196. periodYearDate:'',
  197. nowData:formatCurrentDate(),
  198. judgeShow:0,
  199. daysOfWeek : [7, 1, 2, 3, 4, 5, 6]
  200. }
  201. },
  202. watch: {
  203. visible: {
  204. handler: function (val, oldVal) {
  205. this.dialogVisible = this.visible
  206. },
  207. immediate: true
  208. },
  209. cycleValue: {
  210. handler: function (val, oldVal) {
  211. if(val == '日保养'){
  212. this.judgeShow = 1
  213. }else if(val == '月保养'){
  214. this.judgeShow = 2
  215. }else if(val == '周保养'){
  216. this.judgeShow = 3
  217. }else if(val == '季度保养'){
  218. this.judgeShow = 4
  219. }else if(val == '半年保养'){
  220. this.judgeShow = 5
  221. }else if(val == '年保养'){
  222. this.judgeShow = 6
  223. }else{
  224. this.judgeShow = 0
  225. }
  226. },
  227. immediate: true
  228. },
  229. dayCheckList: {
  230. handler: function (val, oldVal) {
  231. const today = new Date();
  232. const dayOfWeekNumber = this.daysOfWeek[today.getDay()];
  233. let weekNum = []
  234. val.forEach((item,i)=>{
  235. let num = this.weekList.findIndex(e=>e==item)+1
  236. weekNum.push(num)
  237. })
  238. weekNum.sort(function(a,b){
  239. return a-b;
  240. })
  241. let num = weekNum.findIndex(e=>e>dayOfWeekNumber)
  242. if(val.length>0&&num!=-1){
  243. this.periodDayDate = this.getDayDate(weekNum[num],0)
  244. }else if(val.length>0&&num==-1){
  245. this.periodDayDate = this.getDayDate(weekNum[0],1)
  246. }else{
  247. this.periodDayDate = ''
  248. }
  249. },
  250. immediate: true
  251. },
  252. weekDateValue: {
  253. handler: function (val, oldVal) {
  254. const today = new Date();
  255. const dayOfWeekNumber = this.daysOfWeek[today.getDay()];
  256. let weekNum = []
  257. let num1 = this.weekList.findIndex(e=>e==val)+1
  258. weekNum.push(num1)
  259. let num = weekNum.findIndex(e=>e>dayOfWeekNumber)
  260. if(val!=''&&num!=-1){
  261. this.periodWeekDate = this.getDayDate(weekNum[0],0)
  262. }else if(val!=''&&num==-1){
  263. this.periodWeekDate = this.getDayDate(weekNum[0],1)
  264. }else{
  265. this.periodWeekDate = ''
  266. }
  267. },
  268. immediate: true
  269. },
  270. monthDateValue:{
  271. handler: function (val, oldVal) {
  272. let turnVal = val.replace(/[^0-9]/ig, '')
  273. const today = new Date();
  274. let day = today.getDate()
  275. let nextMonth = this.getNextMonthDate(today,turnVal,1)
  276. let currentMonth = this.getNextMonthDate(today,turnVal,0)
  277. this.periodMonthDate = turnVal>day?currentMonth:nextMonth
  278. },
  279. // immediate: true
  280. },
  281. quarterDateValue:{
  282. handler: function (val, oldVal) {
  283. let turnVal = val.replace(/[^0-9]/ig, '')
  284. const today = new Date();
  285. let month = today.getMonth()+1
  286. let qu = this.getQuarter(today)
  287. let nowM = this.quarterList[qu-1][turnVal-1]
  288. let nextM = this.quarterList[qu][turnVal-1]
  289. let endMonth = month>=nowM?nextM:nowM
  290. let yearPJ = today.getFullYear()
  291. let monthPJ = endMonth>9?endMonth:'0'+endMonth
  292. this.periodQuarterDate = yearPJ +'-'+ monthPJ +'-01'
  293. },
  294. // immediate: true
  295. },
  296. midyearDateValue:{
  297. handler: function (val, oldVal) {
  298. let turnVal = val.replace(/[^0-9]/ig, '')
  299. const today = new Date();
  300. let month = today.getMonth()+1
  301. let qu = month>6?2:1
  302. let nowM = this.midList[qu-1][turnVal-1]
  303. let nextM = this.midList[qu][turnVal-1]
  304. let endMonth = month>=nowM?nextM:nowM
  305. let yearPJ = today.getFullYear()
  306. let monthPJ = endMonth>9?endMonth:'0'+endMonth
  307. this.periodMidYearDate = yearPJ +'-'+ monthPJ +'-01'
  308. },
  309. // immediate: true
  310. },
  311. yearDateValue:{
  312. handler: function (val, oldVal) {
  313. let turnVal = val.replace(/[^0-9]/ig, '')
  314. const today = new Date();
  315. let month = today.getMonth()+1
  316. let year = today.getFullYear()
  317. let qu = month>=turnVal?year+1:year
  318. let monthPJ = turnVal>9?turnVal:'0'+turnVal
  319. this.periodYearDate = qu +'-'+ monthPJ +'-01'
  320. },
  321. // immediate: true
  322. },
  323. },
  324. created(){
  325. this.loadFormData()
  326. },
  327. methods: {
  328. handleActionEvent({ key }) {
  329. switch (key) {
  330. case 'confirm':
  331. this.handleConfirm(key)
  332. break
  333. case 'cancel':
  334. this.closeDialog()
  335. break
  336. default:
  337. break
  338. }
  339. },
  340. handleConfirm(key) {
  341. let a=this.dynamicParams.formObj.getData(this.templateKey)
  342. let val = this.corresponding(this.cycleValue)
  343. let valNum = this.correspondingNum(this.cycleValue)
  344. if(this.cycleValue!='按需保养'&&this.cycleValue!=''&&val!=''&&valNum!=''&&this.maintenanceTextarea!=''){
  345. if(this.dynamicParams.position == 'manage'){
  346. this.$set(a,this.dynamicParams.params.index,{weiHuLeiXing:this.cycleValue,weiHuRiQi:val,riQiShuZi:valNum,weiHuXiangMuC:this.maintenanceTextarea})
  347. }else{
  348. a.push({weiHuLeiXing:this.cycleValue,weiHuRiQi:val,riQiShuZi:valNum,weiHuXiangMuC:this.maintenanceTextarea})
  349. }
  350. // this.$nextTick(function(){
  351. this.dynamicParams.formObj.setData(this.templateKey,a)
  352. // })
  353. this.closeDialog()
  354. }else if(this.cycleValue=='按需保养'&&this.cycleValue!=''&&this.maintenanceTextarea!=''){
  355. if(this.dynamicParams.position == 'manage'){
  356. this.$set(a,this.dynamicParams.params.index,{weiHuLeiXing:this.cycleValue,weiHuXiangMuC:this.maintenanceTextarea})
  357. }else{
  358. a.push({weiHuLeiXing:this.cycleValue,weiHuXiangMuC:this.maintenanceTextarea})
  359. }
  360. // this.$nextTick(function(){
  361. this.dynamicParams.formObj.setData(this.templateKey,a)
  362. // })
  363. this.closeDialog()
  364. }else{
  365. this.dynamicParams.formObj.$message.warning("请保证所有信息都已填写")
  366. }
  367. },
  368. corresponding(content){
  369. let that = this
  370. if(content == '日保养'){
  371. let str = '每周'
  372. let numArr = []
  373. that.dayCheckList.forEach((element,i) => {
  374. let ind = that.weekList.findIndex(item=>item===element)!=-1?that.weekList.findIndex(item=>item===element) + 1:''
  375. numArr.push(ind)
  376. });
  377. numArr.sort(function(a,b){
  378. return a-b;
  379. })
  380. numArr.forEach((element,i) => {
  381. if(i==that.dayCheckList.length-1){
  382. str = str+element
  383. }else{
  384. str = str+element+','
  385. }
  386. });
  387. return str=='每周1,2,3,4,5,6,7'?'每天':str
  388. }else if(content == '月保养'){
  389. return '每月'+that.monthDateValue
  390. }else if(content == '周保养'){
  391. let ind = that.weekList.findIndex(item=>item===that.weekDateValue)!=-1?that.weekList.findIndex(item=>item===that.weekDateValue) + 1:''
  392. return '每周'+ind
  393. }else if(content == '季度保养'){
  394. return '每季度'+that.quarterDateValue
  395. }else if(content == '半年保养'){
  396. return '每半年'+that.midyearDateValue
  397. }else if(content == '年保养'){
  398. return '每年'+that.yearDateValue
  399. }else{
  400. return ''
  401. }
  402. },
  403. correspondingNum(content){
  404. let that = this
  405. if(content == '日保养'){
  406. let str = ''
  407. let numArr = []
  408. that.dayCheckList.forEach((element,i) => {
  409. let ind = that.weekList.findIndex(item=>item===element) + 1
  410. numArr.push(ind)
  411. });
  412. numArr.sort(function(a,b){
  413. return a-b;
  414. })
  415. numArr.forEach((element,i) => {
  416. if(i==that.dayCheckList.length-1){
  417. str = str+element
  418. }else{
  419. str = str+element+','
  420. }
  421. });
  422. return str
  423. }else if(content == '月保养'){
  424. let turnVal = that.monthDateValue.replace(/[^0-9]/ig, '')
  425. return turnVal
  426. }else if(content == '周保养'){
  427. let ind = that.weekList.findIndex(item=>item===that.weekDateValue)!=-1?that.weekList.findIndex(item=>item===that.weekDateValue) + 1:''
  428. return ind
  429. }else if(content == '季度保养'){
  430. let turnVal = that.quarterDateValue.replace(/[^0-9]/ig, '')
  431. return turnVal
  432. }else if(content == '半年保养'){
  433. let turnVal = that.midyearDateValue.replace(/[^0-9]/ig, '')
  434. return turnVal
  435. }else if(content == '年保养'){
  436. let turnVal = that.yearDateValue.replace(/[^0-9]/ig, '')
  437. return turnVal
  438. }else{
  439. return ''
  440. }
  441. },
  442. assignment(content){
  443. let that = this
  444. if(content.weiHuLeiXing == '日保养'){
  445. let strArr = []
  446. let str = content.weiHuRiQi=='每天'?'1,2,3,4,5,6,7':content.weiHuRiQi.slice(2)
  447. let partArr = str.split(",")
  448. // console.log(partArr)
  449. partArr.forEach((e,i)=>{
  450. let num = e*1-1
  451. strArr.push(this.weekList[num])
  452. })
  453. this.dayCheckList = strArr
  454. }else if(content.weiHuLeiXing == '月保养'){
  455. that.monthDateValue = content.weiHuRiQi
  456. }else if(content.weiHuLeiXing == '周保养'){
  457. let str = content.weiHuRiQi.slice(2)
  458. let partArr = str.split(",")
  459. // console.log(partArr*1-1)
  460. that.weekDateValue = this.weekList[partArr*1-1]
  461. }else if(content.weiHuLeiXing == '季度保养'){
  462. that.quarterDateValue = content.weiHuRiQi.slice(3)
  463. }else if(content.weiHuLeiXing == '半年保养'){
  464. that.midyearDateValue = content.weiHuRiQi.slice(3)
  465. }else if(content.weiHuLeiXing == '年保养'){
  466. that.yearDateValue = content.weiHuRiQi.slice(2)
  467. }else{
  468. }
  469. },
  470. // 关闭当前窗口
  471. closeDialog() {
  472. this.$emit('close', false)
  473. },
  474. loadFormData() {
  475. if(this.dynamicParams.position == 'manage'){
  476. let a=this.dynamicParams.formObj.getData(this.templateKey)[this.dynamicParams.params.index]
  477. this.assignment(a)
  478. this.cycleValue = a.weiHuLeiXing
  479. this.maintenanceTextarea = a.weiHuXiangMuC
  480. }
  481. },
  482. getDayDate(type, dates) {
  483. let now = new Date();
  484. let nowTime = now.getTime();
  485. let day = now.getDay();
  486. let longTime = 24 * 60 * 60 * 1000;
  487. let n = longTime * 7 * (dates || 0);
  488. let dd = nowTime - (day - type) * longTime + n;
  489. dd = new Date(dd);
  490. let y = dd.getFullYear();
  491. let m = dd.getMonth() + 1;
  492. let d = dd.getDate();
  493. m = m < 10 ? "0" + m: m;
  494. d = d < 10 ? "0" + d: d;
  495. let daynow = y + "-" + m + "-" + d;
  496. return daynow;
  497. },
  498. //获取往后几个月相应的日期
  499. //currentDate:当前日期
  500. //dayOfMonth:获取几号
  501. //val:往后几个月
  502. getNextMonthDate(currentDate, dayOfMonth,val) {
  503. const currentYear = currentDate.getFullYear();
  504. const currentMonth = currentDate.getMonth();
  505. const nextMonth = currentMonth + val;
  506. const nextMonthDate = new Date(currentYear, nextMonth, dayOfMonth);
  507. let formattedDate = nextMonthDate.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-');
  508. return formattedDate;
  509. },
  510. //获取当前季度
  511. getQuarter(date) {
  512. return Math.floor(date.getMonth() / 3) + 1;
  513. }
  514. }
  515. }
  516. </script>
  517. <style lang="scss" >
  518. .form-renderer-dialog {
  519. .el-dialog__body {
  520. padding: 10px 0 5px 0;
  521. }
  522. .el-dialog__headerbtn {
  523. z-index: 99999;
  524. }
  525. @media print {
  526. .el-dialog__headerbtn {
  527. display: none !important;
  528. }
  529. .hidden-print {
  530. padding: 0;
  531. margin: 0;
  532. }
  533. }
  534. }
  535. .maintenanceCycle{
  536. display: flex;
  537. align-items: center;
  538. margin: 2%;
  539. }
  540. .maintenanceFont{
  541. width: 10%;
  542. }
  543. .marginNone{
  544. margin: 0;
  545. }
  546. .rightMargin{
  547. margin-right: 2.5vh !important;
  548. }
  549. .describe{
  550. margin-top: 2%;
  551. font-size: 12px;
  552. color: #808080;
  553. }
  554. .fontColor{
  555. color: #409EFF;
  556. }
  557. </style>