赵士淞
2023-04-24 9bc3f59d8f09cfe536f1758e7a6ed4471e9223a6
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, 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="600px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
          <el-form-item label="费用类型" prop="expenseType">
            <el-select v-model="form.expenseType" placeholder="请选择" filterable clearable style="width: 440px;">
              <el-option
                v-for="item in dict[expenseType]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="所属营业计划" prop="businessPlanId">
            <el-select v-model="form.businessPlanId" placeholder="请选择" filterable clearable style="width: 440px;">
              <el-option
                v-for="item in businessPlanList"
                :key="item.id"
                :label="item.businessContent"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="所属项目">
            <el-select v-model="form.projectId" placeholder="请选择" filterable clearable style="width: 440px;">
              <el-option
                v-for="item in projectList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-button size="mini" type="primary" icon="el-icon-plus" style="position: relative; left: 464px;" @click="reimbursementAdd()" />
          <el-table ref="table" :data="form.businessExpenseReimbursementDtoList" size="small" style="width: 100%;">
            <el-table-column :show-overflow-tooltip="true" prop="reimbursementContent" label="报销内容" />
            <el-table-column :show-overflow-tooltip="true" prop="reimbursementAmount" label="报销金额">
              <template slot-scope="scope">
                {{ crud.toMoney(scope.row.reimbursementAmount) }}
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" prop="reimbursementVoucher" label="报销凭证">
              <template slot-scope="scope">
                <el-image
                  :src="scope.row.reimbursementVoucher != null && scope.row.reimbursementVoucher !== '' ? baseApi + scope.row.reimbursementVoucher.split(',')[0] : ''"
                  :preview-src-list="scope.row.reimbursementVoucher != null && scope.row.reimbursementVoucher !== '' ? scope.row.reimbursementVoucher.split(',').map(item => { return baseApi + item }) : []"
                  style="width: 100px;"
                >
                  <div slot="placeholder" class="image-slot">
                    加载中...
                  </div>
                  <div slot="error" class="image-slot">
                    暂无图片
                  </div>
                </el-image>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="150px" align="center">
              <template slot-scope="scope">
                <el-button size="mini" type="primary" icon="el-icon-edit" @click="reimbursementEdit(scope.row)" />
                <el-button size="mini" type="danger" icon="el-icon-delete" @click="reimbursementDelete(scope.row)" />
              </template>
            </el-table-column>
          </el-table>
          <el-form-item label="备注" style="margin-top: 20px;">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 440px;" />
          </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 type="expand">
          <template slot-scope="props">
            <el-table :data="props.row.businessExpenseReimbursementDtoList" style="margin: 10px 20px 10px 105px; width: calc(100% - 20px - 105px);">
              <el-table-column :show-overflow-tooltip="true" prop="reimbursementContent" label="报销内容" />
              <el-table-column :show-overflow-tooltip="true" prop="reimbursementAmount" label="报销金额">
                <template slot-scope="scope">
                  {{ crud.toMoney(scope.row.reimbursementAmount) }}
                </template>
              </el-table-column>
              <el-table-column :show-overflow-tooltip="true" prop="reimbursementVoucher" label="报销凭证">
                <template slot-scope="scope">
                  <el-image
                    :src="scope.row.reimbursementVoucher != null && scope.row.reimbursementVoucher !== '' ? baseApi + scope.row.reimbursementVoucher.split(',')[0] : ''"
                    :preview-src-list="scope.row.reimbursementVoucher != null && scope.row.reimbursementVoucher !== '' ? scope.row.reimbursementVoucher.split(',').map(item => { return baseApi + item }) : []"
                    style="width: 100px;"
                  >
                    <div slot="placeholder" class="image-slot">
                      加载中...
                    </div>
                    <div slot="error" class="image-slot">
                      暂无图片
                    </div>
                  </el-image>
                </template>
              </el-table-column>
              <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注" />
            </el-table>
          </template>
        </el-table-column>
        <el-table-column prop="expenseType" label="费用类型">
          <template slot-scope="scope">
            {{ dict.label[expenseType][scope.row.expenseType] }}
          </template>
        </el-table-column>
        <el-table-column prop="businessPlanContent" label="所属营业计划" />
        <el-table-column prop="projectName" label="所属项目" />
        <el-table-column prop="amountReimbursementAmount" label="报销总金额">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.amountReimbursementAmount) }}
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="操作" width="150px" align="center">
          <template slot-scope="scope">
            {{ scope.row.id }}
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="reimbursementCancel" :visible.sync="reimbursementStatus" :title="reimbursementTitle" width="600px">
        <el-form ref="reimbursementForm" :model="reimbursementForm" :rules="reimbursementRules" size="small" label-width="140px">
          <el-form-item label="报销内容" prop="reimbursementContent">
            <el-input v-model="reimbursementForm.reimbursementContent" style="width: 340px;" />
          </el-form-item>
          <el-form-item label="报销金额" prop="reimbursementAmount">
            <money-input :key="random" v-model="reimbursementForm.reimbursementAmount" :width="340" />
          </el-form-item>
          <el-form-item label="报销凭证">
            <image-upload ref="imageUpload" :key="random" :image-url="reimbursementForm.reimbursementVoucher == null || reimbursementForm.reimbursementVoucher === '' ? null : reimbursementForm.reimbursementVoucher" :limit="3" @imageInfo="getImageInfo" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="reimbursementForm.remarks" :rows="3" type="textarea" style="width: 340px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="reimbursementCancel">取消</el-button>
          <el-button :loading="reimbursementLoading" type="primary" @click="reimbursementSubmit('reimbursementForm')">确认</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
 
