tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<template>
  <div class="container">
 
    <div class="title" v-if="!editId">项目工时{{ editId }}
      <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
    </div>
    <div class="title" v-else>
      <span>项目工时修改</span> <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
    </div>
 
    <div class="wrap">
 
    <el-form :model="project" label-width="auto"  ref="form" label-position="top"  @submit.prevent :rules="rules">
      <el-row>
        <el-col :span="12">
          <el-form-item label="项目名称">
            <el-input v-model="project.project_name" placeholder="请输入项目名称"  disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="3">
          
          <el-form-item label="对内工时(H)" prop="inner_hours">
            <el-input-number v-model="project.inner_hours"  min="0" />
          </el-form-item>
         
        </el-col>
        <el-col :span="3">
          
          <el-form-item label="对外工时(H)" prop="outer_hours">
              <el-input-number v-model="project.outer_hours"  min="0" />
            </el-form-item>
         
        </el-col>
 
        <el-col :span="3">
          <el-form-item label="基础工时(H)" prop="base_hours">
            <el-input-number v-model="project.base_hours" min="0"/>
          </el-form-item>
        </el-col>
      </el-row>
 
      <el-row>
        <el-col :span="12">
          <el-form-item class="submit">
              <el-button type="primary" @click="submitForm">保 存</el-button>
              <el-button @click="resetForm">重 置</el-button>
            </el-form-item>
        </el-col>
      </el-row>
 
    </el-form>
      
 
 
    </div>
  </div>
</template>
 
<script>
import { reactive, ref, onMounted,computed } from 'vue'
import { ElMessage } from 'element-plus'
import ProjectInfo from '@/model/projectInfo'
 
export default {
  props: {
    editId: {
      type: String,
      default: null,
    },
  },
  setup(props, context) {
    const form = ref(null)
    const loading = ref(false)
 
    const project = reactive({ 
      id:''
      ,project_name:''
      ,inner_hours:0
      ,outer_hours:0
      ,base_hours:0
    })
 
   
 
    const listAssign = (a, b) => Object.keys(a).forEach(key => {
      a[key] = b[key] || a[key]
    })
 
 
    
    /**
     * 表单规则验证
     */
    const { rules } = getRules()
 
    onMounted(() => {
 
      loadDictDitems()
      
      
    })
 
    //根据字典类型查询字典
    const loadDictDitems =async () =>{
 
      if (props.editId) {
        await getProjectInfo()
      
      }
 
    }
 
    const getProjectInfo = async () => {
      loading.value = true
      const res = await ProjectInfo.getProjectInfo(props.editId)
 
      listAssign(project, res)
     
     
      loading.value = false
    }
 
    // 重置表单
    const resetForm = () => {
      form.value.resetFields()
    }
 
    const submitForm = async formName => {
      form.value.validate(async valid => {
        
        if (valid) {
          let res = {}
          if (props.editId) {
            
            res = await ProjectInfo.editProjectHours(props.editId, project)
            context.emit('editClose')
          }
          if (res.code < window.MAX_SUCCESS_CODE) {
            ElMessage.success(`${res.message}`)
          }
        } else {
          console.error('error submit!!')
          ElMessage.error('请将信息填写完整')
        }
      })
    }
 
    const back = () => {
      context.emit('editClose')
    }
 
    return {
      back,
      project,
      form,
      rules,
      resetForm,
      submitForm,
 
 
    }
  },
}
 
/**
 * 表单验证规则
 */
function getRules() {
  /**
   * 验证回调函数
   */
  const checkInfo = (rule, value, callback) => {
    if (!value) {
      callback(new Error('信息不能为空'))
    }
    callback()
  }
 
  const rules = {
    inner_hours: [{ validator: checkInfo, trigger: 'blur', required: true }],
    outer_hours: [{ validator: checkInfo, trigger: 'blur', required: true }],
    
  }
  return { rules }
}
</script>
 
<style lang="scss" scoped>
.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;
    border-bottom: 1px solid #dae1ec;
 
    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }
 
  .wrap {
    padding: 20px;
  }
 
  .submit {
    float: left;
  }
}
</style>