deviceSubtableDialog.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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. let num = weekNum.findIndex(e=>e>dayOfWeekNumber)
  239. if(val.length>0&&num!=-1){
  240. this.periodDayDate = this.getDayDate(weekNum[num],0)
  241. }else if(val.length>0&&num==-1){
  242. this.periodDayDate = this.getDayDate(weekNum[0],1)
  243. }else{
  244. this.periodDayDate = ''
  245. }
  246. },
  247. immediate: true
  248. },
  249. weekDateValue: {
  250. handler: function (val, oldVal) {
  251. const today = new Date();
  252. const dayOfWeekNumber = this.daysOfWeek[today.getDay()];
  253. let weekNum = []
  254. let num1 = this.weekList.findIndex(e=>e==val)+1
  255. weekNum.push(num1)
  256. let num = weekNum.findIndex(e=>e>dayOfWeekNumber)
  257. if(val!=''&&num!=-1){
  258. this.periodWeekDate = this.getDayDate(weekNum[0],0)
  259. }else if(val!=''&&num==-1){
  260. this.periodWeekDate = this.getDayDate(weekNum[0],1)
  261. }else{
  262. this.periodWeekDate = ''
  263. }
  264. },
  265. immediate: true
  266. },
  267. monthDateValue:{
  268. handler: function (val, oldVal) {
  269. let turnVal = val.replace(/[^0-9]/ig, '')
  270. const today = new Date();
  271. let day = today.getDate()
  272. let nextMonth = this.getNextMonthDate(today,turnVal,1)
  273. let currentMonth = this.getNextMonthDate(today,turnVal,0)
  274. this.periodMonthDate = turnVal>day?currentMonth:nextMonth
  275. },
  276. // immediate: true
  277. },
  278. quarterDateValue:{
  279. handler: function (val, oldVal) {
  280. let turnVal = val.replace(/[^0-9]/ig, '')
  281. const today = new Date();
  282. let month = today.getMonth()+1
  283. let qu = this.getQuarter(today)
  284. let nowM = this.quarterList[qu-1][turnVal-1]
  285. let nextM = this.quarterList[qu][turnVal-1]
  286. let endMonth = month>=nowM?nextM:nowM
  287. let yearPJ = today.getFullYear()
  288. let monthPJ = endMonth>9?endMonth:'0'+endMonth
  289. this.periodQuarterDate = yearPJ +'-'+ monthPJ +'-01'
  290. },
  291. // immediate: true
  292. },
  293. midyearDateValue:{
  294. handler: function (val, oldVal) {
  295. let turnVal = val.replace(/[^0-9]/ig, '')
  296. const today = new Date();
  297. let month = today.getMonth()+1
  298. let qu = month>6?2:1
  299. let nowM = this.midList[qu-1][turnVal-1]
  300. let nextM = this.midList[qu][turnVal-1]
  301. let endMonth = month>=nowM?nextM:nowM
  302. let yearPJ = today.getFullYear()
  303. let monthPJ = endMonth>9?endMonth:'0'+endMonth
  304. this.periodMidYearDate = yearPJ +'-'+ monthPJ +'-01'
  305. },
  306. // immediate: true
  307. },
  308. yearDateValue:{
  309. handler: function (val, oldVal) {
  310. let turnVal = val.replace(/[^0-9]/ig, '')
  311. const today = new Date();
  312. let month = today.getMonth()+1
  313. let year = today.getFullYear()
  314. let qu = month>=turnVal?year+1:year
  315. let monthPJ = turnVal>9?turnVal:'0'+turnVal
  316. this.periodYearDate = qu +'-'+ monthPJ +'-01'
  317. },
  318. // immediate: true
  319. },
  320. },
  321. created(){
  322. this.loadFormData()
  323. },
  324. methods: {
  325. handleActionEvent({ key }) {
  326. switch (key) {
  327. case 'confirm':
  328. this.handleConfirm(key)
  329. break
  330. case 'cancel':
  331. this.closeDialog()
  332. break
  333. default:
  334. break
  335. }
  336. },
  337. handleConfirm(key) {
  338. let a=this.dynamicParams.formObj.getData(this.templateKey)
  339. let val = this.corresponding(this.cycleValue)
  340. let valNum = this.correspondingNum(this.cycleValue)
  341. if(this.cycleValue!='按需保养'&&this.cycleValue!=''&&val!=''&&valNum!=''&&this.maintenanceTextarea!=''){
  342. if(this.dynamicParams.position == 'manage'){
  343. this.$set(a,this.dynamicParams.params.index,{weiHuLeiXing:this.cycleValue,weiHuRiQi:val,riQiShuZi:valNum,weiHuXiangMuC:this.maintenanceTextarea})
  344. }else{
  345. a.push({weiHuLeiXing:this.cycleValue,weiHuRiQi:val,riQiShuZi:valNum,weiHuXiangMuC:this.maintenanceTextarea})
  346. }
  347. // this.$nextTick(function(){
  348. this.dynamicParams.formObj.setData(this.templateKey,a)
  349. // })
  350. this.closeDialog()
  351. }else if(this.cycleValue=='按需保养'&&this.cycleValue!=''&&this.maintenanceTextarea!=''){
  352. if(this.dynamicParams.position == 'manage'){
  353. this.$set(a,this.dynamicParams.params.index,{weiHuLeiXing:this.cycleValue,weiHuXiangMuC:this.maintenanceTextarea})
  354. }else{
  355. a.push({weiHuLeiXing:this.cycleValue,weiHuXiangMuC:this.maintenanceTextarea})
  356. }
  357. // this.$nextTick(function(){
  358. this.dynamicParams.formObj.setData(this.templateKey,a)
  359. // })
  360. this.closeDialog()
  361. }else{
  362. this.dynamicParams.formObj.$message.warning("请保证所有信息都已填写")
  363. }
  364. },
  365. corresponding(content){
  366. let that = this
  367. if(content == '日保养'){
  368. let str = '每周'
  369. let numArr = []
  370. that.dayCheckList.forEach((element,i) => {
  371. let ind = that.weekList.findIndex(item=>item===element)!=-1?that.weekList.findIndex(item=>item===element) + 1:''
  372. numArr.push(ind)
  373. });
  374. numArr.sort(function(a,b){
  375. return a-b;
  376. })
  377. numArr.forEach((element,i) => {
  378. if(i==that.dayCheckList.length-1){
  379. str = str+element
  380. }else{
  381. str = str+element+','
  382. }
  383. });
  384. return str
  385. }else if(content == '月保养'){
  386. return '每月'+that.monthDateValue
  387. }else if(content == '周保养'){
  388. let ind = that.weekList.findIndex(item=>item===that.weekDateValue)!=-1?that.weekList.findIndex(item=>item===that.weekDateValue) + 1:''
  389. return '每周'+ind
  390. }else if(content == '季度保养'){
  391. return '每季度'+that.quarterDateValue
  392. }else if(content == '半年保养'){
  393. return '每半年'+that.midyearDateValue
  394. }else if(content == '年保养'){
  395. return '每年'+that.yearDateValue
  396. }else{
  397. return ''
  398. }
  399. },
  400. correspondingNum(content){
  401. let that = this
  402. if(content == '日保养'){
  403. let str = ''
  404. let numArr = []
  405. that.dayCheckList.forEach((element,i) => {
  406. let ind = that.weekList.findIndex(item=>item===element) + 1
  407. numArr.push(ind)
  408. });
  409. numArr.sort(function(a,b){
  410. return a-b;
  411. })
  412. numArr.forEach((element,i) => {
  413. if(i==that.dayCheckList.length-1){
  414. str = str+element
  415. }else{
  416. str = str+element+','
  417. }
  418. });
  419. return str
  420. }else if(content == '月保养'){
  421. let turnVal = that.monthDateValue.replace(/[^0-9]/ig, '')
  422. return turnVal
  423. }else if(content == '周保养'){
  424. let ind = that.weekList.findIndex(item=>item===that.weekDateValue)!=-1?that.weekList.findIndex(item=>item===that.weekDateValue) + 1:''
  425. return ind
  426. }else if(content == '季度保养'){
  427. let turnVal = that.quarterDateValue.replace(/[^0-9]/ig, '')
  428. return turnVal
  429. }else if(content == '半年保养'){
  430. let turnVal = that.midyearDateValue.replace(/[^0-9]/ig, '')
  431. return turnVal
  432. }else if(content == '年保养'){
  433. let turnVal = that.yearDateValue.replace(/[^0-9]/ig, '')
  434. return turnVal
  435. }else{
  436. return ''
  437. }
  438. },
  439. assignment(content){
  440. let that = this
  441. if(content.weiHuLeiXing == '日保养'){
  442. let strArr = []
  443. let str = content.weiHuRiQi.slice(2)
  444. let partArr = str.split(",")
  445. // console.log(partArr)
  446. partArr.forEach((e,i)=>{
  447. let num = e*1-1
  448. strArr.push(this.weekList[num])
  449. })
  450. this.dayCheckList = strArr
  451. }else if(content.weiHuLeiXing == '月保养'){
  452. that.monthDateValue = content.weiHuRiQi
  453. }else if(content.weiHuLeiXing == '周保养'){
  454. let str = content.weiHuRiQi.slice(2)
  455. let partArr = str.split(",")
  456. // console.log(partArr*1-1)
  457. that.weekDateValue = this.weekList[partArr*1-1]
  458. }else if(content.weiHuLeiXing == '季度保养'){
  459. that.quarterDateValue = content.weiHuRiQi
  460. }else if(content.weiHuLeiXing == '半年保养'){
  461. that.midyearDateValue = content.weiHuRiQi
  462. }else if(content.weiHuLeiXing == '年保养'){
  463. that.yearDateValue = content.weiHuRiQi
  464. }else{
  465. }
  466. },
  467. // 关闭当前窗口
  468. closeDialog() {
  469. this.$emit('close', false)
  470. },
  471. loadFormData() {
  472. if(this.dynamicParams.position == 'manage'){
  473. let a=this.dynamicParams.formObj.getData(this.templateKey)[this.dynamicParams.params.index]
  474. this.assignment(a)
  475. this.cycleValue = a.weiHuLeiXing
  476. this.maintenanceTextarea = a.weiHuXiangMuC
  477. }
  478. },
  479. getDayDate(type, dates) {
  480. let now = new Date();
  481. let nowTime = now.getTime();
  482. let day = now.getDay();
  483. let longTime = 24 * 60 * 60 * 1000;
  484. let n = longTime * 7 * (dates || 0);
  485. let dd = nowTime - (day - type) * longTime + n;
  486. dd = new Date(dd);
  487. let y = dd.getFullYear();
  488. let m = dd.getMonth() + 1;
  489. let d = dd.getDate();
  490. m = m < 10 ? "0" + m: m;
  491. d = d < 10 ? "0" + d: d;
  492. let daynow = y + "-" + m + "-" + d;
  493. return daynow;
  494. },
  495. //获取往后几个月相应的日期
  496. //currentDate:当前日期
  497. //dayOfMonth:获取几号
  498. //val:往后几个月
  499. getNextMonthDate(currentDate, dayOfMonth,val) {
  500. const currentYear = currentDate.getFullYear();
  501. const currentMonth = currentDate.getMonth();
  502. const nextMonth = currentMonth + val;
  503. const nextMonthDate = new Date(currentYear, nextMonth, dayOfMonth);
  504. let formattedDate = nextMonthDate.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-');
  505. return formattedDate;
  506. },
  507. //获取当前季度
  508. getQuarter(date) {
  509. return Math.floor(date.getMonth() / 3) + 1;
  510. }
  511. }
  512. }
  513. </script>
  514. <style lang="scss" >
  515. .form-renderer-dialog {
  516. .el-dialog__body {
  517. padding: 10px 0 5px 0;
  518. }
  519. .el-dialog__headerbtn {
  520. z-index: 99999;
  521. }
  522. @media print {
  523. .el-dialog__headerbtn {
  524. display: none !important;
  525. }
  526. .hidden-print {
  527. padding: 0;
  528. margin: 0;
  529. }
  530. }
  531. }
  532. .maintenanceCycle{
  533. display: flex;
  534. align-items: center;
  535. margin: 2%;
  536. }
  537. .maintenanceFont{
  538. width: 10%;
  539. }
  540. .marginNone{
  541. margin: 0;
  542. }
  543. .rightMargin{
  544. margin-right: 2.5vh !important;
  545. }
  546. .describe{
  547. margin-top: 2%;
  548. font-size: 12px;
  549. color: #808080;
  550. }
  551. .fontColor{
  552. color: #409EFF;
  553. }
  554. </style>