index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!-- 交收操作 -->
  2. <template>
  3. <app-modal direction="right-top" height="100%" width="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="请选择" input-align="right"
  14. :rules="formRules.wrstandardname" v-model="checkedRow.wrstandardname"
  15. @click="showWarehouseReceipt = true" is-link readonly />
  16. <template v-if="checkedRow.deliverygoodsid">
  17. <Cell title="持有人" :value="checkedRow.username" />
  18. <Cell title="仓库" :value="checkedRow.warehousename" />
  19. <Cell title="数量" :value="checkedRow.avalidqty + (deliveryRelation?.enumdicname ?? '')" />
  20. </template>
  21. </CellGroup>
  22. <CellGroup inset>
  23. <Cell title="可交收数量" :value="(total * qtyStep) + (deliveryRelation?.enumdicname ?? '')" />
  24. <Field name="DeliveryQty" type="digit" :rules="formRules.DeliveryQty" label="交收数量">
  25. <template #input>
  26. <Stepper v-model="formData.DeliveryQty" theme="round" button-size="22" :min="0"
  27. :max="maxQty" :step="qtyStep" integer />
  28. </template>
  29. </Field>
  30. <Cell title="所需合约量" :value="formData.DeliveryQty ? (formData.DeliveryQty / qtyStep) : 0" />
  31. <Cell title="升贴水" :value="discount.toFixed(2)" />
  32. <slot name="form" :discount="discount" :qty="formData.DeliveryQty ?? 0"></slot>
  33. </CellGroup>
  34. </Form>
  35. <template #footer>
  36. <Button block square type="danger" @click="formRef?.submit">提交</Button>
  37. </template>
  38. </app-view>
  39. <component :is="WarehouseReceipt" v-model:show="showWarehouseReceipt" :goods-id="goodsId" @change="onChange" />
  40. </app-modal>
  41. </template>
  42. <script lang="ts" setup>
  43. import { reactive, shallowRef, computed, defineAsyncComponent, onMounted } from 'vue'
  44. import { v4 } from 'uuid'
  45. import { CellGroup, Cell, Button, FieldRule, Form, Field, Stepper, FormInstance } from 'vant'
  46. import { handleRequestBigNumber } from '@/filters'
  47. import { dialog, fullloading } from '@/utils/vant'
  48. import { useRequest } from '@/hooks/request'
  49. import { ClientType } from '@/constants/client'
  50. import { deliveryOrder } from '@/services/api/trade'
  51. import { queryDeliveryRelation } from '@/services/api/goods'
  52. import { useAccountStore, useFuturesStore } from '@/stores'
  53. import moment from 'moment'
  54. import AppModal from '@/components/base/modal/index.vue'
  55. const props = defineProps({
  56. goodsId: {
  57. type: Number,
  58. required: true,
  59. },
  60. total: {
  61. type: Number,
  62. required: true,
  63. }
  64. })
  65. const WarehouseReceipt = defineAsyncComponent(() => import('./warehouse-receipt.vue'))
  66. const accountStore = useAccountStore()
  67. const futuresStore = useFuturesStore()
  68. const showModal = shallowRef(true)
  69. const refresh = shallowRef(false) // 是否刷新父组件数据
  70. const formRef = shallowRef<FormInstance>()
  71. const checkedRow = shallowRef<Partial<Model.WrDeliveryAvalidHoldLBRsp>>({}) //选中的点选仓单
  72. const showWarehouseReceipt = shallowRef(false)
  73. const quote = futuresStore.getGoodsQuote(props.goodsId) // 商品实时盘面
  74. const formData = reactive<Partial<Proto.DeliveryOrderReq>>({
  75. ClientType: ClientType.Web,
  76. AccountID: accountStore.currentAccountId,
  77. XGoodsID: props.goodsId
  78. })
  79. // 查询商品交割关系
  80. const { data: deliveryRelation } = useRequest(queryDeliveryRelation, {
  81. params: {
  82. goodsid: props.goodsId,
  83. },
  84. onSuccess: (res) => {
  85. deliveryRelation.value = res.data[0]
  86. }
  87. })
  88. // 数量步长
  89. const qtyStep = computed(() => {
  90. const { agreeunit = 0 } = quote.value ?? {}
  91. const { mindeliveryqty = 0, rratio1 = 0, rratio2 = 0 } = deliveryRelation.value ?? {}
  92. if (rratio2 && rratio1) {
  93. return agreeunit * mindeliveryqty * (rratio2 / rratio1)
  94. }
  95. return 0
  96. })
  97. // 可选最大交收数量
  98. const maxQty = computed(() => {
  99. const avalidqty = checkedRow.value.avalidqty ?? 0
  100. const enableqty = props.total * qtyStep.value
  101. return avalidqty > enableqty ? enableqty : avalidqty
  102. })
  103. // 升贴水
  104. const discount = computed(() => (checkedRow.value.pricemove ?? 0) * (formData.DeliveryQty ?? 0))
  105. // 表单验证规则
  106. const formRules: { [key: string]: FieldRule[] } = {
  107. wrstandardname: [{
  108. message: '请选择点选仓单',
  109. validator: () => {
  110. return !!checkedRow.value.deliverygoodsid
  111. }
  112. }],
  113. DeliveryQty: [{
  114. validator: () => {
  115. if (formData.DeliveryQty) {
  116. return formData.DeliveryQty % qtyStep.value === 0 ? true : '数量只能是' + qtyStep.value + '的整数倍'
  117. }
  118. return '请输入交收数量'
  119. }
  120. }],
  121. }
  122. // 选择现货仓单
  123. const onChange = (item: Model.WrDeliveryAvalidHoldLBRsp) => {
  124. checkedRow.value = item
  125. showWarehouseReceipt.value = false
  126. }
  127. const onSubmit = () => {
  128. dialog({
  129. message: '确认要交收吗?',
  130. showCancelButton: true,
  131. }).then(() => {
  132. fullloading((hideLoading) => {
  133. const item = checkedRow.value
  134. formData.DeliveryGoodsID = item.deliverygoodsid
  135. formData.XQty = (formData.DeliveryQty ?? 0) / qtyStep.value
  136. formData.DeliveryOrderDetail = {
  137. AccountID: item.accountid, // 对手方账号
  138. Qty: formData.DeliveryQty, // 点选数量
  139. LadingBillID: item.ladingbillid,// 提单ID
  140. SubNum: item.subnum, // 提单子单号
  141. WRFactorTypeID: handleRequestBigNumber(item.wrfactortypeid ?? '0'), // 仓单要素类型ID
  142. }
  143. formData.ClientSerialNo = v4()
  144. formData.ClientOrderTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  145. deliveryOrder({
  146. data: formData
  147. }).then(() => {
  148. hideLoading('交收成功', 'success')
  149. closed(true)
  150. }).catch((err) => {
  151. hideLoading(err, 'fail')
  152. })
  153. })
  154. })
  155. }
  156. // 关闭弹窗
  157. const closed = (isRefresh = false) => {
  158. refresh.value = isRefresh
  159. if (showWarehouseReceipt.value) {
  160. showWarehouseReceipt.value = false
  161. } else {
  162. showModal.value = false
  163. }
  164. }
  165. // 暴露组件属性给父组件调用
  166. defineExpose({
  167. closed,
  168. })
  169. onMounted(() => {
  170. if (!quote.value) {
  171. console.warn(`商品 ${props.goodsId} 不存在`)
  172. }
  173. })
  174. </script>