zhaoxiaoqiang1
2026-01-04 f1d30d03186c79ca2cbcfe60d6d2ce7d73fba97b
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
<template>
  <div class="apply-info">
    <SectionTitle title="补开发票信息"></SectionTitle>
    <div class="middle-button" v-if="isEdit">
      <el-button
        type="primary"
        @click="addRecord"
        icon="el-icon-circle-plus-outline"
        size="small"
      >新增发票</el-button>
    </div>
    <CommTable
      :list="list"
      :header="tableHeader"
      @doAction="doAction"
      @updateValue="updateValue"
      ref="fillTable"
    ></CommTable>
    <Dialog
      v-model="isShowDel"
      title="删除确认"
      :buttons="[{text: '取消'}, {text: '确定', type: 'primary'}]"
      @handleClick="doDel"
    >
      <!-- <p class="del-id">{{tempRecord.serialNo || ''}}</p> -->
      <p class="del-id">请确认是否删除该笔记录?</p>
    </Dialog>
 
    <Dialog
      v-model="isShowSucc"
      icon="succ"
      iconText="提交成功"
      :close="false"
      :buttons="[{text: '确定', type: 'primary'}]"
      @handleClick="sureSucc"
    ></Dialog>
  </div>
</template>
<script>
// 补开发票信息
import { mapState, mapActions } from 'vuex'
import CommTable from '@/components/CommTable'
import Dialog from '@/components/Dialog'
import SectionTitle from '@/components/SectionTitle'
import queryFillOpenInvoiceInfo from '@/controller/queryFillOpenInvoiceInfo'
import saveFillOpenInvoice from '@/controller/saveFillOpenInvoice'
import delFillOpenInvoice from '@/controller/delFillOpenInvoice'
import invoiceAdjustSubmit from '@/controller/invoiceAdjustSubmit'
 
const addButtons = [
  { text: '取消', prop: 'cancleButton' },
  { text: '保存', prop: 'addButton' }
]
 
const normalButtons = [{ text: '删除', prop: 'deleteButton' }]
 
