InvoiceDialog.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <style scoped lang="scss">
  2. </style>
  3. <template>
  4. <div class="system-dialog-container">
  5. <el-dialog
  6. :title="state.dialog.title"
  7. v-model="state.dialog.isShowDialog"
  8. width="820px"
  9. draggable
  10. destroy-on-close
  11. :close-on-click-modal="false"
  12. align-center>
  13. <ext-detail-form
  14. ref="formRef"
  15. v-model="state.ruleForm"
  16. :columns="state.columns"
  17. :rules="state.rules"
  18. @on-change="handleFormChange"
  19. ></ext-detail-form>
  20. <template #footer>
  21. <span class="dialog-footer">
  22. <el-button @click="onCancel" size="default">取 消</el-button>
  23. <el-button :loading="state.btnLoading" type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
  24. </span>
  25. </template>
  26. </el-dialog>
  27. </div>
  28. </template>
  29. <script setup lang="ts" name="InvoiceDialog">
  30. import {defineAsyncComponent, reactive, onMounted, ref} from 'vue';
  31. import {Msg} from "/@/utils/message";
  32. import {$body, $get} from "/@/utils/request";
  33. import u from '/@/utils/u'
  34. // 引入组件
  35. const ExtDetailForm = defineAsyncComponent(() => import('/@/components/form/ExtDetailForm.vue'));
  36. // 定义子组件向父组件传值/事件
  37. const emit = defineEmits(['refresh']);
  38. const formRef = ref();
  39. //定义初始变量,重置使用
  40. const initState = ()=>({
  41. ruleForm: {
  42. id:0
  43. },
  44. btnLoading: false,
  45. dialog: {
  46. isShowDialog: false,
  47. type: '',
  48. title: '',
  49. submitTxt: '',
  50. },
  51. columns: [
  52. {label: '微信发票申请id', prop: 'applyId', type: 'text',},
  53. {label: '发票抬头填写人的openid', prop: 'openid', type: 'text',},
  54. {label: '发票关联订单详情', prop: 'orderDetails', type: 'user'},
  55. {label: '累积总金额(元)', prop: 'totalMoney', type: 'user',},
  56. {label: '累积电费(元)', prop: 'elecMoney', type: 'user',},
  57. {label: '累积服务费(元)', prop: 'serviceMoney', type: 'user',},
  58. {label: '接收发票邮箱', prop: 'email', type: 'text',},
  59. {label: '电话', prop: 'phone', type: 'text',},
  60. {label: '发票类型:INDIVIDUAL-个人 ORGANIZATION-企业', prop: 'invoiceType', type: 'text',},
  61. {label: '发票抬头名称', prop: 'invoiceTitle', type: 'text',},
  62. {label: '公司税号', prop: 'taxId', type: 'text',},
  63. {label: '公司地址', prop: 'address', type: 'text',},
  64. {label: '开户银行', prop: 'bankName', type: 'text',},
  65. {label: '银行账户', prop: 'bankAccount', type: 'text',},
  66. {label: '发票金额(单位:分)', prop: 'invoiceAmount', type: 'user',},
  67. {label: '税额详情信息', prop: 'taxInfo', type: 'user'},
  68. {label: '开票人', prop: 'biller', type: 'text',},
  69. {
  70. label: '发票状态:0-待开票 1-已开票 2-已作废',
  71. prop: 'status',
  72. sortable: 'custom',
  73. align: 'center',
  74. type: 'dict',
  75. conf: {dict: 'Invoice.status'}
  76. },
  77. {label: '发票状态:0-待开票 1-已开票 2-已作废', prop: 'status', type: 'user',},
  78. {label: '备注', prop: 'remark', type: 'text',},
  79. { label: '', prop: 'createTime', type: 'datetime',},
  80. { label: '', prop: 'updateTime', type: 'datetime',},
  81. ],
  82. rules: {},
  83. })
  84. // 定义变量内容
  85. const state = reactive(initState());
  86. // 打开弹窗
  87. const open = (action: string='add', row: any) => {
  88. state.dialog.title = u.dialog.actions[action].title +"『发票记录表』"
  89. state.dialog.submitTxt = u.dialog.actions[action].btn +"『发票记录表』"
  90. state.dialog.isShowDialog = true;
  91. if (action !=='add') {
  92. loadData(row.id);
  93. }else{
  94. state.ruleForm = Object.assign(state.ruleForm,row);
  95. }
  96. };
  97. // 关闭弹窗
  98. const onClose = () => {
  99. state.dialog.isShowDialog = false;
  100. Object.assign(state,initState())
  101. };
  102. // 取消
  103. const onCancel = () => {
  104. onClose();
  105. };
  106. // 提交
  107. const onSubmit = () => {
  108. formRef.value.checkForm().then(() => {
  109. state.btnLoading = true;
  110. const url = state.ruleForm.id > 0 ? "invoice/modify" : "invoice/add"
  111. $body(url, state.ruleForm).then(() => {
  112. state.btnLoading = false;
  113. Msg.message('操作成功');
  114. console.log('submit!')
  115. onClose();
  116. emit('refresh');
  117. })
  118. }).catch(() => {
  119. state.btnLoading = false;
  120. Msg.message('请先完整填写表单', 'error');
  121. })
  122. };
  123. const handleFormChange = (formData: any) => {
  124. console.log(formData)
  125. }
  126. // 初始化表格数据
  127. const loadData = (id: number) => {
  128. $get(`invoice/detail/${id}`).then((res: any) => {
  129. state.ruleForm = res;
  130. })
  131. }
  132. // 暴露变量
  133. defineExpose({
  134. open
  135. });
  136. </script>