audit-warrant-input.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <a-form-model-item
  3. v-if="lx === 'type'"
  4. ref="model"
  5. :rules="rules"
  6. :label="null"
  7. prop="empowerType"
  8. >
  9. <a-select v-model="model.empowerType" @change="changee">
  10. <a-select-option v-for="(key, i) in field.attr.selectListItem" :key="i" :value="key.value">
  11. {{ key.label }}
  12. </a-select-option>
  13. </a-select>
  14. </a-form-model-item>
  15. <a-form-model-item
  16. v-else-if="lx === 'stime'"
  17. ref="model"
  18. :rules="rules"
  19. :label="null"
  20. prop="startDate"
  21. >
  22. <a-date-picker
  23. :key="modelKey"
  24. v-model="model.startDate"
  25. :disabled="disabled"
  26. :disabled-date="disabledStartDate"
  27. @change="changest"
  28. />
  29. </a-form-model-item>
  30. <a-form-model-item v-else ref="model" :label="null" :rules="rules" prop="endDate">
  31. <a-date-picker
  32. :key="modelKey"
  33. v-model="model.endDate"
  34. :disabled="disabled"
  35. :disabled-date="disabledEndDate"
  36. @change="changeet"
  37. />
  38. </a-form-model-item>
  39. </template>
  40. <script>
  41. import moment from 'moment'
  42. export default {
  43. name: 'AuditWarrantInput',
  44. metaInfo: {
  45. title: 'AuditWarrantInput',
  46. },
  47. props: {
  48. value: {
  49. type: Object,
  50. default: null,
  51. },
  52. field: {
  53. type: Object,
  54. default: () => {},
  55. },
  56. index: {
  57. type: Number,
  58. default: -1,
  59. },
  60. lx: {
  61. type: String,
  62. default: '',
  63. },
  64. data: {
  65. type: String,
  66. default: 'udata',
  67. },
  68. },
  69. data() {
  70. return {
  71. modelKey: 0,
  72. time: '',
  73. model: { empowerType: '', startDate: '', endDate: '' },
  74. disabled:
  75. this.value.empowerType === '1' ||
  76. this.value.empowerType === '2' ||
  77. this.empowerType === '2',
  78. rules: [{ required: true, trigger: ['change', 'blur'] }],
  79. empowerType: '',
  80. startDate: '',
  81. endDate: '',
  82. }
  83. },
  84. watch: {
  85. empowerType(val) {
  86. this.isLastDay()
  87. this.$emit('change', this.model.empowerType, this.field, this.index, this.lx, this.data)
  88. this.$refs.model.validate('blur')
  89. },
  90. startDate() {
  91. this.$emit('change', this.model.startDate, this.field, this.index, this.lx, this.data)
  92. this.$refs.model.validate('blur')
  93. },
  94. endDate() {
  95. this.$emit('change', this.model.endDate, this.field, this.index, this.lx, this.data)
  96. this.$refs.model.validate('blur')
  97. },
  98. },
  99. created() {
  100. if (this.value !== null) {
  101. if (this.lx === 'type') {
  102. if (this.value.empowerType) {
  103. this.model.empowerType = this.value.empowerType
  104. }
  105. } else if (this.lx === 'stime') {
  106. if (this.value.startDate) {
  107. this.model.startDate = this.value.startDate
  108. if (this.value.empowerType === '1') {
  109. this.disabled = true
  110. }
  111. }
  112. } else if (this.lx === 'etime') {
  113. if (this.value.endDate) {
  114. this.model.endDate = this.value.endDate
  115. if (this.value.empowerType === '1') {
  116. this.disabled = true
  117. }
  118. }
  119. }
  120. }
  121. },
  122. methods: {
  123. disabledStartDate(startDate) {
  124. const finishDate = this.time
  125. if (!startDate || !finishDate) {
  126. return false
  127. }
  128. return startDate.valueOf() > finishDate.valueOf()
  129. },
  130. disabledEndDate(finishDate) {
  131. const startDate = this.time
  132. if (!finishDate || !startDate) {
  133. return false
  134. }
  135. return startDate.valueOf() >= finishDate.valueOf()
  136. },
  137. changee(value) {
  138. this.empowerType = value
  139. this.isLastDay()
  140. },
  141. changest(value) {
  142. this.startDate = value
  143. this.isLastDay()
  144. },
  145. changeet(value) {
  146. this.endDate = value
  147. this.isLastDay()
  148. },
  149. isLastDay() {
  150. // if (this.empowerType === '2') {
  151. // const now = moment()
  152. // const end = moment().endOf('year')
  153. // this.startDate = now
  154. // this.endDate = end
  155. // this.model.startDate = now
  156. // this.model.endDate = end
  157. // }
  158. },
  159. },
  160. }
  161. </script>
  162. <style module lang="scss">
  163. @use '@/common/design' as *;
  164. </style>