export default {
  components: {
    CommTable,
    SectionTitle,
    Dialog
  },
  props: {
    conf: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      isShowDel: false,
      isShowSucc: false,
      tableHeader: [],
      model: null,
      addModel: null,
      delModel: null,
      submitModel: null,
      list: [],
      pageInfo: {
        currentPage: 1,
        pageSize: 10
      },
      total: 0,
      isDoingAdd: false,
      currentIndex: 0,
      records: [],
      tempRecord: {}
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      const { $route, isEdit } = this
      const { query } = $route
      this.query = query
      const model = queryFillOpenInvoiceInfo()
      const tableHeader = model.getTableList()
      this.delModel = delFillOpenInvoice()
      this.tableHeader = isEdit
        ? tableHeader
        : tableHeader.filter(({ type }) => type !== 'buttons')
      this.model = model
      this.addModel = saveFillOpenInvoice()
      this.submitModel = invoiceAdjustSubmit()
      this.getList()
    },
    async getList() {
      const { model, query, pageInfo } = this
      const { invoiceSerialno } = query
      const { list = [] } = await model.request({
        ...pageInfo,
        invoiceSerialno
      })
      this.list = list.map(item => ({
        ...item,
        action: {
          buttons: normalButtons
        }
      }))
      this.tempRecord = {}
      // this.total = parseInt(total)
    },
 
    // 新增
    addRecord() {
      const { isDoingAdd, list } = this
      if (isDoingAdd) {
        return false
      }
      this.list = [{ ...this.getEditRecord() }, ...list]
      this.currentIndex = 0
      this.isDoingAdd = true
    },
 
    getEditRecord() {
      const { tableHeader, invoiceInfo, addModel } = this
      const { invoiceSeller = '', invoiceBuyer = '' } = invoiceInfo
      const formList = addModel.getFormList({ invoiceSeller, invoiceBuyer })
      return tableHeader.reduce((pre, { prop, isMoney = false }) => {
        if (prop === 'action') {
          pre[prop] = {
            buttons: addButtons
          }
        } else {
          const inputItem = formList.find(({ name }) => name === prop)
          if (inputItem) {
            pre[prop] = { value: '', ...inputItem }
          }
        }
        return pre
      }, {})
    },
 
    updateValue(val, inputItem, parentName, recordIndex = 0) {
      const { list } = this
      const { name } = inputItem
      const listItem = list[recordIndex]
      const key = Object.keys(listItem).find(k => k === name)
      this.$set(list, recordIndex, {
        ...listItem,
        [key]: { ...listItem[key], value: val }
      })
    },
 
    // 表格按钮事件处理
    doAction(item, record, index) {
      const { prop } = item
      this.currentIndex = index
      if (prop === 'deleteButton') {
        this.tempRecord = { ...record }
        this.isShowDel = true
      }
      if (prop === 'cancleButton') {
        this.cancle()
      }
      if (prop === 'addButton') {
        this.toSubmit()
      }
    },
 
    async toSubmit() {
      const { list, currentIndex, query, addModel, info } = this
      const { invoiceSerialno } = query
      const { unRelativeAmount = 0 } = info
      const [err, values] = this.$refs.fillTable.validate(list[currentIndex])
      if (err) {
        this.$message.warning(err)
      } else {
        const unAmount = Math.abs(unRelativeAmount)
        if (Number(values.invoiceAmt) > unAmount) {
          // 财务开票阶段 提交时,当新增关联信息、删除关联信息、补开发票新增、删除
          // 均需要刷新开票基本信息, 当开票金额> 申请开票金额  则提示 开票金额不能大于申请开票金额
          this.$message.warning(
            `开票金额不能大于未关联贴息金额 ${unAmount || ''}`
          )
          return false
        }
 
        await addModel.request({
          invoiceSerialno,
          ...values
        })
        this.updateInfo()
        this.isShowSucc = true
      }
    },
 
    async submit() {
      const { query, submitModel } = this
      const { invoiceSerialno, fromButton } = query
      if (fromButton === 'invoiceAdjustButton') {
        await submitModel.request({
          invoiceSerialno
        })
        this.isShowSucc = true
        this.currentIndex = -1
        this.updateInfo()
      }
    },
 
    doDel(index) {
      if (index === 0) {
        this.isShowDel = false
      } else {
        this.toDel()
      }
    },
 
    cancle() {
      const { list } = this
      this.list = list.filter((item, index) => index > 0)
      this.isDoingAdd = false
    },
 
    sureSucc() {
      const { currentIndex } = this
      this.isShowSucc = false
      if (currentIndex === -1) {
        this.commitSuccess()
      } else {
        this.isDoingAdd = false
        this.getList()
      }
    },
 
    // 更新开票基本信息
    updateInfo() {
      const { transCode, invoiceSerialno } = this.query
      this.queryBaseDiscountInvoiceInfo({
        transCode,
        invoiceSerialno
      })
    },
 
    // 提交成功后返回原列表页
    commitSuccess() {
      this.$router.go(-1)
    },
 
    async toDel() {
      const { tempRecord, delModel } = this
      await delModel.request({
        serialNo: tempRecord.serialNo
      })
      this.isShowDel = false
      this.isShowSucc = true
      this.updateInfo()
    },
    ...mapActions(['queryBaseDiscountInvoiceInfo'])
  },
  computed: {
    isEdit() {
      const { conf } = this
      return conf.edit === 'Y'
    },
    ...mapState({
      invoiceAmount: state => state.tabsModule.invoiceAmount,
      invoiceInfo: state => state.tabsModule.invoiceInfo,
      info: state => state.tabsModule.baseDiscountInvoiceInfo
    })
  },
  watch: {
    $route() {
      const { invoiceSerialno } = this.$route.query
      if (invoiceSerialno) {
        this.init()
      }
    }
  }
}
</script>
<style lang="postcss" scoped>
.middle-button {
  margin-bottom: 20px;
}
.del-id {
  text-align: center;
  padding-bottom: 20px;
}
</style>