index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!-- 交收操作 -->
  2. <template>
  3. <app-modal direction="right" height="100%" v-model:show="showModal" :refresh="refresh">
  4. <app-view class="g-form">
  5. <template #header>
  6. <app-navbar title="交收" @back="closed" />
  7. </template>
  8. <Form ref="formRef" class="g-form__container" @submit="onSubmit">
  9. <CellGroup title="持仓信息" inset v-if="$slots.header">
  10. <slot name="header"></slot>
  11. </CellGroup>
  12. <CellGroup title="交收信息" inset>
  13. <Field name="wrstandardname" label="点选仓单" placeholder="请选择" :rules="formRules.wrstandardname"
  14. v-model="checkedRow.wrstandardname" @click="showWarehouseReceipt = true" is-link readonly />
  15. <template v-if="checkedRow.deliverygoodsid">
  16. <Field label="持有人" v-model="checkedRow.username" readonly />
  17. <Field label="仓库" v-model="checkedRow.warehousename" readonly />
  18. <Field label="数量" v-model="checkedRow.avalidqty" readonly />
  19. </template>
  20. </CellGroup>
  21. <CellGroup inset>
  22. <Field name="DeliveryQty" type="digit" :rules="formRules.DeliveryQty" label="交收数量">
  23. <template #input>
  24. <Stepper v-model="formData.DeliveryQty" theme="round" button-size="22" :min="0" :max="maxQty"
  25. integer />
  26. </template>
  27. </Field>
  28. <Field label="升贴水">
  29. <template #input>
  30. {{ discount.toFixed(2) }}
  31. </template>
  32. </Field>
  33. <slot name="form" :discount="discount" :qty="formData.DeliveryQty ?? 0"></slot>
  34. </CellGroup>
  35. </Form>
  36. <template #footer>
  37. <Button block square type="danger" @click="formRef?.submit">提交</Button>
  38. </template>
  39. </app-view>
  40. <component :is="WarehouseReceipt" v-model:show="showWarehouseReceipt" :goods-id="goodsId" @change="onChange" />
  41. </app-modal>
  42. </template>
  43. <script lang="ts" setup>
  44. import { reactive, shallowRef, computed, defineAsyncComponent } from 'vue'
  45. import { v4 } from 'uuid'
  46. import { CellGroup, Button, FieldRule, Form, Field, Stepper, FormInstance } from 'vant'
  47. import { handleRequestBigNumber } from '@/filters'
  48. import { dialog, fullloading } from '@/utils/vant'
  49. import { ClientType } from '@/constants/client'
  50. import { deliveryOrder } from '@/services/api/trade'
  51. import { useAccountStore } from '@/stores'
  52. import moment from 'moment'
  53. import AppModal from '@/components/base/modal/index.vue'
  54. const props = defineProps({
  55. goodsId: {
  56. type: Number,
  57. required: true,
  58. },
  59. total: {
  60. type: Number,
  61. required: true,
  62. }
  63. })
  64. const WarehouseReceipt = defineAsyncComponent(() => import('./warehouse-receipt.vue'))
  65. const accountStore = useAccountStore()
  66. const showModal = shallowRef(true)
  67. const refresh = shallowRef(false) // 是否刷新父组件数据
  68. const formRef = shallowRef<FormInstance>()
  69. const checkedRow = shallowRef<Partial<Model.WrDeliveryAvalidHoldLBRsp>>({}) //选中的点选仓单
  70. const showWarehouseReceipt = shallowRef(false)
  71. const formData = reactive<Partial<Proto.DeliveryOrderReq>>({
  72. ClientType: ClientType.Web,
  73. AccountID: accountStore.currentAccountId,
  74. XGoodsID: props.goodsId
  75. })
  76. // 可选最大交收数量
  77. const maxQty = computed(() => {
  78. const avalidqty = checkedRow.value.avalidqty ?? 0
  79. const enableqty = props.total
  80. return avalidqty > enableqty ? enableqty : avalidqty
  81. })
  82. // 升贴水
  83. const discount = computed(() => (checkedRow.value.pricemove ?? 0) * (formData.DeliveryQty ?? 0))
  84. // 表单验证规则
  85. const formRules: { [key: string]: FieldRule[] } = {
  86. wrstandardname: [{
  87. message: '请选择点选仓单',
  88. validator: () => {
  89. return !!checkedRow.value.deliverygoodsid
  90. }
  91. }],
  92. DeliveryQty: [{
  93. message: '请输入交收数量',
  94. validator: () => {
  95. return !!formData.DeliveryQty
  96. }
  97. }],
  98. }
  99. // 选择现货仓单
  100. const onChange = (item: Model.WrDeliveryAvalidHoldLBRsp) => {
  101. checkedRow.value = item
  102. showWarehouseReceipt.value = false
  103. }
  104. const onSubmit = () => {
  105. dialog({
  106. message: '确认要交收吗?',
  107. showCancelButton: true,
  108. }).then(() => {
  109. fullloading((hideLoading) => {
  110. const item = checkedRow.value
  111. formData.DeliveryGoodsID = item.deliverygoodsid
  112. formData.XQty = formData.DeliveryQty
  113. formData.DeliveryOrderDetail = {
  114. AccountID: item.accountid, // 对手方账号
  115. Qty: formData.DeliveryQty, // 点选数量
  116. LadingBillID: item.ladingbillid,// 提单ID
  117. SubNum: item.subnum, // 提单子单号
  118. WRFactorTypeID: handleRequestBigNumber(item.wrfactortypeid ?? '0'), // 仓单要素类型ID
  119. }
  120. formData.ClientSerialNo = v4()
  121. formData.ClientOrderTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  122. deliveryOrder({
  123. data: formData
  124. }).then(() => {
  125. hideLoading('交收成功', 'success')
  126. closed(true)
  127. }).catch((err) => {
  128. hideLoading(err, 'fail')
  129. })
  130. })
  131. })
  132. }
  133. // 关闭弹窗
  134. const closed = (isRefresh = false) => {
  135. if (showWarehouseReceipt.value) {
  136. showWarehouseReceipt.value = false
  137. } else {
  138. refresh.value = isRefresh
  139. showModal.value = false
  140. }
  141. }
  142. // 暴露组件属性给父组件调用
  143. defineExpose({
  144. closed,
  145. })
  146. </script>