<script>
import crudBusinessExpenseFlowable from '@/api/business/expenseFlowable'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import constant from '../../../utils/constant'
import crudBusinessPlan from '@/api/business/plan'
import crudProject from '@/api/project/project'
import moneyInput from '../../assembly/moneyInput/index.vue'
import imageUpload from '../../assembly/imageUpload/index.vue'
import { mapGetters } from 'vuex'
 
const defaultForm = { id: null, expenseType: null, businessPlanId: null, projectId: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null, businessExpenseReimbursementDtoList: [] }
export default {
  name: 'BusinessExpenseFlowableReport',
  components: { pagination, crudOperation, moneyInput, imageUpload },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.EXPENSE_TYPE],
  cruds() {
    return CRUD({ title: '营业费用', url: 'api/businessExpenseFlowable/report', idField: 'id', sort: 'id,desc', crudMethod: { ...crudBusinessExpenseFlowable }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'businessExpenseFlowable:add'],
        edit: ['admin', 'businessExpenseFlowable:edit'],
        del: ['admin', 'businessExpenseFlowable:del'],
        download: ['admin', 'businessExpenseFlowable:download']
      },
      rules: {
        expenseType: [
          { required: true, message: '费用类型不能为空', trigger: 'change' }
        ],
        businessPlanId: [
          { required: true, message: '所属营业计划不能为空', trigger: 'change' }
        ]
      },
      // 字典:费用类型
      expenseType: constant.EXPENSE_TYPE,
      // 随机数
      random: 0,
      // 营业计划列表
      businessPlanList: [],
      // 项目列表
      projectList: [],
      // 营业费用明细弹窗状态
      reimbursementStatus: false,
      // 营业费用明细弹窗标题
      reimbursementTitle: '营业费用明细',
      // 营业费用明细弹窗表单
      reimbursementForm: {},
      // 营业费用明细弹窗验证
      reimbursementRules: {
        businessExpenseId: [
          { required: true, message: '所属营业费用不能为空', trigger: 'change' }
        ],
        reimbursementContent: [
          { required: true, message: '报销内容不能为空', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ],
        reimbursementAmount: [
          { required: true, message: '报销金额不能为空', trigger: 'blur' }
        ]
      },
      // 营业费用明细弹窗操作
      reimbursementExecute: {},
      // 营业费用明细弹窗加载
      reimbursementLoading: false
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ])
  },
  created() {
    this.crud.optShow = {
      add: true,
      edit: false,
      del: false,
      download: false
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 获取营业计划
      this.getBusinessPlan()
      // 获取项目
      this.getProject()
      return true
    },
    // 获取营业计划
    getBusinessPlan() {
      // 获取营业计划
      crudBusinessPlan.getAll().then(res => {
        // 营业计划列表
        this.businessPlanList = res
      })
    },
    // 获取项目
    getProject() {
      // 获取项目
      crudProject.getAll().then(res => {
        // 项目列表
        this.projectList = res
      })
    },
    // 营业费用明细弹窗新增
    reimbursementAdd() {
      // 指针重定义
      const _this = this
      // 营业费用明细弹窗表单
      this.reimbursementForm = {}
      // 营业费用明细弹窗状态
      this.reimbursementStatus = true
      // 营业费用明细弹窗操作
      this.reimbursementExecute = {}
      // 表单清空
      setTimeout(function() {
        _this.$refs['reimbursementForm'].clearValidate()
      }, 3)
      // 随机数
      this.random = Math.random()
    },
    // 营业费用明细弹窗修改
    reimbursementEdit(data) {
      // 营业费用明细弹窗表单
      this.reimbursementForm = JSON.parse(JSON.stringify(data))
      // 营业费用明细弹窗状态
      this.reimbursementStatus = true
      // 营业费用明细弹窗操作
      this.reimbursementExecute = JSON.parse(JSON.stringify(data))
      // 随机数
      this.random = Math.random()
    },
    // 营业费用明细弹窗删除
    reimbursementDelete(data) {
      // 筛选费用明细人员
      const reimbursementInfo = this.crud.form.businessExpenseReimbursementDtoList.filter(function(item) {
        return item.reimbursementContent === data.reimbursementContent && item.reimbursementAmount === data.reimbursementAmount
      })
      // 获取下标
      const subscript = this.crud.form.businessExpenseReimbursementDtoList.indexOf(reimbursementInfo[0])
      // 营业费用明细移除元素
      this.crud.form.businessExpenseReimbursementDtoList.splice(subscript, 1)
    },
    // 营业费用明细弹窗关闭
    reimbursementCancel() {
      // 营业费用明细弹窗状态
      this.reimbursementStatus = false
    },
    // 营业费用明细弹窗提交
    reimbursementSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 通过“this.$refs.imageUpload”找到子页面,“submit”是子页面的方法。
          this.$refs.imageUpload.submit()
        } else {
          return false
        }
      })
    },
    // 获取图片信息
    getImageInfo(info) {
      // 判断返回数据
      if (info.length === 0) {
        // 表单图片路径赋值
        this.reimbursementForm.reimbursementVoucher = null
        // 表单提交
        this.reimbursementSubmitCU()
        // 终止
        return
      }
      // 循环返回数据
      for (let i = 0; i < info.length; i++) {
        // 判断循环下标
        if (i === 0) {
          // 表单图片路径赋值
          this.reimbursementForm.reimbursementVoucher = info[i].response == null || info[i].response === '' ? info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : '/file/' + info[i].response.type + '/' + info[i].response.realName
        } else {
          // 表单图片路径赋值
          this.reimbursementForm.reimbursementVoucher += info[i].response == null || info[i].response === '' ? ',' + info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : ',/file/' + info[i].response.type + '/' + info[i].response.realName
        }
        // 判断循环是否结束
        if (i === info.length - 1) {
          // 表单提交
          this.reimbursementSubmitCU()
        }
      }
    },
    // 表单提交
    reimbursementSubmitCU() {
      // 判断营业费用明细弹窗操作
      if (this.reimbursementExecute.reimbursementContent !== undefined) {
        // 营业费用明细弹编辑
        // 指针重定义
        const _this = this
        // 筛选营业费用明细弹
        const reimbursementInfo = this.crud.form.businessExpenseReimbursementDtoList.filter(function(item) {
          return item.reimbursementContent === _this.reimbursementExecute.reimbursementContent && item.reimbursementAmount === _this.reimbursementExecute.reimbursementAmount
        })
        // 营业费用明细弹更新
        reimbursementInfo[0].reimbursementContent = this.reimbursementForm.reimbursementContent
        reimbursementInfo[0].reimbursementAmount = this.reimbursementForm.reimbursementAmount
        reimbursementInfo[0].reimbursementVoucher = this.reimbursementForm.reimbursementVoucher
        reimbursementInfo[0].remarks = this.reimbursementForm.remarks
      } else {
        // 营业费用明细新增
        this.crud.form.businessExpenseReimbursementDtoList.push(this.reimbursementForm)
      }
      // 营业费用明细弹窗关闭
      this.reimbursementCancel()
    }
  }
}
</script>
 
<style scoped>
 
</style>