yaozc
2023-07-07 c752e33fe402e2179e7e6795f567d41c044ca3c6
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <el-input
          v-model="query.number"
          clearable
          size="small"
          placeholder="编号"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.name"
          clearable
          size="small"
          placeholder="名称"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select v-model="query.affiliatedCompanyId" filterable clearable placeholder="所属公司" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in companyList"
            :key="item.id"
            :label="item.label"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.state" filterable clearable placeholder="使用状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[dictAccteUse]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <el-button
          slot="right"
          v-permission="permission.divide"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-share"
          :disabled="crud.selections.length !== 1"
          style="margin-left: 0px !important;"
          @click="toDivide(crud.selections[0])"
        >
          分配
        </el-button>
        <el-button
          slot="right"
          v-permission="permission.seeDivide"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-view"
          :disabled="crud.selections.length !== 1"
          style="margin-left: 4px !important;"
          @click="toAssetUseManagement(crud.selections[0])"
        >
          查看分配
        </el-button>
      </crudOperation>
      <!--表单组件-->
      <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="number">
            <el-input v-model="form.number" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="型号">
            <el-input v-model="form.typeNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="资产类型" prop="assetsType">
            <el-select v-model="form.assetsType" clearable style="width: 370px;">
              <el-option
                v-for="item in dict[dictAccetType]"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="购买日期">
            <el-date-picker
              v-model="form.buyDate"
              type="datetime"
              placeholder="选择日期时间"
              style="width: 370px;"
              value-format="yyyy-MM-dd HH:mm:ss"
              align="right"
            />
          </el-form-item>
          <el-form-item label="购买金额" prop="buyMoney">
            <money-input :key="random" v-model="form.buyMoney" :width="370" />
          </el-form-item>
          <el-form-item label="所属公司" prop="affiliatedCompanyId">
            <el-select v-model="form.affiliatedCompanyId" style="width: 370px" clearable>
              <el-option v-for="item in companyList" :key="item.id" :label="item.label" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="使用状态" prop="state">
            <el-select v-model="form.state" clearable style="width: 370px;">
              <el-option
                v-for="item in dict[dictAccteUse]"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" type="textarea" rows="3" style="width: 370px;" />
          </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-dialog :close-on-click-modal="false" :before-close="divideClose" :visible.sync="divideStatus" :title="crudStatusTitle" width="500px">
        <el-form ref="assUserManagementForm" :model="assUserManagementForm" :rules="rules" size="small" label-width="110px">
          <el-form-item label="编号">
            {{ assUserManagementForm.number }}
          </el-form-item>
          <el-form-item label="名称">
            {{ assUserManagementForm.name }}
          </el-form-item>
          <el-form-item label="员工">
            <el-select v-model="assUserManagementForm.userId" filterable clearable placeholder="请选择" style="width: 330px;">
              <el-option
                v-for="item in users"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
                :disabled="!item.enabled"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="所属会议室">
            <el-select v-model="assUserManagementForm.meetingId" filterable clearable placeholder="请选择" style="width: 330px;">
              <el-option
                v-for="item in meetingRooms"
                :key="item.id"
                :label="item.conferenceRoomName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="使用开始日期" prop="useStartTime">
            <el-date-picker
              v-model="assUserManagementForm.useStartTime"
              type="date"
              placeholder="选择日期时间"
              style="width: 330px;"
              value-format="yyyy-MM-dd"
              align="right"
              :picker-options="{
                disabledDate(time) {
                  return assUserManagementForm.useEndTime ? time.getTime() > new Date(assUserManagementForm.useEndTime).getTime() - 8.64e7 : false;
                }
              }"
            />
          </el-form-item>
          <el-form-item label="使用结束时间">
            <el-date-picker
              v-model="assUserManagementForm.useEndTime"
              type="date"
              placeholder="选择日期时间"
              style="width: 330px;"
              value-format="yyyy-MM-dd"
              align="right"
              :picker-options="{
                disabledDate(time) {
                  return assUserManagementForm.useStartTime ? time.getTime() < new Date(assUserManagementForm.useStartTime).getTime() - 8.64e7 : false;
                }
              }"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="divideClose">取消</el-button>
          <el-button :loading="divideLoading" type="primary" @click="divideSubmit">确认</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="number" label="编号" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.number }}
          </template>
        </el-table-column>
        <el-table-column prop="name" label="名称" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.name }}
          </template>
        </el-table-column>
        <el-table-column prop="typeNumber" label="型号" show-overflow-tooltip />
        <el-table-column prop="assetsType" label="资产类型" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag>
              {{ dict.label[dictAccetType][scope.row.assetsType] }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="buyDate" label="购买日期" show-overflow-tooltip />
        <el-table-column prop="buyMoney" label="购买金额" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.buyMoney) }}
          </template>
        </el-table-column>
        <el-table-column prop="affiliatedCompanyId" label="所属公司" show-overflow-tooltip>
          <template slot-scope="scope">
            <template v-for="item in companyList">
              <el-tag v-if="scope.row.affiliatedCompanyId == item.id" :key="item.id">{{ item.label }}</el-tag>
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="state" label="使用状态" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag>{{ dict.label[dictAccteUse][scope.row.state] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column v-if="checkPer(['admin','assetManagement:edit','assetManagement:del'])" label="操作" width="180px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            >
              <el-button
                slot="left"
                v-permission="permission.divide"
                size="mini"
                type="primary"
                icon="el-icon-share"
                @click="toDivide(scope.row)"
              />
            </udOperation>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
 
<script>
import crudAssetManagement from '@/api/assetManagement/assetManagement'
import crudSysCompany from '@/api/system/sysCompany'
import crudUser from '@/api/system/user'
import crudMeetingRoom from '@/api/conferenceRoom/meetingRoom'
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 '../../assembly/moneyInput/index.vue'
 
const defaultForm = { id: null, number: null, name: null, typeNumber: null, assetsType: null, buyDate: null, buyMoney: null, affiliatedCompanyId: null, state: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'AssetManagement',
  components: { pagination, crudOperation, rrOperation, udOperation, moneyInput },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  // 数据字典
  dicts: [constant.ACCET_TYPE, constant.ACCETS_USE],
  cruds() {
    return CRUD({ title: '资产记录', url: 'api/assetManagement', idField: 'id', sort: 'id,desc', crudMethod: { ...crudAssetManagement }})
  },
  data() {
    // (千万内)验证
    var wageValidate = (rule, value, callback) => {
      if (value != null && value !== '' && (isNaN(value) || Number(value) < 0 || Number(value) > 10000000)) {
        callback(new Error('请输入 一千万 以内的正整数或两位小数'))
      } else {
        callback()
      }
    }
    return {
      permission: {
        add: ['admin', 'assetManagement:add'],
        edit: ['admin', 'assetManagement:edit'],
        del: ['admin', 'assetManagement:del'],
        download: ['admin', 'assetManagement:download'],
        divide: ['admin', 'assetManagement:divide'],
        seeDivide: ['admin', 'assetManagement:seeDivide']
      },
      rules: {
        number: [
          { required: true, message: '编号不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        assetsType: [
          { required: true, message: '资产类型不能为空', trigger: 'change' }
        ],
        affiliatedCompanyId: [
          { required: true, message: '所属公司不能为空', trigger: 'change' }
        ],
        state: [
          { required: true, message: '使用状态不能为空', trigger: 'change' }
        ],
        useStartTime: [
          { required: true, message: '使用开始时间不能为空', trigger: 'change' }
        ],
        buyMoney: [
          { validator: wageValidate, trigger: 'blur' }
        ]
      },
      dictAccetType: constant.ACCET_TYPE,
      companyList: [],
      dictAccteUse: constant.ACCETS_USE,
      dictOnStart: constant.ACCETS_USE_IN,
      dictOffStart: constant.ACCETS_USE_STOP,
      random: 0,
      assUserManagementForm: { assetId: null, userId: null, meetingId: null, useStartTime: null, useEndTime: null, number: null, name: null, divideUserIds: [] },
      divideStatus: false,
      divideLoading: false,
      users: [],
      meetingRooms: [],
      crudStatusTitle: '分配资产',
      assetUseManagements: []
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 查询配置参数
      crudSysCompany.getAll().then(res => {
        // 公司列表
        this.companyList = res
      })
      // 用户
      crudUser.getAll().then(res => {
        this.users = res
      })
      // 会议室
      crudMeetingRoom.getAll().then(res => {
        this.meetingRooms = res
      })
      return true
    },
    // 钩子: 在新增前执行
    [CRUD.HOOK.beforeToCU]() {
      // 随机数
      this.random = Math.random()
    },
    // 查看资产使用管理
    toAssetUseManagement(data) {
      console.log(data)
      // 跳转页面
      this.$router.push({
        name: 'assetUseManagement',
        params: {
          assetId: data.id
        }
      })
    },
    // 分配资产使用
    toDivide(data) {
      if (data.state === this.dictOffStart) {
        this.crud.notify('使用状态已停止,无法分配', CRUD.NOTIFICATION_TYPE.ERROR)
      } else {
        this.assUserManagementForm.assetId = data.id
        this.assUserManagementForm.userId = data.userId
        this.assUserManagementForm.number = data.number
        this.assUserManagementForm.name = data.name
        this.divideStatus = true
      }
    },
    // 分配表单提交
    divideSubmit() {
      if (this.assUserManagementForm.userId === '' || this.assUserManagementForm.userId === undefined) {
        this.assUserManagementForm.userId = null
      }
      if (this.assUserManagementForm.meetingId === '' || this.assUserManagementForm.meetingId === undefined) {
        this.assUserManagementForm.meetingId = null
      }
      if (this.assUserManagementForm.userId !== null && this.assUserManagementForm.meetingId != null) {
        // 消息提示
        this.crud.notify('用户和会议室只能选择一个', CRUD.NOTIFICATION_TYPE.ERROR)
        return
      }
      if (this.assUserManagementForm.userId == null && this.assUserManagementForm.meetingId == null) {
        // 消息提示
        this.crud.notify('用户和会议室必须选择一个', CRUD.NOTIFICATION_TYPE.ERROR)
        return
      }
      // 分配表单加载
      this.divideLoading = true
      // 表单验证
      this.$refs['assUserManagementForm'].validate((valid) => {
        if (valid) {
          // 分配任务
          crudAssetManagement.divide(this.assUserManagementForm).then(res => {
            // 分配表单关闭
            this.divideClose()
            // 消息提示
            this.crud.notify('资产分配成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
            // 刷新页面
            this.crud.refresh()
          })
          this.divideLoading = false
        } else {
          // 分配表单加载
          this.divideLoading = false
          return false
        }
      })
    },
    // 分配表单关闭
    divideClose() {
      // 分配表单状态
      this.divideStatus = false
      // 分配表单加载
      this.divideLoading = false
      // 清除表单验证
      this.$nextTick(() => {
        this.$refs['assUserManagementForm'].clearValidate()
      })
    }
  }
}
</script>
 
<style scoped>
 
</style>