index.vue 7.8 KB

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