huaz
2023-01-09 5fd2ac11a530b5b7ddfcb2a40cf5d68fdde193be
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
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.name" clearable placeholder="请输入名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.standardUnitCurrency" filterable placeholder="请选择标准单价币种" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[standardUnitCurrency]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation />
      </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="120px">
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" maxlength="100" style="width: 330px;" />
          </el-form-item>
          <el-form-item label="标准单价币种" prop="standardUnitCurrency">
            <el-select v-model="form.standardUnitCurrency" filterable placeholder="请选择" style="width: 330px;">
              <el-option
                v-for="item in dict[standardUnitCurrency]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="标准单价金额" prop="standardUnitPrice">
            <money-input :key="random" v-model="form.standardUnitPrice" :width="330" />
          </el-form-item>
          <el-form-item label="标准利润金额" prop="standardProfitPrice">
            <money-input :key="random" v-model="form.standardProfitPrice" :width="330" />
          </el-form-item>
          <el-form-item label="标准工作量单位" prop="standardWorkloadUnit">
            <el-select v-model="form.standardWorkloadUnit" filterable placeholder="请选择" style="width: 330px;">
              <el-option
                v-for="item in dict[standardWorkloadUnit]"
                :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: 330px;" />
          </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 type="selection" width="55" />
        <el-table-column prop="name" label="名称" show-overflow-tooltip />
        <el-table-column prop="standardUnitCurrency" label="标准单价币种">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[standardUnitCurrency][scope.row.standardUnitCurrency] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="standardUnitPrice" label="标准单价金额">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.standardUnitPrice) }}
          </template>
        </el-table-column>
        <el-table-column prop="standardProfitPrice" label="标准利润金额">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.standardProfitPrice) }}
          </template>
        </el-table-column>
        <el-table-column prop="standardWorkloadUnit" label="标准工作量单位">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[standardWorkloadUnit][scope.row.standardWorkloadUnit] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注" show-overflow-tooltip />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column v-if="checkPer(['admin','projectType:edit','projectType: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 crudProjectType from '@/api/project/projectType'
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 moneyInput from '../../assembly/moneyInput/index.vue'
import constant from '../../../utils/constant'
 
const defaultForm = { id: null, name: null, standardUnitCurrency: null, standardUnitPrice: null, standardProfitPrice: null, standardWorkloadUnit: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'ProjectType',
  components: { pagination, crudOperation, rrOperation, udOperation, moneyInput },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.STANDARD_UNIT_CURRENCY, constant.STANDARD_WORKLOAD_UNIT],
  cruds() {
    return CRUD({ title: '项目类型', url: 'api/projectType', idField: 'id', sort: 'id,desc', crudMethod: { ...crudProjectType }})
  },
  data() {
    var checkStandardUnitPricet = (rule, value, callback) => {
      if (value !== null) {
        if (isNaN(Number(value))) {
          callback(new Error('标准单价金额必须是数字'))
        } else {
          if (value <= 0) {
            callback(new Error('标准单价金额必须大于0'))
          } else if (value >= 10000000000) {
            callback(new Error('标准单价金额必须小于1百亿'))
          } else {
            callback()
          }
        }
      } else {
        callback(new Error('标准单价金额不能为空'))
      }
    }
    var checkStandardProfitPrice = (rule, value, callback) => {
      if (value !== null) {
        if (isNaN(Number(value))) {
          callback(new Error('标准利润金额必须是数字'))
        } else {
          if (value <= 0) {
            callback(new Error('标准利润金额必须大于0'))
          } else if (value >= 10000000000) {
            callback(new Error('标准利润金额必须小于1百亿'))
          } else {
            callback()
          }
        }
      } else {
        callback(new Error('标准利润金额不能为空'))
      }
    }
    return {
      permission: {
        add: ['admin', 'projectType:add'],
        edit: ['admin', 'projectType:edit'],
        del: ['admin', 'projectType:del'],
        download: ['admin', 'projectType:download']
      },
      rules: {
        name: [
          { required: true, message: '名称不能为空', trigger: 'blur' },
          { min: 1, max: 100, message: '最大长度 100 个字符', trigger: 'blur' }
        ],
        standardUnitCurrency: [
          { required: true, message: '标准单价币种不能为空', trigger: 'blur' }
        ],
        standardUnitPrice: [
          { required: true, validator: checkStandardUnitPricet, trigger: 'blur' }
        ],
        standardProfitPrice: [
          { required: true, validator: checkStandardProfitPrice, trigger: 'blur' }
        ],
        standardWorkloadUnit: [
          { required: true, message: '标准工作量单位不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'name', display_name: '名称' },
        { key: 'standardUnitCurrency', display_name: '标准单价币种' }
      ],
      // 标准单价币种
      standardUnitCurrency: constant.STANDARD_UNIT_CURRENCY,
      // 标准工作量单位
      standardWorkloadUnit: constant.STANDARD_WORKLOAD_UNIT,
      // 随机数
      random: 0
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      // 随机数
      this.random = Math.random()
    }
  }
}
</script>
 
<style scoped>
 
</style>