defaultSettingDialog.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <template>
  2. <el-dialog
  3. title="配置默认数据"
  4. :visible.sync="dialogVisible"
  5. width="65%"
  6. style="margin-top:5vh"
  7. top
  8. append-to-body
  9. class="dialog"
  10. :close-on-click-modal="false"
  11. :close-on-press-escape="false"
  12. :show-close="false"
  13. >
  14. <div class="contain">
  15. <div class="form">
  16. <el-form ref="subformRef" :model="form" label-width="100px">
  17. <el-row :gutter="20">
  18. <el-col :span="12">
  19. <el-form-item label="默认部门:">
  20. <ibps-user-selector
  21. v-model="form.bian_zhi_bu_men_"
  22. size="mini"
  23. type="position"
  24. readonly-text="text"
  25. :disabled="false"
  26. :multiple="false"
  27. style="width:100%"
  28. :filter="filter"
  29. filterable
  30. />
  31. </el-form-item>
  32. </el-col>
  33. <el-col :span="12">
  34. <el-form-item label="默认岗位:">
  35. <el-select v-model="form.gang_wei_" placeholder="请选择" size="mini" style="width:100%">
  36. <el-option
  37. v-for="item in jianCeGangWeiList"
  38. :key="item.id_"
  39. :label="item.wei_hu_gang_wei_"
  40. :value="item.wei_hu_gang_wei_"
  41. />
  42. </el-select>
  43. </el-form-item>
  44. </el-col>
  45. </el-row>
  46. <el-row :gutter="20">
  47. <el-col :span="12">
  48. <el-form-item label="默认周期:">
  49. <el-select v-model="form.zhou_qi_" placeholder="请选择" size="mini" style="width:100%">
  50. <el-option
  51. v-for="item in period"
  52. :key="item.value"
  53. :label="item.label"
  54. :value="item.value"
  55. />
  56. </el-select>
  57. </el-form-item>
  58. </el-col>
  59. </el-row>
  60. <el-row v-if="form.zhou_qi_!==''" :gutter="20">
  61. <el-col :span="12">
  62. <el-form-item :label="labelShow">
  63. <el-checkbox-group v-if="form.zhou_qi_==='每日'" v-model="dayCheck" style="width:100%">
  64. <el-checkbox v-for="item in weekDays" :key="item.value" :label="item.value" size="mini">{{ item.label }}</el-checkbox>
  65. </el-checkbox-group>
  66. <template v-if="form.zhou_qi_==='每周'">
  67. <div class="radio" style="width:100%">
  68. <el-radio v-for="item in weekDays" :key="item.value" v-model="weekCheck" :label="item.value" size="mini">{{ item.label }}</el-radio>
  69. </div>
  70. </template>
  71. <el-select v-if="form.zhou_qi_==='每月'" v-model="monthCheck" placeholder="请选择" size="mini" style="width:100%">
  72. <el-option
  73. v-for="item in 28"
  74. :key="item"
  75. :label="`第${item}天`"
  76. :value="item"
  77. />
  78. </el-select>
  79. <el-select v-if="form.zhou_qi_==='每季度'" v-model="quarterCheck" placeholder="请选择" size="mini" style="width:100%">
  80. <el-option
  81. v-for="item in 3"
  82. :key="item"
  83. :label="`第${item}个月`"
  84. :value="item"
  85. />
  86. </el-select>
  87. <el-select v-if="form.zhou_qi_==='每半年'" v-model="halfYearCheck" placeholder="请选择" size="mini" style="width:100%">
  88. <el-option
  89. v-for="item in 6"
  90. :key="item"
  91. :label="`第${item}个月`"
  92. :value="item"
  93. />
  94. </el-select>
  95. <el-select v-if="form.zhou_qi_==='每年'" v-model="yearCheck" placeholder="请选择" size="mini" style="width:100%">
  96. <el-option
  97. v-for="item in 12"
  98. :key="item"
  99. :label="`第${item}个月`"
  100. :value="item"
  101. />
  102. </el-select>
  103. <el-select v-if="form.zhou_qi_==='间隔'" v-model="sepCheck" placeholder="请选择" size="mini" style="width:100%">
  104. <el-option
  105. v-for="item in 30"
  106. :key="item"
  107. :label="`每隔${item}天`"
  108. :value="item"
  109. />
  110. </el-select>
  111. </el-form-item>
  112. </el-col>
  113. <el-col v-if="nextDate" :span="12">
  114. <el-form-item label="下次监测日期为:" label-width="150">
  115. <el-tag size="mini" class="eltag">{{ nextDate }}</el-tag>
  116. </el-form-item>
  117. </el-col>
  118. <el-col v-if="form.zhou_qi_==='间隔'" :span="12">
  119. <el-form-item label="开始监测时间:" prop="">
  120. <el-date-picker
  121. v-model="form.kai_shi_shi_jian_"
  122. :clearable="false"
  123. type="date"
  124. placeholder="选择监测开始时间"
  125. :picker-options="pickerOptions"
  126. value-format="yyyy-MM-dd"
  127. size="mini"
  128. style="width:100%"
  129. />
  130. </el-form-item>
  131. </el-col>
  132. </el-row>
  133. <el-row :gutter="20">
  134. <el-col :span="12">
  135. <el-form-item label="默认控制条件:">
  136. <el-input v-model="form.tiao_jian_" type="textarea" :rows="2" size="mini" style="width:100%" />
  137. </el-form-item>
  138. </el-col>
  139. </el-row>
  140. <el-row :gutter="20">
  141. <el-col :span="24">
  142. <FacilityData v-if="form.lie_biao_shu_ju_" :form-data="{lieBiaoShuJu:form.lie_biao_shu_ju_}" :is-cul="false" @change-data="onFacilityData" />
  143. </el-col>
  144. </el-row>
  145. </el-form>
  146. </div>
  147. </div>
  148. <span slot="footer" class="dialog-footer">
  149. <el-button size="mini" type="info" icon="el-icon-setting" @click="emitParent('settingEmpty')">为空替换</el-button>
  150. <el-button size="mini" type="info" icon="el-icon-setting" @click="emitParent('settingAll')">全部替换</el-button>
  151. <el-button size="mini" type="danger" icon="ibps-icon-close" @click="handleClose">取消</el-button>
  152. </span>
  153. </el-dialog>
  154. </template>
  155. <script>
  156. import ibpsUserSelector from '@/business/platform/org/selector'
  157. import FacilityData from '@/views/component/facility/facilityData.vue'
  158. export default {
  159. components: {
  160. FacilityData, ibpsUserSelector
  161. },
  162. props: {
  163. dialogVisible: {
  164. type: Boolean,
  165. default: false
  166. },
  167. params: {
  168. type: Object,
  169. default: () => ({})
  170. },
  171. jianCeGangWeiList: {
  172. type: Array,
  173. default: () => []
  174. },
  175. day: {
  176. type: Array,
  177. default: () => []
  178. },
  179. week: {
  180. type: [String, Number],
  181. default: ''
  182. },
  183. month: {
  184. type: [String, Number],
  185. default: ''
  186. },
  187. quarter: {
  188. type: [String, Number],
  189. default: ''
  190. },
  191. halfYear: {
  192. type: [String, Number],
  193. default: ''
  194. },
  195. year: {
  196. type: [String, Number],
  197. default: ''
  198. },
  199. sep: {
  200. type: [String, Number],
  201. default: ''
  202. }
  203. },
  204. data () {
  205. return {
  206. pickerOptions: {
  207. disabledDate (time) {
  208. return time.getTime() < (Date.now() - (24 * 60 * 1000 * 60))
  209. }
  210. },
  211. dayCheck: [],
  212. weekCheck: '',
  213. monthCheck: '',
  214. quarterCheck: '',
  215. halfYearCheck: '',
  216. yearCheck: '',
  217. sepCheck: '',
  218. weekDays: [{ label: '周一', value: 1 }, { label: '周二', value: 2 }, { label: '周三', value: 3 }, { label: '周四', value: 4 }, { label: '周五', value: 5 }, { label: '周六', value: 6 }, { label: '周日', value: 7 }],
  219. nextDate: '',
  220. form: {},
  221. filter: [{
  222. descVal: '2',
  223. includeSub: true,
  224. old: 'position',
  225. partyId: this.$store.getters.userInfo.employee.positions,
  226. partyName: '',
  227. scriptContent: '',
  228. type: 'user',
  229. userType: 'position'
  230. }],
  231. period: [
  232. { label: '日监测', value: '每日' },
  233. { label: '周监测', value: '每周' },
  234. { label: '月监测', value: '每月' },
  235. { label: '季度监测', value: '每季度' },
  236. { label: '半年监测', value: '每半年' },
  237. { label: '年监测', value: '每年' },
  238. { label: '按时间间隔监测', value: '间隔' }
  239. ]
  240. }
  241. },
  242. computed: {
  243. labelShow () {
  244. if (this.form.zhou_qi_) {
  245. if (this.form.zhou_qi_ !== '间隔') {
  246. return this.form.zhou_qi_.split('每')[1] + '监测日期:'
  247. }
  248. return '间隔时间:'
  249. }
  250. return ''
  251. }
  252. },
  253. watch: {
  254. params: {
  255. handler (val) {
  256. this.form = val
  257. },
  258. immediate: true
  259. },
  260. day: {
  261. handler (val) {
  262. this.dayCheck = val
  263. }
  264. },
  265. week: {
  266. handler (val) {
  267. this.weekCheck = val
  268. }
  269. },
  270. month: {
  271. handler (val) {
  272. this.monthCheck = val
  273. }
  274. },
  275. quarter: {
  276. handler (val) {
  277. this.quarterCheck = val
  278. }
  279. },
  280. halfYear: {
  281. handler (val) {
  282. this.halfYearCheck = val
  283. }
  284. },
  285. year: {
  286. handler (val) {
  287. this.yearCheck = val
  288. }
  289. },
  290. sep: {
  291. handler (val) {
  292. this.sepCheck = val
  293. }
  294. },
  295. 'form.zhou_qi_' (val, old) {
  296. if (!old) return
  297. this.dayCheck = []
  298. this.weekCheck = ''
  299. this.monthCheck = ''
  300. this.quarterCheck = ''
  301. this.halfYearCheck = ''
  302. this.yearCheck = ''
  303. this.sepCheck = ''
  304. this.form.kai_shi_shi_jian_ = ''
  305. this.nextDate = ''
  306. },
  307. dayCheck: {
  308. handler: function (val, oldVal) {
  309. this.formatRiQi()
  310. if (val.length === 0) {
  311. this.nextDate = ''
  312. return
  313. }
  314. const temp_val = JSON.parse(JSON.stringify(val))
  315. const today = new Date()
  316. temp_val.sort(function (a, b) {
  317. return a - b
  318. })
  319. const num = temp_val.findIndex(e => e > today.getDay())
  320. if (temp_val.length > 0 && num !== -1) {
  321. this.nextDate = this.getDayDate(temp_val[num], 0)
  322. } else if (temp_val.length > 0 && num === -1) {
  323. this.nextDate = this.getDayDate(temp_val[0], 1)
  324. } else {
  325. this.nextDate = ''
  326. }
  327. },
  328. immediate: true
  329. },
  330. weekCheck: {
  331. handler: function (val, oldVal) {
  332. this.formatRiQi()
  333. if (val === '') {
  334. this.nextDate = ''
  335. return
  336. }
  337. const today = new Date()
  338. const weekNum = []
  339. weekNum.push(val)
  340. const num = weekNum.findIndex(e => e > today.getDay())
  341. if (val !== '' && num !== -1) {
  342. this.nextDate = this.getDayDate(weekNum[0], 0)
  343. } else if (val !== '' && num === -1) {
  344. this.nextDate = this.getDayDate(weekNum[0], 1)
  345. } else {
  346. this.nextDate = ''
  347. }
  348. },
  349. immediate: true
  350. },
  351. monthCheck: {
  352. handler: function (val, oldVal) {
  353. this.formatRiQi()
  354. if (val === '') {
  355. this.nextDate = ''
  356. return
  357. }
  358. const today = new Date()
  359. const day = today.getDate()
  360. const nextMonth = this.getNextMonthDate(today, val, 1)
  361. const currentMonth = this.getNextMonthDate(today, val, 0)
  362. this.nextDate = val > day ? currentMonth : nextMonth
  363. }
  364. // immediate: true
  365. },
  366. quarterCheck: {
  367. handler: function (val, oldVal) {
  368. this.formatRiQi()
  369. if (val === '') {
  370. this.nextDate = ''
  371. return
  372. }
  373. const quarterList = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
  374. const today = new Date()
  375. const month = today.getMonth() + 1
  376. const qu = this.getQuarter(today)
  377. const nowM = quarterList[qu - 1][val - 1]
  378. const nextM = quarterList[qu % 4][val - 1]
  379. const endMonth = month >= nowM ? nextM : nowM
  380. const yearPJ = today.getFullYear()
  381. const monthPJ = endMonth > 9 ? endMonth : '0' + endMonth
  382. this.nextDate = yearPJ + '-' + monthPJ + '-01'
  383. }
  384. // immediate: true
  385. },
  386. halfYearCheck: {
  387. handler: function (val, oldVal) {
  388. this.formatRiQi()
  389. if (val === '') {
  390. this.nextDate = ''
  391. return
  392. }
  393. const midList = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]
  394. const today = new Date()
  395. const month = today.getMonth() + 1
  396. const qu = month > 6 ? 2 : 1
  397. const nowM = midList[qu - 1][val - 1]
  398. const nextM = midList[qu % 2][val - 1]
  399. const endMonth = month >= nowM ? nextM : nowM
  400. const yearPJ = month >= nowM ? today.getFullYear() + 1 : today.getFullYear()
  401. const monthPJ = endMonth > 9 ? endMonth : '0' + endMonth
  402. this.nextDate = yearPJ + '-' + monthPJ + '-01'
  403. }
  404. // immediate: true
  405. },
  406. yearCheck: {
  407. handler: function (val, oldVal) {
  408. this.formatRiQi()
  409. if (val === '') {
  410. this.nextDate = ''
  411. return
  412. }
  413. const today = new Date()
  414. const month = today.getMonth() + 1
  415. const year = today.getFullYear()
  416. const qu = month >= val ? year + 1 : year
  417. const monthPJ = val > 9 ? val : '0' + val
  418. this.nextDate = qu + '-' + monthPJ + '-01'
  419. }
  420. // immediate: true
  421. },
  422. sepCheck: {
  423. handler: function (val, oldVal) {
  424. this.formatRiQi()
  425. }
  426. },
  427. 'form.kai_shi_shi_jian_': {
  428. handler: function (val, oldVal) {
  429. this.formatRiQi()
  430. }
  431. }
  432. },
  433. methods: {
  434. getDayDate (type, dates) {
  435. const now = new Date()
  436. const nowTime = now.getTime()
  437. const day = now.getDay()
  438. const longTime = 24 * 60 * 60 * 1000
  439. const n = longTime * 7 * (dates || 0)
  440. let dd = nowTime - (day - type) * longTime + n
  441. dd = new Date(dd)
  442. const y = dd.getFullYear()
  443. let m = dd.getMonth() + 1
  444. let d = dd.getDate()
  445. m = m < 10 ? '0' + m : m
  446. d = d < 10 ? '0' + d : d
  447. const daynow = y + '-' + m + '-' + d
  448. return daynow
  449. },
  450. // 获取往后几个月相应的日期
  451. // currentDate:当前日期
  452. // dayOfMonth:获取几号
  453. // val:往后几个月
  454. getNextMonthDate (currentDate, dayOfMonth, val) {
  455. const currentYear = currentDate.getFullYear()
  456. const currentMonth = currentDate.getMonth()
  457. const nextMonth = currentMonth + val
  458. const nextMonthDate = new Date(currentYear, nextMonth, dayOfMonth)
  459. const formattedDate = nextMonthDate.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-')
  460. return formattedDate
  461. },
  462. // 获取当前季度
  463. getQuarter (date) {
  464. return Math.floor(date.getMonth() / 3) + 1
  465. },
  466. formatRiQi () {
  467. switch (this.form.zhou_qi_) {
  468. case '每日':
  469. if (!this.dayCheck || this.dayCheck.length === 0) {
  470. this.form.jian_ce_ri_qi_ = ''
  471. this.form.ri_qi_lie_biao_ = ''
  472. } else if (this.dayCheck.length === 7) {
  473. this.form.jian_ce_ri_qi_ = '每天'
  474. this.form.ri_qi_lie_biao_ = '1,2,3,4,5,6,7'
  475. } else {
  476. const temp_dayCheck = JSON.parse(JSON.stringify(this.dayCheck))
  477. temp_dayCheck.sort(function (a, b) {
  478. return a - b
  479. })
  480. this.form.ri_qi_lie_biao_ = temp_dayCheck.join(',')
  481. this.form.jian_ce_ri_qi_ = '每周' + temp_dayCheck.join(',')
  482. }
  483. break
  484. case '每周':
  485. if (this.weekCheck) {
  486. this.form.jian_ce_ri_qi_ = '每周' + this.weekCheck
  487. this.form.ri_qi_lie_biao_ = this.weekCheck + ''
  488. } else {
  489. this.form.jian_ce_ri_qi_ = ''
  490. this.form.ri_qi_lie_biao_ = ''
  491. }
  492. break
  493. case '每月':
  494. if (this.monthCheck) {
  495. this.form.jian_ce_ri_qi_ = '每个月第' + this.monthCheck + '天'
  496. this.form.ri_qi_lie_biao_ = this.monthCheck + ''
  497. } else {
  498. this.form.jian_ce_ri_qi_ = ''
  499. this.form.ri_qi_lie_biao_ = ''
  500. }
  501. break
  502. case '每季度':
  503. if (this.quarterCheck) {
  504. this.form.jian_ce_ri_qi_ = '每季度第' + this.quarterCheck + '个月'
  505. this.form.ri_qi_lie_biao_ = this.quarterCheck + ''
  506. } else {
  507. this.form.jian_ce_ri_qi_ = ''
  508. this.form.ri_qi_lie_biao_ = ''
  509. }
  510. break
  511. case '每半年':
  512. if (this.halfYearCheck) {
  513. this.form.jian_ce_ri_qi_ = '每半年第' + this.halfYearCheck + '个月'
  514. this.form.ri_qi_lie_biao_ = this.halfYearCheck + ''
  515. } else {
  516. this.form.jian_ce_ri_qi_ = ''
  517. this.form.ri_qi_lie_biao_ = ''
  518. }
  519. break
  520. case '每年':
  521. if (this.yearCheck) {
  522. this.form.jian_ce_ri_qi_ = '每年第' + this.yearCheck + '个月'
  523. this.form.ri_qi_lie_biao_ = this.yearCheck + ''
  524. } else {
  525. this.form.jian_ce_ri_qi_ = ''
  526. this.form.ri_qi_lie_biao_ = ''
  527. }
  528. break
  529. case '间隔':
  530. if (this.sepCheck && this.form.kai_shi_shi_jian_) {
  531. this.form.jian_ce_ri_qi_ = this.form.kai_shi_shi_jian_ + '起每隔' + this.sepCheck + '天'
  532. this.form.ri_qi_lie_biao_ = this.sepCheck + ''
  533. } else {
  534. this.form.jian_ce_ri_qi_ = ''
  535. this.form.ri_qi_lie_biao_ = ''
  536. }
  537. break
  538. default:
  539. this.form.jian_ce_ri_qi_ = ''
  540. this.form.ri_qi_lie_biao_ = ''
  541. break
  542. }
  543. },
  544. emitParent (type) {
  545. let msg = ''
  546. if (type === 'settingEmpty') msg = '该操作会将未设置过的配置子表数据设置为默认值,是否继续?'
  547. if (type === 'settingAll') msg = '该操作会将所有配置子表数据替换为默认值,是否继续?'
  548. this.$confirm(msg, '提示', {
  549. confirmButtonText: '继续',
  550. cancelButtonText: '取消',
  551. type: 'warning'
  552. }).then(() => {
  553. this.$emit('emitParent', type)
  554. }).catch(() => {
  555. })
  556. },
  557. // 接收自定义组件数据
  558. onFacilityData (...arg) {
  559. if (arg.length > 1) {
  560. this.form.lie_biao_shu_ju_ = arg[1]
  561. }
  562. },
  563. handleClose () {
  564. this.$emit('update:dialogVisible', false)
  565. }
  566. }
  567. }
  568. </script>
  569. <style lang="scss" scoped>
  570. .contain{
  571. .form{
  572. padding: 20px;
  573. height: 60vh;
  574. .el-row{
  575. margin: 10px 0;
  576. }
  577. }
  578. .el-row{
  579. margin: 0 !important;
  580. }
  581. .eltag{
  582. margin-top: 6px;
  583. }
  584. }
  585. .dialog-footer{
  586. display: flex;
  587. justify-content: center;
  588. }
  589. ::v-deep {
  590. .el-form-item__label{
  591. text-align: left
  592. }
  593. .el-form-item__content{
  594. display: flex;
  595. }
  596. }
  597. </style>