EditInvoice.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!--
  2. * @Author: liuzl 461480418@qq.com
  3. * @Date: 2023-01-09 15:34:20
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-01-10 09:53:19
  6. * @Description: file content
  7. * @FilePath: \订单全流程管理系统\src\views\contract\components\EditInvoice.vue
  8. -->
  9. <template>
  10. <el-dialog :title="title" :visible.sync="editVisible" @close="handleClose">
  11. <el-form ref="editForm" :model="editForm" :rules="editRules">
  12. <el-row :gutter="20">
  13. <el-col :span="12">
  14. <el-form-item label="合同编号" prop="contractCode">
  15. <el-input v-model="editForm.contractCode" :disabled="Boolean(details)" placeholder="请输入合同编号" />
  16. </el-form-item>
  17. </el-col>
  18. <el-col :span="12">
  19. <el-form-item label="开票金额" prop="invoiceAmount">
  20. <el-input v-model.number="editForm.invoiceAmount" clearable placeholder="请输入开票金额" />
  21. </el-form-item>
  22. </el-col>
  23. </el-row>
  24. <el-row :gutter="20">
  25. <el-col :span="12">
  26. <el-form-item label="开票日期" prop="invoiceDate">
  27. <el-date-picker
  28. v-model="editForm.invoiceDate"
  29. placeholder="选择开票日期"
  30. style="width: 100%"
  31. type="date"
  32. value-format="yyyy-MM-dd" />
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="12">
  36. <el-form-item label="开票类型" prop="invoiceType">
  37. <el-select v-model="editForm.invoiceType" placeholder="请选择开票类型" style="width: 100%">
  38. <el-option v-for="item in invoiceTypeData" :key="item.key" :label="item.value" :value="item.key" />
  39. </el-select>
  40. </el-form-item>
  41. </el-col>
  42. </el-row>
  43. <el-row :gutter="20">
  44. <el-col :span="12">
  45. <el-form-item label="备注" prop="remark">
  46. <el-input v-model="editForm.remark" clearable placeholder="请输入备注" rows="5" type="textarea" />
  47. </el-form-item>
  48. </el-col>
  49. </el-row>
  50. </el-form>
  51. <span slot="footer">
  52. <el-button v-show="!editForm.id" type="primary" @click="invoiceSave">保存</el-button>
  53. <el-button v-show="editForm.id" type="primary" @click="contractEdit">保存</el-button>
  54. <el-button @click="editVisible = false">取消</el-button>
  55. </span>
  56. </el-dialog>
  57. </template>
  58. <script>
  59. import to from 'await-to-js'
  60. import invoiceApi from '@/api/contract/invoice'
  61. export default {
  62. props: {
  63. details: {
  64. type: Object,
  65. default: () => {},
  66. },
  67. invoiceTypeData: {
  68. type: Array,
  69. default: () => [],
  70. },
  71. },
  72. data() {
  73. return {
  74. title: '新建发票',
  75. editVisible: false,
  76. editForm: {
  77. invoiceDate: '', //开票日期
  78. contractCode: '', //合同编号
  79. contractId: null, //合同id
  80. invoiceAmount: '', //开票金额
  81. invoiceType: '', //开票类型
  82. remark: '', //备注
  83. },
  84. editRules: {
  85. contractCode: [{ required: true, trigger: 'blur', message: '请选择合同' }],
  86. invoiceAmount: [{ required: true, trigger: 'blur', message: '请输入开票金额' }],
  87. invoiceDate: [{ required: true, trigger: 'change', message: '请选择开票日期' }],
  88. invoiceType: [{ required: true, trigger: 'chgange', message: '请输入开票类型' }],
  89. },
  90. }
  91. },
  92. mounted() {},
  93. methods: {
  94. async init(id) {
  95. if (!id) {
  96. this.title = '新建发票'
  97. if (this.details) {
  98. console.log(this.details)
  99. this.editForm.contractCode = this.details.contractCode
  100. this.editForm.contractId = this.details.id
  101. console.log(this.editForm)
  102. }
  103. } else {
  104. this.title = '编辑发票'
  105. const [err, res] = await to(invoiceApi.getDetails({ id }))
  106. if (err) return
  107. if (res.data) {
  108. this.editForm = res.data
  109. }
  110. }
  111. this.editVisible = true
  112. },
  113. // 保存发票
  114. async invoiceSave() {
  115. let params = { ...this.editForm }
  116. const [valid] = await to(this.$refs.editForm.validate())
  117. if (valid == false) return
  118. const [err, res] = await to(invoiceApi.addInvoice(params))
  119. if (err) return
  120. if (res.code == 200) this.$message.success(res.msg)
  121. else return
  122. this.editVisible = false
  123. this.$emit('invoiceSave')
  124. },
  125. // 编辑发票
  126. async contractEdit() {
  127. let params = { ...this.editForm }
  128. const [valid] = await to(this.$refs.editForm.validate())
  129. if (valid == false) return
  130. const [err, res] = await to(invoiceApi.updateInvoice(params))
  131. if (err) return
  132. if (res.code == 200) this.$message.success(res.msg)
  133. else return
  134. this.editVisible = false
  135. this.$emit('invoiceSave')
  136. },
  137. handleClose() {
  138. this.editForm = {
  139. invoiceDate: '', //开票日期
  140. contractCode: '', //合同编号
  141. contractId: null, //合同id
  142. invoiceAmount: '', //开票金额
  143. invoiceType: '', //开票类型
  144. remark: '', //备注
  145. }
  146. this.$refs.editForm.resetFields()
  147. },
  148. },
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .mb10 {
  153. margin-bottom: 10px;
  154. }
  155. .proj-col {
  156. text-align: right;
  157. }
  158. </style>