weicd
2023-02-20 6754df3c4faf22d426d45d1c4995c865cab686de
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
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.contractId" filterable clearable placeholder="所属合同" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in contractList"
            :key="item.contractId"
            :label="item.contractNumber + ' - ' + item.contractName"
            :value="item.contractId"
          />
        </el-select>
        <el-select v-model="query.fundType" filterable clearable placeholder="款项类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[fundType]"
            :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="630px">
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="所属合同" prop="contractId">
            <el-select v-model="form.contractId" filterable clearable placeholder="请选择" style="width: 495px;" @change="contractIdChange">
              <el-option
                v-for="item in contractList"
                :key="item.contractId"
                :label="item.contractNumber + ' - ' + item.contractName"
                :value="item.contractId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="付款时间" prop="paymentTime">
            <el-date-picker v-model="form.paymentTime" type="datetime" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="款项类型" prop="fundType">
            <el-select v-model="form.fundType" filterable placeholder="请选择" style="width: 200px;">
              <el-option
                v-for="item in dict[fundType]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="付款金额" prop="paymentAmount">
            <money-input :key="random" v-model="form.paymentAmount" :width="200" />
          </el-form-item>
          <!--魏传栋 - 始-->
          <el-form-item label="所属公司" prop="companyId">
            <el-select v-model="form.companyId" filterable clearable placeholder="请选择" style="width: 200px;">
              <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="paymentType">
            <el-select v-model="form.paymentType" filterable clearable placeholder="请选择" style="width: 200px;">
              <el-option
                v-for="item in dict[paymentType]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <!--魏传栋 - 终-->
          <span v-if="form.fundType == fundContract">
            <el-divider>合同费款项所属</el-divider>
            <el-form-item label="所属内容" prop="fundBelong">
              <el-input v-model="form.fundBelong" style="width: 495px;" />
            </el-form-item>
          </span>
          <span v-if="form.fundType == fundService">
            <el-divider>服务费款项所属</el-divider>
            <el-form-item label="所属年度" prop="fundBelongYear">
              <el-input v-model="form.fundBelongYear" style="width: 200px;" @change="changeFundBelongYear" />
            </el-form-item>
            <el-form-item label="">
              <span style="width: 200px;" />
            </el-form-item>
            <el-form-item label="开始日期" prop="fundBelongStart">
              <el-date-picker v-model="form.fundBelongStart" type="date" style="width: 200px;" disabled />
            </el-form-item>
            <el-form-item label="结束日期" prop="fundBelongEnd">
              <el-date-picker v-model="form.fundBelongEnd" type="date" style="width: 200px;" disabled />
            </el-form-item>
          </span>
          <el-form-item label="相关发票">
            <el-select v-model="form.contractInvoiceIds" filterable multiple placeholder="请选择" style="width: 495px;">
              <el-option
                v-for="item in contractInvoiceList"
                :key="item.invoiceId"
                :label="item.afterTaxAmount"
                :value="item.invoiceId"
              >
                <span style="float: left">开票金额:{{ item.afterTaxAmount }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">开票时间:{{ item.billingTime }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="备注信息" prop="remarks">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 495px;" />
          </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="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 :show-overflow-tooltip="true" prop="contractName" label="所属合同" />
        <el-table-column :show-overflow-tooltip="true" prop="paymentTime" label="付款时间" />
        <el-table-column :show-overflow-tooltip="true" prop="fundType" label="款项类型">
          <template slot-scope="scope">
            {{ dict.label[fundType][scope.row.fundType] }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="paymentAmount" label="付款金额">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.paymentAmount) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="companyName" label="所属公司" />
        <el-table-column :show-overflow-tooltip="true" prop="paymentType" label="收支类型">
          <template slot-scope="scope">
            {{ dict.label[paymentType][scope.row.paymentType] }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="fundBelong" label="款项所属">
          <template slot-scope="scope">
            <span v-if="scope.row.fundBelong != null">
              {{ scope.row.fundBelong }}
            </span>
            <span v-if="scope.row.fundBelongStart != null && scope.row.fundBelongEnd != null">
              {{ scope.row.fundBelongStart.substring(0,10) }} 至 {{ scope.row.fundBelongEnd.substring(0,10) }} 服务费
            </span>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注信息" />
        <el-table-column v-if="checkPer(['admin','contractPayment:edit','contractPayment: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 crudContractPayment from '@/api/contract/contractPayment'
import crudSysCompany from '@/api/system/sysCompany'
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'
import crudContract from '@/api/contract/contract'
import crudContractInvoice from '@/api/contract/contractInvoice'
 
const defaultForm = { paymentId: null, contractId: null, paymentTime: null, fundType: null, paymentAmount: null, fundBelong: null, fundBelongYear: null, fundBelongStart: null, fundBelongEnd: null, remarks: null, contractInvoiceIds: [], createBy: null, updateBy: null, createTime: null, updateTime: null, companyId: null, paymentType: null }
export default {
  name: 'ContractPayment',
  components: { pagination, crudOperation, rrOperation, udOperation, moneyInput },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.FUND_TYPE, constant.CONTRACR_TYPE_COST],
  cruds() {
    return CRUD({ title: '合同付款', url: 'api/contractPayment', idField: 'paymentId', sort: 'paymentId,desc', crudMethod: { ...crudContractPayment }})
  },
  data() {
    // 付款金额校验规则
    var validatePaymentAmount = (rule, value, callback) => {
      if (value !== null) {
        if (isNaN(Number(value))) {
          callback(new Error('请输入数字值'))
        } else {
          if (value < 0 || value > 1000000000) {
            callback(new Error('付款金额不能超过10亿'))
          } else {
            callback()
          }
        }
      } else {
        callback(new Error('付款金额不能为空'))
      }
    }
    return {
      permission: {
        add: ['admin', 'contractPayment:add'],
        edit: ['admin', 'contractPayment:edit'],
        del: ['admin', 'contractPayment:del'],
        download: ['admin', 'contractPayment:download']
      },
      rules: {
        contractId: [
          { required: true, message: '请选择所属合同', trigger: 'change' }
        ],
        paymentTime: [
          { required: true, message: '请选择付款时间', trigger: 'change' }
        ],
        fundType: [
          { required: true, message: '请选择款项类型', trigger: 'change' }
        ],
        paymentAmount: [
          { required: true, validator: validatePaymentAmount, trigger: 'blur' }
        ],
        fundBelong: [
          { min: 2, max: 100, message: '长度在 2 到 100 个字符', trigger: 'blur' }
        ],
        fundBelongYear: [
          { required: true, message: '请输入所属年度', trigger: 'blur' }
        ],
        fundBelongStart: [
          { required: true, message: '请选择款项开始日期', trigger: 'change' }
        ],
        fundBelongEnd: [
          { required: true, message: '请选择款项结束日期', trigger: 'change' }
        ],
        companyId: [
          { required: true, message: '请选择所属公司', trigger: 'change' }
        ],
        paymentType: [
          { required: true, message: '请选择收支类型', trigger: 'change' }
        ]
      },
      queryTypeOptions: [
        { key: 'contractId', display_name: '所属合同' },
        { key: 'fundType', display_name: '款项类型' }
      ],
      // 字典:款项类型
      fundType: constant.FUND_TYPE,
      // 字典:款项类型-合同费
      fundContract: constant.FUND_CONTRACT,
      // 字典:款项类型-服务费
      fundService: constant.FUND_SERVICE,
      // 随机数
      random: 0,
      // 合同数据
      contractList: [],
      // 发票数据
      contractInvoiceList: [],
      // 当前合同信息
      currentContract: {},
      // 公司
      companyList: [],
      // 字典:收支类型
      paymentType: constant.CONTRACR_TYPE_COST
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 获取合同数据
      this.getContractList()
      // 检索条件赋值
      if (this.$route.query.contractId != null && this.crud.query.contractId === undefined) {
        this.$set(this.crud.query, 'contractId', Number(this.$route.query.contractId))
      }
      // 获取公司数据
      crudSysCompany.getAll().then(res => {
        this.companyList = res
      })
      return true
    },
    // 获取合同数据
    getContractList() {
      const that = this
      // 获取合同数据
      crudContract.getAll().then(res => {
        // 获取合同数据
        that.contractList = res
        // 判断是否传参进入
        if (that.$route.query.contractId != null) {
          // 循环合同数据
          for (let i = 0; i < res.length; i++) {
            if (res[i].contractId === Number(that.$route.query.contractId)) {
              // 当前合同信息
              that.currentContract = res[i]
              // 当前合同信息 - 服务结束日期
              that.currentContract.serviceEndDate = new Date(res[i].serviceStartsDate).getTime() - 24 * 60 * 60 * 1000
            }
          }
        }
      })
    },
    // 钩子:开始 "新建/编辑" - 之前
    [CRUD.HOOK.beforeToCU]() {
      const that = this
      // 随机数
      that.random = Math.random()
      // 表单合同所属年份
      if (that.crud.form.fundBelongStart != null) {
        that.crud.form.fundBelongYear = that.crud.form.fundBelongStart.substring(0, 4)
      }
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      const that = this
      // 判断检索条件
      if (that.crud.query.contractId !== undefined) {
        // 表单赋值
        that.$set(that.crud.form, 'contractId', Number(that.crud.query.contractId))
        // 所属合同变更
        that.contractIdChange()
      }
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      const that = this
      // 获取发票数据
      that.getContractInvoice()
    },
    // 所属合同变更
    contractIdChange() {
      const that = this
      // 相关发票
      that.crud.form.contractInvoiceIds = []
      // 获取发票数据
      that.contractInvoiceList = []
      // 判断所属合同是否为空
      if (that.crud.form.contractId != null && that.crud.form.contractId !== '') {
        // 获取发票数据
        that.getContractInvoice()
      }
    },
    // 获取发票数据
    getContractInvoice() {
      const that = this
      // 获取发票数据
      crudContractInvoice.getAll({ contractId: that.crud.form.contractId }).then(res => {
        // 获取发票数据
        that.contractInvoiceList = res
      })
    },
    // 表单提交
    submitCU() {
      const that = this
      // 判断款项类型
      if (that.crud.form.fundType === that.fundContract) {
        // 款项所属年度
        that.crud.form.fundBelongYear = null
        // 款项开始日期
        that.crud.form.fundBelongStart = null
        // 款项结束日期
        that.crud.form.fundBelongEnd = null
      } else if (that.crud.form.fundType === that.fundService) {
        // 款项所属
        that.crud.form.fundBelong = null
      } else {
        // 暂无
      }
      // 表单提交
      that.crud.submitCU()
    },
    // 所属年度变更
    changeFundBelongYear() {
      const that = this
      // 款项开始日期
      that.crud.form.fundBelongStart = that.crud.form.fundBelongYear + that.crud.toDate(that.currentContract.serviceStartsDate).substring(4, 10)
      // 款项结束日期
      that.crud.form.fundBelongEnd = that.crud.toDate(that.currentContract.serviceEndDate).substring(4, 10) === '-12-31'
        ? Number(that.crud.form.fundBelongYear) + that.crud.toDate(that.currentContract.serviceEndDate).substring(4, 10)
        : (Number(that.crud.form.fundBelongYear) + 1) + that.crud.toDate(that.currentContract.serviceEndDate).substring(4, 10)
    }
  }
}
</script>
 
<style scoped>
 
</style>