item.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div>
  3. <div v-if="props.items.length" class="d-flex align-center mb-1">
  4. <v-checkbox v-model="selectAll" :label="!selectAll ? $t('common.selectAll') : `已选中${selectList.length}条`" hide-details color="primary" @update:model-value="handleChangeSelectAll"></v-checkbox>
  5. <div v-if="tab === 1" class="ml-8">
  6. <v-btn :disabled="!selectAll" color="primary" variant="tonal" size="small" @click="handleAction(2, 'batch', {})">{{ $t('common.refresh') }}</v-btn>
  7. <v-btn class="mx-3" :disabled="!selectAll" color="primary" variant="tonal" size="small" @click="handleAction(3, 'top', {})">{{ $t('common.topping') }}</v-btn>
  8. <v-btn :disabled="!selectAll" color="primary" variant="tonal" size="small" @click="handleAction(0, 'close', {})">{{ $t('common.close') }}</v-btn>
  9. </div>
  10. <v-btn v-if="tab === 2" class="ml-8" :disabled="!selectAll" color="primary" variant="tonal" size="small" @click="handleAction(1, 'activation', {})">{{ $t('common.activation') }}</v-btn>
  11. </div>
  12. <div v-for="val in items" :key="val.id" class="itemBox mb-3" style="height: 134px;">
  13. <div class="d-flex justify-space-between" style="padding: 10px 20px;">
  14. <div class="position">
  15. <div class="item-select">
  16. <v-checkbox v-model="val.select" hide-details color="primary" @update:model-value="handleChangeSelect"></v-checkbox>
  17. </div>
  18. <div :class="['ml-10' ,'d-flex' ,'align-center']">
  19. <span v-if="val.name.indexOf('style')" v-html="val.name" class="position-name"></span>
  20. <span v-else class="position-name">{{ val.name }}</span>
  21. </div>
  22. <div :class="['mt-3', 'other-info', 'ellipsis', 'ml-10']">
  23. <span>{{ val.areaName }}</span>
  24. <span class="lines" v-if="val.areaName && val.eduName"></span>
  25. <span>{{ val.eduName }}</span>
  26. <span class="lines"></span>
  27. <span>{{ val.expName }}</span>
  28. <span class="lines"></span>
  29. <span v-if="!val.payFrom && !val.payTo">面议</span>
  30. <span v-else>{{ val.payFrom ? val.payFrom + '-' : '' }}{{ val.payTo }}{{ val.payName ? '/' + val.payName : '' }}</span>
  31. <span class="lines"></span>
  32. <span>{{ val.positionName }}</span>
  33. </div>
  34. </div>
  35. <div class="d-flex align-center">
  36. <v-btn v-if="tab === 1" class="ml-3" color="primary" @click="handleAction(2, '', val)">{{ $t('common.refresh') + $t('common.position') }}</v-btn>
  37. <v-btn v-if="tab === 2" color="primary" @click="handleAction(1, '', val)">{{ $t('common.activatePosition') }}</v-btn>
  38. </div>
  39. </div>
  40. <div class="bottom pa-5 d-flex justify-space-between align-center">
  41. <div>{{ $t('position.refreshTime') }} :{{ timesTampChange(val.updateTime, 'Y-M-D') }}</div>
  42. <div class="d-flex">
  43. <div class="ml-10 d-flex">
  44. <div v-if="tab === 1">
  45. <span class="cursor-pointer actions" @click="handleAction(3, '', val)">{{ $t('common.topping') }}</span>
  46. <span class="lines"></span>
  47. <span class="cursor-pointer actions" @click="handleAction(0, '', val)">{{ $t('common.close') }}</span>
  48. <span class="lines"></span>
  49. </div>
  50. <div class="cursor-pointer actions" @click="handleEdit(val)">{{ $t('common.edit') }}</div>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script setup>
  58. defineOptions({ name: 'enterprise-position-item'})
  59. import { ref, watch } from 'vue'
  60. import { useRouter } from 'vue-router'
  61. import { timesTampChange } from '@/utils/date'
  62. import { useI18n } from '@/hooks/web/useI18n'
  63. import { closeJobAdvertised, enableJobAdvertised, refreshJobAdvertised, topJobAdvertised } from '@/api/position'
  64. import Snackbar from '@/plugins/snackbar'
  65. const { t } = useI18n()
  66. const emit = defineEmits(['refresh'])
  67. const props = defineProps({
  68. tab: {
  69. type: Number,
  70. default: 1
  71. },
  72. items: Array
  73. })
  74. const selectAll = ref(false) // 全选
  75. const selectList = ref([]) // 选中列表
  76. const dealSelect = () => {
  77. selectList.value = props.items.filter(e => e.select).map(k => k.id)
  78. }
  79. // 全选
  80. const handleChangeSelectAll = () => {
  81. props.items.map(k => {
  82. k.select = selectAll.value
  83. return k
  84. })
  85. dealSelect()
  86. }
  87. // 单选
  88. const handleChangeSelect = () => {
  89. const length = props.items.filter(k => k.select).length
  90. selectAll.value = length > 0 ? true : false
  91. dealSelect()
  92. }
  93. // tab改变时清空选中的项
  94. watch(
  95. () => props.tab,
  96. () => {
  97. props.items.map(e => e.select = false)
  98. selectList.value = []
  99. selectAll.value = false
  100. },
  101. { immediate: true }
  102. )
  103. // 分页选中回显
  104. watch(
  105. () => props.items,
  106. (newVal) => {
  107. selectList.value.forEach(e => {
  108. const obj = newVal.find(k => k.id === e)
  109. if (obj) obj.select = true
  110. })
  111. },
  112. { immediate: true },
  113. { deep: true }
  114. )
  115. const apiList = [ closeJobAdvertised, enableJobAdvertised, refreshJobAdvertised, topJobAdvertised ]
  116. // 职位关闭、激活、刷新、置顶
  117. const handleAction = async (index, type, { id }) => {
  118. const ids = type ? props.items.filter(e => e.select).map(k => k.id) : [id]
  119. if (!ids.length && !index) return
  120. await apiList[index](ids)
  121. Snackbar.success(t('common.operationSuccessful'))
  122. // 清空选项
  123. selectList.value = []
  124. selectAll.value = false
  125. emit('refresh')
  126. }
  127. const router = useRouter()
  128. // 职位编辑
  129. const handleEdit = (val) => {
  130. router.push(`/recruit/enterprise/position/edit?id=${val.id}`)
  131. }
  132. </script>
  133. <style scoped lang="scss">
  134. .itemBox {
  135. position: relative;
  136. border: 1px solid #e5e6eb;
  137. }
  138. .position-name {
  139. color: var(--color-333);
  140. font-size: 19px;
  141. }
  142. .position {
  143. max-width: 46%;
  144. position: relative;
  145. .item-select {
  146. position: absolute;
  147. left: -8px;
  148. top: -13px;
  149. }
  150. }
  151. .lines {
  152. display: inline-block;
  153. width: 1px;
  154. height: 17px;
  155. vertical-align: middle;
  156. background-color: #e0e0e0;
  157. margin: 0 10px;
  158. }
  159. .other-info {
  160. font-size: 15px;
  161. color: var(--color-666);
  162. }
  163. .bottom {
  164. position: absolute;
  165. bottom: 0;
  166. left: 0;
  167. width: 100%;
  168. height: 40px;
  169. background-color: #f7f8fa;
  170. font-size: 14px;
  171. color: var(--color-888);
  172. }
  173. .actions:hover {
  174. color: var(--v-primary-base);
  175. }
  176. </style>