FinancePaymentForm.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <Dialog :title="dialogTitle" v-model="dialogVisible" width="1080">
  3. <el-form
  4. ref="formRef"
  5. :model="formData"
  6. :rules="formRules"
  7. label-width="100px"
  8. v-loading="formLoading"
  9. :disabled="disabled"
  10. >
  11. <el-row :gutter="20">
  12. <el-col :span="8">
  13. <el-form-item label="付款单号" prop="no">
  14. <el-input disabled v-model="formData.no" placeholder="保存时自动生成" />
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="8">
  18. <el-form-item label="付款时间" prop="paymentTime">
  19. <el-date-picker
  20. v-model="formData.paymentTime"
  21. type="date"
  22. value-format="x"
  23. placeholder="选择付款时间"
  24. class="!w-1/1"
  25. />
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="8">
  29. <el-form-item label="供应商" prop="supplierId">
  30. <el-select
  31. v-model="formData.supplierId"
  32. clearable
  33. filterable
  34. placeholder="请选择供应商"
  35. class="!w-1/1"
  36. >
  37. <el-option
  38. v-for="item in supplierList"
  39. :key="item.id"
  40. :label="item.name"
  41. :value="item.id"
  42. />
  43. </el-select>
  44. </el-form-item>
  45. </el-col>
  46. <el-col :span="8">
  47. <el-form-item label="财务人员" prop="financeUserId">
  48. <el-select
  49. v-model="formData.financeUserId"
  50. clearable
  51. filterable
  52. placeholder="请选择财务人员"
  53. class="!w-1/1"
  54. >
  55. <el-option
  56. v-for="item in userList"
  57. :key="item.id"
  58. :label="item.nickname"
  59. :value="item.id"
  60. />
  61. </el-select>
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="16">
  65. <el-form-item label="备注" prop="remark">
  66. <el-input
  67. type="textarea"
  68. v-model="formData.remark"
  69. :rows="1"
  70. placeholder="请输入备注"
  71. />
  72. </el-form-item>
  73. </el-col>
  74. <el-col :span="8">
  75. <el-form-item label="附件" prop="fileUrl">
  76. <UploadFile :is-show-tip="false" v-model="formData.fileUrl" :limit="1" />
  77. </el-form-item>
  78. </el-col>
  79. </el-row>
  80. <!-- 子表的表单 -->
  81. <ContentWrap>
  82. <el-tabs v-model="subTabsName" class="-mt-15px -mb-10px">
  83. <el-tab-pane label="采购入库、退货单" name="item">
  84. <FinancePaymentItemForm
  85. ref="itemFormRef"
  86. :items="formData.items"
  87. :disabled="disabled"
  88. />
  89. </el-tab-pane>
  90. </el-tabs>
  91. </ContentWrap>
  92. <el-row :gutter="20">
  93. <el-col :span="8">
  94. <el-form-item label="付款账户" prop="accountId">
  95. <el-select
  96. v-model="formData.accountId"
  97. clearable
  98. filterable
  99. placeholder="请选择结算账户"
  100. class="!w-1/1"
  101. >
  102. <el-option
  103. v-for="item in accountList"
  104. :key="item.id"
  105. :label="item.name"
  106. :value="item.id"
  107. />
  108. </el-select>
  109. </el-form-item>
  110. </el-col>
  111. <el-col :span="8">
  112. <el-form-item label="合计付款" prop="totalPrice">
  113. <el-input disabled v-model="formData.totalPrice" :formatter="erpPriceInputFormatter" />
  114. </el-form-item>
  115. </el-col>
  116. <el-col :span="8">
  117. <el-form-item label="优惠金额" prop="discountPrice">
  118. <el-input-number
  119. v-model="formData.discountPrice"
  120. controls-position="right"
  121. :precision="2"
  122. placeholder="请输入优惠金额"
  123. class="!w-1/1"
  124. />
  125. </el-form-item>
  126. </el-col>
  127. <el-col :span="8">
  128. <el-form-item label="实际付款">
  129. <el-input
  130. disabled
  131. v-model="formData.paymentPrice"
  132. :formatter="erpPriceInputFormatter"
  133. />
  134. </el-form-item>
  135. </el-col>
  136. </el-row>
  137. </el-form>
  138. <template #footer>
  139. <el-button @click="submitForm" type="primary" :disabled="formLoading" v-if="!disabled">
  140. 确 定
  141. </el-button>
  142. <el-button @click="dialogVisible = false">取 消</el-button>
  143. </template>
  144. </Dialog>
  145. </template>
  146. <script setup lang="ts">
  147. import { FinancePaymentApi, FinancePaymentVO } from '@/api/erp/finance/payment'
  148. import FinancePaymentItemForm from './components/FinancePaymentItemForm.vue'
  149. import { SupplierApi, SupplierVO } from '@/api/erp/purchase/supplier'
  150. import { erpPriceInputFormatter, erpPriceMultiply } from '@/utils'
  151. import * as UserApi from '@/api/system/user'
  152. import { AccountApi, AccountVO } from '@/api/erp/finance/account'
  153. /** ERP 付款单表单 */
  154. defineOptions({ name: 'FinancePaymentForm' })
  155. const { t } = useI18n() // 国际化
  156. const message = useMessage() // 消息弹窗
  157. const dialogVisible = ref(false) // 弹窗的是否展示
  158. const dialogTitle = ref('') // 弹窗的标题
  159. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  160. const formType = ref('') // 表单的类型:create - 新增;update - 修改;detail - 详情
  161. const formData = ref({
  162. id: undefined,
  163. supplierId: undefined,
  164. accountId: undefined,
  165. financeUserId: undefined,
  166. paymentTime: undefined,
  167. remark: undefined,
  168. fileUrl: '',
  169. totalPrice: 0,
  170. discountPrice: 0,
  171. paymentPrice: 0,
  172. items: [],
  173. no: undefined // 订单单号,后端返回
  174. })
  175. const formRules = reactive({
  176. supplierId: [{ required: true, message: '供应商不能为空', trigger: 'blur' }],
  177. paymentTime: [{ required: true, message: '订单时间不能为空', trigger: 'blur' }]
  178. })
  179. const disabled = computed(() => formType.value === 'detail')
  180. const formRef = ref() // 表单 Ref
  181. const supplierList = ref<SupplierVO[]>([]) // 供应商列表
  182. const accountList = ref<AccountVO[]>([]) // 账户列表
  183. const userList = ref<UserApi.UserVO[]>([]) // 用户列表
  184. /** 子表的表单 */
  185. const subTabsName = ref('item')
  186. const itemFormRef = ref()
  187. /** 计算 discountPrice、totalPrice 价格 */
  188. watch(
  189. () => formData.value,
  190. (val) => {
  191. if (!val) {
  192. return
  193. }
  194. const totalPrice = val.items.reduce((prev, curr) => prev + curr.totalPrice, 0)
  195. const discountPrice =
  196. val.discountPercent != null ? erpPriceMultiply(totalPrice, val.discountPercent / 100.0) : 0
  197. formData.value.discountPrice = discountPrice
  198. formData.value.totalPrice = totalPrice - discountPrice
  199. },
  200. { deep: true }
  201. )
  202. /** 打开弹窗 */
  203. const open = async (type: string, id?: number) => {
  204. dialogVisible.value = true
  205. dialogTitle.value = t('action.' + type)
  206. formType.value = type
  207. resetForm()
  208. // 修改时,设置数据
  209. if (id) {
  210. formLoading.value = true
  211. try {
  212. formData.value = await FinancePaymentApi.getFinancePayment(id)
  213. } finally {
  214. formLoading.value = false
  215. }
  216. }
  217. // 加载供应商列表
  218. supplierList.value = await SupplierApi.getSupplierSimpleList()
  219. // 加载用户列表
  220. userList.value = await UserApi.getSimpleUserList()
  221. // 加载账户列表
  222. accountList.value = await AccountApi.getAccountSimpleList()
  223. const defaultAccount = accountList.value.find((item) => item.defaultStatus)
  224. if (defaultAccount) {
  225. formData.value.accountId = defaultAccount.id
  226. }
  227. }
  228. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  229. /** 提交表单 */
  230. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  231. const submitForm = async () => {
  232. // 校验表单
  233. await formRef.value.validate()
  234. await itemFormRef.value.validate()
  235. // 提交请求
  236. formLoading.value = true
  237. try {
  238. const data = formData.value as unknown as FinancePaymentVO
  239. if (formType.value === 'create') {
  240. await FinancePaymentApi.createFinancePayment(data)
  241. message.success(t('common.createSuccess'))
  242. } else {
  243. await FinancePaymentApi.updateFinancePayment(data)
  244. message.success(t('common.updateSuccess'))
  245. }
  246. dialogVisible.value = false
  247. // 发送操作成功的事件
  248. emit('success')
  249. } finally {
  250. formLoading.value = false
  251. }
  252. }
  253. /** 重置表单 */
  254. const resetForm = () => {
  255. formData.value = {
  256. id: undefined,
  257. supplierId: undefined,
  258. accountId: undefined,
  259. financeUserId: undefined,
  260. paymentTime: undefined,
  261. remark: undefined,
  262. fileUrl: undefined,
  263. totalPrice: 0,
  264. discountPrice: 0,
  265. paymentPrice: 0,
  266. items: [],
  267. no: undefined
  268. }
  269. formRef.value?.resetFields()
  270. }
  271. </script>