gaoluyang
5 天以前 a0a35be4065d75b80ba4a9a51da7031e03166766
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<template>
  <div>
    <el-dialog
        v-model="dialogFormVisible"
        title="详情"
        width="70%"
        @close="closeDia"
    >
      <!-- 按照入职新增弹窗字段展示基础信息和合同信息 -->
      <el-descriptions class="detail-descriptions" :column="2" border size="small">
        <el-descriptions-item label="员工编号">
          {{ formData.staffNo || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="姓名">
          {{ formData.staffName || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="性别">
          {{ formData.sex || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="年龄">
          {{ formData.age || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="户籍住址" :span="2">
          {{ formData.nativePlace || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="现住址" :span="2">
          {{ formData.adress || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="岗位">
          {{ formData.postJob || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="第一学历">
          {{ formData.firstStudy || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="专业">
          {{ formData.profession || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="联系电话">
          {{ formData.phone || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="紧急联系人">
          {{ formData.emergencyContact || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="紧急联系人电话">
          {{ formData.emergencyContactPhone || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="合同开始日期">
          {{ formData.contractStartTime || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="合同结束日期">
          {{ formData.contractExpireTime || '-' }}
        </el-descriptions-item>
        <el-descriptions-item label="合同年限">
          {{ formattedContractTerm }}
        </el-descriptions-item>
      </el-descriptions>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeDia">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import {ref, reactive, computed} from "vue";
import dayjs from "dayjs";
const emit = defineEmits(['close'])
 
const dialogFormVisible = ref(false);
const operationType = ref('')
const formData = reactive({
  staffNo: "",
  staffName: "",
  sex: "",
  identityCard: "",
  nativePlace: "",
  postJob: "",
  adress: "",
  firstStudy: "",
  profession: "",
  age: 0,
  phone: "",
  emergencyContact: "",
  emergencyContactPhone: "",
  dateSelect: "",
  trialStartDate: "",
  trialEndDate: "",
  proSalary: null,
  signDate: "",
  salarySelect: "",
  contractStartTime: "",
  contractExpireTime: "",
  contractTerm: null,
  remark: "",
});
 
const formattedContractTerm = computed(() => {
  const value = formData.contractTerm;
  if (value === null || value === undefined || value === "") {
    return "-";
  }
  const numberValue = Number(value);
  if (!isNaN(numberValue)) {
    return `${numberValue}年`;
  }
  return value;
});
 
const calculatedContractStart = computed(() => {
  const endDate = formData.contractExpireTime;
  const termValue = formData.contractTerm;
  const numberValue = Number(termValue);
  if (!endDate || isNaN(numberValue)) {
    return formData.contractStartTime || "-";
  }
  const start = dayjs(endDate).subtract(numberValue, "year");
  if (!start.isValid()) {
    return formData.contractStartTime || "-";
  }
  return start.format("YYYY-MM-DD");
});
 
// 打开弹框
const openDialog = (type, row) => {
  operationType.value = type;
  dialogFormVisible.value = true;
  // 重置表单数据
  Object.keys(formData).forEach(key => {
    if (key === 'age') {
      formData[key] = 0;
    } else if (["proSalary", "contractTerm"].includes(key)) {
      formData[key] = null;
    } else {
      formData[key] = "";
    }
  });
  
  if (operationType.value === 'edit' && row) {
    // 直接使用 row 数据赋值
    Object.assign(formData, row);
  }
}
 
// 关闭弹框
const closeDia = () => {
  dialogFormVisible.value = false;
  emit('close')
};
defineExpose({
  openDialog,
});
</script>
 
<style scoped>
.detail-descriptions {
  margin-bottom: 16px;
  border-radius: 6px;
  overflow: hidden;
}
 
.detail-descriptions :deep(.el-descriptions__cell) {
  padding: 12px 16px !important;
}
 
.detail-descriptions :deep(.el-descriptions__label) {
  width: 140px;
  color: #606266;
  background-color: #f7f9fc;
  font-weight: 500;
}
 
.detail-descriptions :deep(.el-descriptions__content) {
  color: #303133;
  line-height: 20px;
}
</style>