form.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <xn-form-container
  3. :title="formData.id ? '编辑起卸预约' : '增加起卸预约'"
  4. :width="700"
  5. v-model:open="open"
  6. :destroy-on-close="true"
  7. @close="onClose"
  8. >
  9. <a-form ref="formRef" :model="formData" :rules="formRules" :wrapper-col="wrapperCol" :label-col="labelCol">
  10. <a-form-item label="客户信息:" name="customerId">
  11. <a-select v-model:value="formData.customerId" placeholder="请选择客户信息"
  12. :options="customerIdList"
  13. > </a-select>
  14. </a-form-item>
  15. <a-form-item label="货品信息:" name="goodsId">
  16. <a-select v-model:value="formData.goodsId" placeholder="请选择货品信息"
  17. :options="goodsIdList"
  18. > </a-select>
  19. </a-form-item>
  20. <a-form-item label="订单数量:" name="orderWeight">
  21. <a-input-number v-model:value="formData.orderWeight" style="width:90%" :precision="2" :min="0.01" :max="9999999" placeholder="请输入订单数量" @blur="getTotalAmount" allow-clear/><span style="margin-left:10px;">吨</span>
  22. </a-form-item>
  23. <a-form-item label="单价:" name="orderPrice">
  24. <a-input-number v-model:value="formData.orderPrice" style="width:90%" :precision="2" :min="0.01" :max="999999" placeholder="请输入单价" @blur="getTotalAmount" allow-clear/><span style="margin-left:10px;">元/吨</span>
  25. </a-form-item>
  26. <a-form-item label="订单总额:" name="orderAmount">
  27. <a-input-number v-model:value="formData.orderAmount" style="width:90%" :precision="2" :min="0.01" :max="9999999" placeholder="请输入订单总额" allow-clear/><span style="margin-left:10px;">元</span>
  28. </a-form-item>
  29. <a-form-item label="船运供应商:" name="supplierId">
  30. <a-select v-model:value="formData.supplierId" placeholder="请选择船运供应商"
  31. :options="supplierIds"
  32. > </a-select>
  33. </a-form-item>
  34. <a-form-item label="运费单价:" name="freightPrice">
  35. <a-input-number v-model:value="formData.freightPrice" style="width:90%" :precision="2" :min="0.01" :max="999999" placeholder="请输入运费单价" allow-clear/><span style="margin-left:10px;">元/吨</span>
  36. </a-form-item>
  37. <a-form-item label="支付方式:" name="payType">
  38. <a-radio-group button-style="solid" v-model:value="formData.payType">
  39. <a-radio-button value="1">
  40. 预付
  41. </a-radio-button>
  42. <a-radio-button value="2">
  43. 授信
  44. </a-radio-button>
  45. </a-radio-group>
  46. </a-form-item>
  47. <a-form-item label="订单类型:" name="orderType">
  48. <a-radio-group button-style="solid" v-model:value="formData.orderType">
  49. <a-radio-button value="1">
  50. 配送订单
  51. </a-radio-button>
  52. <a-radio-button value="2">
  53. 自提订单
  54. </a-radio-button>
  55. </a-radio-group>
  56. </a-form-item>
  57. <a-form-item label="汽运供应商:" name="supplierIdList">
  58. <a-select v-model:value="formData.supplierIdList" placeholder="请选择汽运供应商"
  59. :options="supplierIdLists" mode="tags"
  60. > </a-select>
  61. </a-form-item>
  62. </a-form>
  63. <template #footer>
  64. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  65. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  66. </template>
  67. </xn-form-container>
  68. </template>
  69. <script setup name="bizLoadAppointForm">
  70. import { cloneDeep } from 'lodash-es'
  71. import { required } from '@/utils/formRules'
  72. import bizLoadAppointApi from '@/api/biz/bizLoadAppointApi'
  73. import bizServiceCustomerApi from '@/api/biz/bizServiceCustomerApi'
  74. import bizGoodsApi from "@/api/biz/bizGoodsApi";
  75. import bizSupplierApi from "@/api/biz/bizSupplierApi";
  76. // 抽屉状态
  77. const open = ref(false)
  78. const emit = defineEmits({ successful: null })
  79. const formRef = ref()
  80. // 表单数据
  81. const formData = ref({})
  82. const submitLoading = ref(false)
  83. const customerIdList = ref()
  84. const goodsIdList = ref()
  85. const supplierIds = ref()
  86. const supplierIdLists = ref()
  87. //设置表单样式
  88. const labelCol = ref({ span: 5})
  89. const wrapperCol = ref({ span: 16})
  90. // 打开抽屉
  91. const onOpen = (record) => {
  92. open.value = true
  93. if (record) {
  94. let recordData = cloneDeep(record)
  95. formData.value = Object.assign({}, recordData)
  96. }
  97. //查询服务客户信息
  98. bizServiceCustomerApi.getList().then((res)=>{
  99. customerIdList.value = res.map((item)=>{
  100. return{
  101. value:item.id,
  102. label:item.name
  103. }
  104. })
  105. })
  106. //查询货品信息
  107. bizGoodsApi.getList().then((res)=>{
  108. goodsIdList.value = res.map((item)=>{
  109. return{
  110. value:item.id,
  111. label:item.goodsName+'-'+item.goodsCode
  112. }
  113. })
  114. })
  115. //查询船运供货商信息
  116. bizSupplierApi.getList({transportType:'2'}).then((res)=>{
  117. supplierIds.value = res.map((item)=>{
  118. return{
  119. value:item.id,
  120. label:item.supplierName
  121. }
  122. })
  123. })
  124. //查询汽运供货商信息
  125. bizSupplierApi.getList({transportType:'1'}).then((res)=>{
  126. supplierIdLists.value = res.map((item)=>{
  127. return{
  128. value:item.id,
  129. label:item.supplierName
  130. }
  131. })
  132. })
  133. }
  134. // 关闭抽屉
  135. const onClose = () => {
  136. formRef.value.resetFields()
  137. formData.value = {}
  138. open.value = false
  139. }
  140. // 默认要校验的
  141. const formRules = {
  142. customerId:[required('请选择客户信息')],
  143. goodsId:[required('请选择货品信息')],
  144. orderWeight:[required('请输入订单数量')],
  145. orderPrice:[required('请输入单价')],
  146. orderAmount:[required('请输入订单总额')],
  147. supplierId:[required('请选择船运供应商')],
  148. freightPrice:[required('请输入运费单价')],
  149. payType:[required('请选择支付方式')],
  150. orderType:[required('请选择订单类型')],
  151. supplierIdList:[required('请选择汽运供应商')],
  152. }
  153. //获取订单总额
  154. const getTotalAmount = () => {
  155. console.log("gfdlkgjkfl")
  156. if(formData.value.orderWeight!=null && formData.value.orderWeight!='' &&
  157. formData.value.orderPrice!=null && formData.value.orderPrice!=''){
  158. formData.value.orderAmount = (formData.value.orderWeight * formData.value.orderPrice).toFixed(2)
  159. }
  160. }
  161. // 验证并提交数据
  162. const onSubmit = () => {
  163. formRef.value
  164. .validate()
  165. .then(() => {
  166. submitLoading.value = true
  167. const formDataParam = cloneDeep(formData.value)
  168. bizLoadAppointApi
  169. .bizLoadAppointSubmitForm(formDataParam, formDataParam.id)
  170. .then(() => {
  171. onClose()
  172. emit('successful')
  173. })
  174. .finally(() => {
  175. submitLoading.value = false
  176. })
  177. })
  178. .catch(() => {})
  179. }
  180. // 抛出函数
  181. defineExpose({
  182. onOpen
  183. })
  184. </script>