SaleOutForm.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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="outTime">
  19. <el-date-picker
  20. v-model="formData.outTime"
  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="customerId">
  30. <el-select
  31. v-model="formData.customerId"
  32. clearable
  33. filterable
  34. placeholder="请选择客户"
  35. class="!w-1/1"
  36. >
  37. <el-option
  38. v-for="item in customerList"
  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="orderNo">
  48. <el-input v-model="formData.orderNo" readonly>
  49. <template #append>
  50. <el-button @click="openSaleOrderOutEnableList">
  51. <Icon icon="ep:search" /> 选择
  52. </el-button>
  53. </template>
  54. </el-input>
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="8">
  58. <el-form-item label="备注" prop="remark">
  59. <el-input
  60. type="textarea"
  61. v-model="formData.remark"
  62. :rows="1"
  63. placeholder="请输入备注"
  64. />
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="8">
  68. <el-form-item label="附件" prop="fileUrl">
  69. <UploadFile :is-show-tip="false" v-model="formData.fileUrl" :limit="1" />
  70. </el-form-item>
  71. </el-col>
  72. </el-row>
  73. <!-- 子表的表单 -->
  74. <ContentWrap>
  75. <el-tabs v-model="subTabsName" class="-mt-15px -mb-10px">
  76. <el-tab-pane label="出库产品清单" name="item">
  77. <SaleOutItemForm ref="itemFormRef" :items="formData.items" :disabled="disabled" />
  78. </el-tab-pane>
  79. </el-tabs>
  80. </ContentWrap>
  81. <el-row :gutter="20">
  82. <el-col :span="8">
  83. <el-form-item label="优惠率(%)" prop="discountPercent">
  84. <el-input-number
  85. v-model="formData.discountPercent"
  86. controls-position="right"
  87. :min="0"
  88. :precision="2"
  89. placeholder="请输入优惠率"
  90. class="!w-1/1"
  91. />
  92. </el-form-item>
  93. </el-col>
  94. <el-col :span="8">
  95. <el-form-item label="收款优惠" prop="discountPrice">
  96. <el-input
  97. disabled
  98. v-model="formData.discountPrice"
  99. :formatter="erpPriceInputFormatter"
  100. />
  101. </el-form-item>
  102. </el-col>
  103. <el-col :span="8">
  104. <el-form-item label="优惠后金额">
  105. <el-input disabled v-model="formData.totalPrice" :formatter="erpPriceInputFormatter" />
  106. </el-form-item>
  107. </el-col>
  108. <el-col :span="8">
  109. <el-form-item label="结算账户" prop="accountId">
  110. <el-select
  111. v-model="formData.accountId"
  112. clearable
  113. filterable
  114. placeholder="请选择结算账户"
  115. class="!w-1/1"
  116. >
  117. <el-option
  118. v-for="item in accountList"
  119. :key="item.id"
  120. :label="item.name"
  121. :value="item.id"
  122. />
  123. </el-select>
  124. </el-form-item>
  125. </el-col>
  126. <el-col :span="8">
  127. <el-form-item label="收取订金" prop="depositPrice">
  128. <el-input-number
  129. v-model="formData.depositPrice"
  130. controls-position="right"
  131. :min="0"
  132. :precision="2"
  133. placeholder="请输入收取订金"
  134. class="!w-1/1"
  135. />
  136. </el-form-item>
  137. </el-col>
  138. </el-row>
  139. </el-form>
  140. <template #footer>
  141. <el-button @click="submitForm" type="primary" :disabled="formLoading" v-if="!disabled">
  142. 确 定
  143. </el-button>
  144. <el-button @click="dialogVisible = false">取 消</el-button>
  145. </template>
  146. </Dialog>
  147. <!-- 可出库的订单列表 -->
  148. <SaleOrderOutEnableList ref="saleOrderOutEnableListRef" @success="handleSaleOrderChange" />
  149. </template>
  150. <script setup lang="ts">
  151. import { SaleOutApi, SaleOutVO } from '@/api/erp/sale/out'
  152. import SaleOutItemForm from './components/SaleOutItemForm.vue'
  153. import { CustomerApi, CustomerVO } from '@/api/erp/sale/customer'
  154. import { AccountApi, AccountVO } from '@/api/erp/finance/account'
  155. import { erpPriceInputFormatter, erpPriceMultiply } from '@/utils'
  156. import SaleOrderOutEnableList from '@/views/erp/sale/order/components/SaleOrderOutEnableList.vue'
  157. import { SaleOrderVO } from '@/api/erp/sale/order'
  158. /** ERP 销售出库表单 */
  159. defineOptions({ name: 'SaleOutForm' })
  160. const { t } = useI18n() // 国际化
  161. const message = useMessage() // 消息弹窗
  162. const dialogVisible = ref(false) // 弹窗的是否展示
  163. const dialogTitle = ref('') // 弹窗的标题
  164. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  165. const formType = ref('') // 表单的类型:create - 新增;update - 修改;detail - 详情
  166. const formData = ref({
  167. id: undefined,
  168. customerId: undefined,
  169. accountId: undefined,
  170. outTime: undefined,
  171. remark: undefined,
  172. fileUrl: '',
  173. discountPercent: 0,
  174. discountPrice: 0,
  175. totalPrice: 0,
  176. depositPrice: 0,
  177. orderNo: undefined,
  178. items: [],
  179. no: undefined // 出库单号,后端返回
  180. })
  181. const formRules = reactive({
  182. customerId: [{ required: true, message: '客户不能为空', trigger: 'blur' }],
  183. outTime: [{ required: true, message: '出库时间不能为空', trigger: 'blur' }]
  184. })
  185. const disabled = computed(() => formType.value === 'detail')
  186. const formRef = ref() // 表单 Ref
  187. const customerList = ref<CustomerVO[]>([]) // 客户列表
  188. const accountList = ref<AccountVO[]>([]) // 账户列表
  189. /** 子表的表单 */
  190. const subTabsName = ref('item')
  191. const itemFormRef = ref()
  192. /** 计算 discountPrice、totalPrice 价格 */
  193. watch(
  194. () => formData.value,
  195. (val) => {
  196. if (!val) {
  197. return
  198. }
  199. const totalPrice = val.items.reduce((prev, curr) => prev + curr.totalPrice, 0)
  200. const discountPrice =
  201. val.discountPercent != null ? erpPriceMultiply(totalPrice, val.discountPercent / 100.0) : 0
  202. formData.value.discountPrice = discountPrice
  203. formData.value.totalPrice = totalPrice - discountPrice
  204. },
  205. { deep: true }
  206. )
  207. /** 打开弹窗 */
  208. const open = async (type: string, id?: number) => {
  209. dialogVisible.value = true
  210. dialogTitle.value = t('action.' + type)
  211. formType.value = type
  212. resetForm()
  213. // 修改时,设置数据
  214. if (id) {
  215. formLoading.value = true
  216. try {
  217. formData.value = await SaleOutApi.getSaleOut(id)
  218. } finally {
  219. formLoading.value = false
  220. }
  221. }
  222. // 加载客户列表
  223. customerList.value = await CustomerApi.getCustomerSimpleList()
  224. // 加载账户列表
  225. accountList.value = await AccountApi.getAccountSimpleList()
  226. const defaultAccount = accountList.value.find((item) => item.defaultStatus)
  227. if (defaultAccount) {
  228. formData.value.accountId = defaultAccount.id
  229. }
  230. // TODO 芋艿:单独搞
  231. // saleOrderOutEnableListRef.value.open()
  232. }
  233. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  234. /** 打开【可出库的订单列表】弹窗 */
  235. const saleOrderOutEnableListRef = ref() // 可出库的订单列表 Ref
  236. const openSaleOrderOutEnableList = () => {
  237. saleOrderOutEnableListRef.value.open()
  238. }
  239. const handleSaleOrderChange = (order: SaleOrderVO) => {
  240. debugger
  241. formData.value.orderNo = order.no
  242. // formData.value.customerId = order.customerId
  243. // formData.value.accountId = order.accountId
  244. // formData.value.items = order.items.map((item) => {
  245. // return {
  246. // productId: item.productId,
  247. // count: item.count,
  248. // productPrice: item.productPrice,
  249. // taxPercent: item.taxPercent
  250. // }
  251. // })
  252. }
  253. /** 提交表单 */
  254. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  255. const submitForm = async () => {
  256. // 校验表单
  257. await formRef.value.validate()
  258. await itemFormRef.value.validate()
  259. // 提交请求
  260. formLoading.value = true
  261. try {
  262. const data = formData.value as unknown as SaleOutVO
  263. if (formType.value === 'create') {
  264. await SaleOutApi.createSaleOut(data)
  265. message.success(t('common.createSuccess'))
  266. } else {
  267. await SaleOutApi.updateSaleOut(data)
  268. message.success(t('common.updateSuccess'))
  269. }
  270. dialogVisible.value = false
  271. // 发送操作成功的事件
  272. emit('success')
  273. } finally {
  274. formLoading.value = false
  275. }
  276. }
  277. /** 重置表单 */
  278. const resetForm = () => {
  279. formData.value = {
  280. id: undefined,
  281. customerId: undefined,
  282. accountId: undefined,
  283. outTime: undefined,
  284. remark: undefined,
  285. fileUrl: undefined,
  286. discountPercent: 0,
  287. discountPrice: 0,
  288. totalPrice: 0,
  289. depositPrice: 0,
  290. items: []
  291. }
  292. formRef.value?.resetFields()
  293. }
  294. </script>