index.vue 7.2 KB

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