BAOLH
2026-11-10 4d730af0447c686133130d0116a0fa3dd82c2dca
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
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.projectId" clearable filterable 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>
        <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="projectId">
            <el-select v-model="form.projectId" clearable filterable placeholder="请选择" style="width: 370px;" :disabled="disabledFlagByApprove">
              <el-option
                v-for="item in projectList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                :disabled="item.approveStatus == approveStatusAcknowledged"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="成本类型" prop="projectCostType">
            <el-select v-model="form.projectCostType" clearable filterable placeholder="请选择" style="width: 370px;" :disabled="disabledFlagByApprove" @change="form.subProjectCostType = null">
              <el-option
                v-for="item in dict[projectCostType]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="form.projectCostType === '3'" label="子类型" prop="subProjectCostType">
            <el-select v-model="form.subProjectCostType" clearable filterable placeholder="请选择" style="width: 370px;" :disabled="disabledFlagByApprove">
              <el-option
                v-for="item in subProjectCostTypeList"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="项目成本" prop="projectCost">
            <money-input :key="randomCost" v-model="form.projectCost" :width="370" :disabled="disabledFlagByApprove" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" :rows="3" type="textarea" style="width: 370px;" :disabled="disabledFlagByApprove" />
          </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" show-summary :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="projectId" label="项目" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag>{{ scope.row.projectName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="projectCostType" label="项目成本类型">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[projectCostType][scope.row.projectCostType] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="subProjectCostType" label="项目成本子类型" />
        <el-table-column prop="projectCost" label="项目成本">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.projectCost) }}
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" />
        <el-table-column v-if="checkPer(['admin','projectCostOther:edit','projectCostOther:del'])" label="操作" 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 crudProjectCostOther from '@/api/projectCostOther'
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'
import moneyInput from '@/views/assembly/moneyInput/index.vue'
 
const defaultForm = { id: null, projectId: null, projectCostType: null, subProjectCostType: null, projectCost: null, remark: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'ProjectCostOther',
  components: { pagination, crudOperation, rrOperation, udOperation, moneyInput },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['project_cost_type'],
  cruds() {
    return CRUD({ title: '项目其他成本', url: 'api/projectCostOther', idField: 'id', sort: 'id,desc', crudMethod: { ...crudProjectCostOther }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'projectCostOther:add'],
        edit: ['admin', 'projectCostOther:edit'],
        del: ['admin', 'projectCostOther:del']
      },
      rules: {
        projectId: [
          { required: true, message: '项目不能为空', trigger: 'blur' }
        ],
        projectCostType: [
          { required: true, message: '项目成本类型不能为空', trigger: 'blur' }
        ],
        projectCost: [
          { required: true, message: '项目成本不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'projectId', display_name: '项目' }
      ],
      // 表单禁用标记(承认状态)
      disabledFlagByApprove: false,
      // 字典:任务分类
      projectCostType: 'project_cost_type',
      // 项目列表
      projectList: [],
      // 随机数
      randomCost: 0,
      // 承认状态:已承认
      approveStatusAcknowledged: constant.APPROVE_STATUS_ACKNOWLEDGED,
      // 子成本类型List
      subProjectCostTypeList: [
        {
          id: 1,
          label: '补贴',
          value: '补贴'
        },
        {
          id: 2,
          label: '加油费',
          value: '加油费'
        },
        {
          id: 3,
          label: '餐饮费',
          value: '餐饮费'
        },
        {
          id: 4,
          label: '住宿费',
          value: '住宿费'
        }
      ]
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 判断传参是否为空
      if (this.$route.params.projectId != null && this.$route.params.projectId !== '' && this.crud.query.projectId === undefined) {
        // 检索条件赋值
        this.$set(this.crud.query, 'projectId', Number(this.$route.params.projectId))
      }
      // 获取项目列表
      this.getProjectList()
      return true
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      // 表单禁用标记(承认状态)
      this.disabledFlagByApprove = false
      // 循环项目列表
      for (let i = 0; i < this.projectList.length; i++) {
        // 判断是否为同一项目
        if (this.form.projectId === this.projectList[i].id && this.projectList[i].approveStatus === constant.APPROVE_STATUS_ACKNOWLEDGED) {
          // 表单禁用标记(承认状态)
          this.disabledFlagByApprove = true
        }
      }
      // 随机数
      this.randomCost = Math.random()
    },
    // 获取项目列表
    getProjectList() {
      // 获取项目列表
      crudProject.getAll().then(res => {
        // 项目列表
        this.projectList = res
      })
    }
  }
}
</script>
 
<style scoped>
 
</style>