weicd
2023-09-28 d0c51ac702c57f2cae84a8d879a5b605f2dab630
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.belongYear" filterable clearable placeholder="年度" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in belongYearList"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
        <el-select v-model="query.belongWeek" filterable clearable placeholder="周数" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in belongWeekList"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
        <el-select v-model="query.projectId" filterable clearable placeholder="所属项目" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in projectList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.distinguish" filterable clearable placeholder="项目区分" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[projectDistinguish]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="所属项目" prop="project.id">
            <el-select v-model="form.project.id" filterable clearable placeholder="请选择" style="width: 370px;" :disabled="disabled || crud.status.add !== 1">
              <el-option
                v-for="item in projectList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                :disabled="item.approveStatus == approveStatusUnsettled"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="年度" prop="belongYear">
            <el-input v-model.number="form.belongYear" style="width: 370px;" :disabled="disabled || crud.status.add !== 1" />
          </el-form-item>
          <el-form-item label="周数" prop="belongWeek">
            <el-input v-model.number="form.belongWeek" style="width: 370px;" :disabled="disabled || crud.status.add !== 1" />
          </el-form-item>
          <el-form-item v-if="crud.status.add !== 1" label="本周预计" prop="lastedProgress">
            <el-input v-model="form.lastProjectProcess.estimatedProgress" style="width: 370px;" :disabled="true">
              <template slot="append">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="本周实际" prop="projectProgress">
            <el-input v-model="form.projectProgress" style="width: 370px;" :disabled="disabled">
              <template slot="append">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="下周预计" prop="estimatedProgress">
            <el-input v-model="form.estimatedProgress" style="width: 370px;" :disabled="disabled">
              <template slot="append">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="承认状态" prop="approveStatus">
            <el-select v-model="form.approveStatus" filterable clearable :disabled="disabled" placeholder="请选择" style="width: 370px;">
              <el-option
                v-for="item in dict[approveStatus]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 370px;" :disabled="disabled" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column fixed type="selection" width="55px" />
        <el-table-column fixed show-overflow-tooltip prop="belongYear" label="年度" />
        <el-table-column fixed show-overflow-tooltip prop="belongWeek" label="周数" />
        <el-table-column fixed show-overflow-tooltip prop="projectName" label="所属项目" width="140px">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.project.name }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="lastedProgress" label="本周预计">
          <template slot-scope="scope">
            {{ (scope.row.lastProjectProcess.estimatedProgress ? scope.row.lastProjectProcess.estimatedProgress : 0) + '%' }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="projectProgress" label="本周实际">
          <template slot-scope="scope">
            <span :style="{ color: scope.row.lastedProgress > scope.row.projectProgress ? 'red' : '' }">{{ (scope.row.projectProgress ? scope.row.projectProgress + '%' : '0%') }}</span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="estimatedProgress" label="下周预计">
          <template slot-scope="scope">
            {{ (scope.row.estimatedProgress ? scope.row.estimatedProgress + '%' : '0%') }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="moneyTotalInit" label="计划总成本" width="140px">
          <template slot-scope="scope">
            {{ scope.row.moneyTotalInit != null && scope.row.moneyTotalInit != '' ? crud.toMoney(scope.row.moneyTotalInit) : 0 }}
            ({{ scope.row.lastProjectProcess.moneyTotalInit != null && scope.row.lastProjectProcess.moneyTotalInit != '' ? crud.toMoney(scope.row.moneyTotalInit - scope.row.lastProjectProcess.moneyTotalInit) : crud.toMoney(0) }})
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="moneyTotalCost" label="总消耗成本" width="140px">
          <template slot-scope="scope">
            {{ scope.row.moneyTotalCost != null && scope.row.moneyTotalCost != '' ? crud.toMoney(scope.row.moneyTotalCost) : 0 }}
            ({{ scope.row.lastProjectProcess.moneyTotalCost != null && scope.row.lastProjectProcess.moneyTotalCost != '' ? crud.toMoney(scope.row.moneyTotalCost - scope.row.lastProjectProcess.moneyTotalCost) : crud.toMoney(0) }})
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="realLastCost" label="本周消化工时" width="100px">
          <template slot-scope="scope">
            {{ scope.row.lastProjectProcess.realLastCost != null ? scope.row.realLastCost - scope.row.lastProjectProcess.realLastCost : scope.row.realLastCost }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="workTotalInit" label="总工作量" width="100px">
          <template slot-scope="scope">
            {{ scope.row.workTotalInit != null && scope.row.workTotalInit != '' ? crud.toMoney(scope.row.workTotalInit) : 0 }}
            ({{ scope.row.lastProjectProcess.workTotalInit != null && scope.row.lastProjectProcess.workTotalInit != '' ? crud.toMoney(scope.row.workTotalInit - scope.row.lastProjectProcess.workTotalInit) : crud.toMoney(0) }})
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="workTotalCost" label="总消耗工作量" width="100px">
          <template slot-scope="scope">
            {{ scope.row.workTotalCost != null && scope.row.workTotalCost != '' ? crud.toMoney(scope.row.workTotalCost) : 0 }}
            ({{ scope.row.lastProjectProcess.workTotalCost != null && scope.row.lastProjectProcess.workTotalCost != '' ? crud.toMoney(scope.row.workTotalCost - scope.row.lastProjectProcess.workTotalCost) : crud.toMoney(0) }})
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="approveStatus" label="承认状态">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[approveStatus][scope.row.approveStatus] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="remarks" label="备注" width="140" />
        <el-table-column show-overflow-tooltip prop="createTime" label="创建时间" width="140" />
        <el-table-column v-if="checkPer(['admin','projectProgress:edit','projectProgress:del'])" label="操作" fixed="right" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
 
<script>
import crudProjectProgress from '@/api/project/projectProgress'
import crudProject from '@/api/project/project'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import constant from '../../../utils/constant'
 
const defaultForm = { id: null, project: { id: null }, belongYear: null, belongWeek: null, approveStatus: null, projectProgress: null, estimatedProgress: null, lastProjectProcess: {}, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'ProjectProgress',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.APPROVE_STATUS, constant.PROJECT_DISTINGUISH],
  cruds() {
    return CRUD({ title: '项目进度', url: 'api/projectProgress', idField: 'id', sort: ['belongYear,desc', 'belongWeek,desc'], crudMethod: { ...crudProjectProgress }})
  },
  data() {
    // 年度(2020~2099)验证
    var yearValidate = (rule, value, callback) => {
      if (value != null && value !== '' && (isNaN(value) || !Number.isInteger(value) || Number(value) <= 2020 || Number(value) >= 2099)) {
        callback(new Error('请输入 2020 到 2099 以内的正整数'))
      } else {
        callback()
      }
    }
    // 周数(1~53)验证
    var weekValidate = (rule, value, callback) => {
      if (value != null && value !== '' && (isNaN(value) || !Number.isInteger(value) || Number(value) < 1 || Number(value) > 53)) {
        callback(new Error('请输入 1 到 53 以内的正整数'))
      } else {
        callback()
      }
    }
    // 进度(百内)验证
    var progressValidate = (rule, value, callback) => {
      const reg = /^([0-9]|[1-9]\d)(\.\d{1,2})?$|100$/
      if (value != null && value !== '' && !reg.test(value)) {
        callback(new Error('请输入 一百 以内的正整数或两位小数'))
      } else {
        callback()
      }
    }
    return {
      permission: {
        add: ['admin', 'projectProgress:add'],
        edit: ['admin', 'projectProgress:edit'],
        del: ['admin', 'projectProgress:del'],
        download: ['admin', 'projectProgress:download']
      },
      rules: {
        'project.id': [
          { required: true, message: '所属项目不能为空', trigger: 'change' }
        ],
        belongYear: [
          { required: true, message: '年度不能为空', trigger: 'blur' },
          { validator: yearValidate, trigger: 'blur' }
        ],
        belongWeek: [
          { required: true, message: '周数不能为空', trigger: 'blur' },
          { validator: weekValidate, trigger: 'blur' }
        ],
        projectProgress: [
          { required: true, message: '本周实际不能为空', trigger: 'blur' },
          { validator: progressValidate, trigger: 'blur' }
        ],
        estimatedProgress: [
          { required: true, message: '下周预计不能为空', trigger: 'blur' },
          { validator: progressValidate, trigger: 'blur' }
        ],
        approveStatus: [
          { required: true, message: '承认状态不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'belongYear', display_name: '年度' },
        { key: 'belongWeek', display_name: '周数' },
        { key: 'projectId', display_name: '所属项目' },
        { key: 'projectDistinguish', display_name: '项目区分' }
      ],
      // 项目区分
      projectDistinguish: constant.PROJECT_DISTINGUISH,
      // 承认状态
      approveStatus: constant.APPROVE_STATUS,
      // 承认状态:未承认
      approveStatusUnsettled: constant.APPROVE_STATUS_UNRECOGNIZED,
      // 承认状态:已承认
      approveStatusAcknowledged: constant.APPROVE_STATUS_ACKNOWLEDGED,
      // 项目列表
      projectList: [],
      // 年度列表
      belongYearList: [],
      // 周数列表
      belongWeekList: [],
      // 禁用状态
      disabled: false
    }
  },
  watch: {
    // 检索条件:年度
    'query.belongYear'(newValue) {
      // 年度变更后,周数初始化
      if (this.query.belongWeek) {
        this.query.belongWeek = null
      }
      // 周数列表
      this.belongWeekList = []
      // 年度清空后不需要查询数据
      if (!newValue) {
        return
      }
      // 查询年度对应的周数
      crudProjectProgress.getBelongWeek(newValue).then(res => {
        res.forEach(item => {
          // 周数列表
          this.belongWeekList.push(item)
        })
      })
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 获取项目信息
      this.getProject()
      // 获取年度信息
      this.getBelongYear()
      return true
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      // 是否可以修改
      this.getDisabled()
    },
    // 获取项目信息
    getProject() {
      // 获取项目信息
      crudProject.getAll().then(res => {
        // 项目列表
        this.projectList = res
      })
    },
    // 获取年度信息
    getBelongYear() {
      // 获取年度信息
      crudProjectProgress.getBelongYear().then(res => {
        // 年度列表
        this.belongYearList = res
      })
    },
    // 是否可以修改
    getDisabled() {
      // 禁用状态
      this.disabled = false
      // 判断表单承认状态
      if (this.form.approveStatus === this.approveStatusAcknowledged) {
        // 禁用状态
        this.disabled = true
      } else if (this.form.approveStatus === this.approveStatusUnsettled) {
        // 禁用状态
        this.disabled = false
      }
    }
  }
}
</script>
 
<style scoped>
 
</style>