index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 { dialog, fullloading } from '@/utils/vant'
  48. import { ClientType } from '@/constants/client'
  49. import { deliveryOrder } from '@/services/api/trade'
  50. import { useAccountStore } from '@/stores'
  51. import moment from 'moment'
  52. import AppModal from '@/components/base/modal/index.vue'
  53. const props = defineProps({
  54. goodsId: {
  55. type: Number,
  56. required: true,
  57. },
  58. total: {
  59. type: Number,
  60. required: true,
  61. }
  62. })
  63. const WarehouseReceipt = defineAsyncComponent(() => import('./warehouse-receipt.vue'))
  64. const accountStore = useAccountStore()
  65. const showModal = shallowRef(true)
  66. const refresh = shallowRef(false) // 是否刷新父组件数据
  67. const formRef = shallowRef<FormInstance>()
  68. const checkedRow = shallowRef<Partial<Model.WrDeliveryAvalidHoldLBRsp>>({}) //选中的点选仓单
  69. const showWarehouseReceipt = shallowRef(false)
  70. const formData = reactive<Partial<Proto.DeliveryOrderReq>>({
  71. ClientType: ClientType.Web,
  72. AccountID: accountStore.currentAccountId,
  73. XGoodsID: props.goodsId
  74. })
  75. // 可选最大交收数量
  76. const maxQty = computed(() => {
  77. const avalidqty = checkedRow.value.avalidqty ?? 0
  78. const enableqty = props.total
  79. return avalidqty > enableqty ? enableqty : avalidqty
  80. })
  81. // 升贴水
  82. const discount = computed(() => (checkedRow.value.pricemove ?? 0) * (formData.DeliveryQty ?? 0))
  83. // 表单验证规则
  84. const formRules: { [key: string]: FieldRule[] } = {
  85. wrstandardname: [{
  86. message: '请选择点选仓单',
  87. validator: () => {
  88. return !!checkedRow.value.deliverygoodsid
  89. }
  90. }],
  91. DeliveryQty: [{
  92. message: '请输入交收数量',
  93. validator: () => {
  94. return !!formData.DeliveryQty
  95. }
  96. }],
  97. }
  98. // 选择现货仓单
  99. const onChange = (item: Model.WrDeliveryAvalidHoldLBRsp) => {
  100. checkedRow.value = item
  101. showWarehouseReceipt.value = false
  102. }
  103. const onSubmit = () => {
  104. dialog({
  105. message: '确认要交收吗?',
  106. showCancelButton: true,
  107. }).then(() => {
  108. fullloading((hideLoading) => {
  109. const item = checkedRow.value
  110. formData.DeliveryGoodsID = item.deliverygoodsid
  111. formData.XQty = formData.DeliveryQty
  112. formData.DeliveryOrderDetail = {
  113. AccountID: item.accountid, // 对手方账号
  114. Qty: formData.DeliveryQty, // 点选数量
  115. LadingBillID: item.ladingbillid,// 提单ID
  116. SubNum: item.subnum, // 提单子单号
  117. WRFactorTypeID: item.wrfactortypeid, // 仓单要素类型ID
  118. }
  119. formData.ClientSerialNo = v4()
  120. formData.ClientOrderTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  121. deliveryOrder({
  122. data: formData
  123. }).then(() => {
  124. hideLoading('交收成功')
  125. }).catch((err) => {
  126. hideLoading(err, 'fail')
  127. })
  128. })
  129. })
  130. }
  131. // 关闭弹窗
  132. const closed = (isRefresh = false) => {
  133. if (showWarehouseReceipt.value) {
  134. showWarehouseReceipt.value = false
  135. } else {
  136. refresh.value = isRefresh
  137. showModal.value = false
  138. }
  139. }
  140. // 暴露组件属性给父组件调用
  141. defineExpose({
  142. closed,
  143. })
  144. </script>