index.backup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <app-view class="goods-details">
  3. <template #header>
  4. <app-navbar title="采购详情" />
  5. </template>
  6. <Form ref="formRef" class="goods-details__form" @submit="onSubmit">
  7. <CellGroup>
  8. <Field name="THJDeliveryMode" label="交收方式" :rules="formRules.THJDeliveryMode" is-link>
  9. <template #input>
  10. <app-select v-model="formData.THJDeliveryMode" placeholder="请选择"
  11. :options="details.deliverymodes"
  12. :optionProps="{ label: 'enumdicname', value: 'enumitemname' }" />
  13. </template>
  14. </Field>
  15. <Field label="交收月份" name="PresaleApplyID" :rules="formRules.PresaleApplyID">
  16. <template #input>
  17. <app-select placeholder="开始月份" :options="deliveryMonths" @confirm="onMonthChange" />
  18. <app-select placeholder="结束日期" :options="deliveryDays"
  19. :optionProps="{ label: 'enddate', value: 'presaleapplyid' }" @confirm="onDayChange" />
  20. </template>
  21. </Field>
  22. <Field name="DepositID" label="支付方式" :rules="formRules.DepositID" is-link
  23. v-if="selectedDate?.presaleapplyid">
  24. <template #input>
  25. <app-select placeholder="请选择" :options="presaleApplyDeposits" @confirm="onDepositChange" />
  26. </template>
  27. </Field>
  28. <Field v-model="formData.Qty" name="Qty" type="digit" label="采购数量" :rules="formRules.Qty">
  29. <template #input>
  30. <div class="form-qty">
  31. <div class="form-qty__input">
  32. <input type="number" v-model="formData.Qty" placeholder="必填" />
  33. <span v-if="selectedDate">≤{{ selectedDate.remainqty }}{{
  34. getGoodsUnitName(goodsinfo.unitid)
  35. }}</span>
  36. </div>
  37. <div class="form-qty__label">
  38. <span>定金{{ deposit }}元</span>
  39. </div>
  40. </div>
  41. </template>
  42. </Field>
  43. <Field label="收货信息" :rules="formRules.addressInfo" @click="openComponent('address')" is-link
  44. v-if="showAddressInfo">
  45. <template #input>
  46. <div class="form-address">
  47. <template v-if="validatorAddressInfo">
  48. <span>联系人:{{ formData.ContactName }}</span>
  49. <span>联系方式:{{ formData.ContactInfo }}</span>
  50. <span v-if="formData.THJDeliveryMode === 3">目的地:{{ formData.DesAddress }}</span>
  51. <span v-if="formData.ReceiptInfo">发票信息:{{ formData.ReceiptInfo }}</span>
  52. </template>
  53. <template v-else>
  54. <span class="form-address__placeholder">必填</span>
  55. </template>
  56. </div>
  57. </template>
  58. </Field>
  59. </CellGroup>
  60. </Form>
  61. <div class="goods-details__content">
  62. <div class="submitbar">
  63. <Button type="primary" @click="formRef?.submit" round block>采购下单</Button>
  64. </div>
  65. <div class="titlebar" v-if="selectedDate">
  66. <span>参考价(元/{{ getGoodsUnitName(goodsinfo.unitid) }})</span>
  67. <span>{{ selectedDate.unitprice ?? 0.00 }}</span>
  68. </div>
  69. <template v-if="chartData.price.length">
  70. <Divider>历史价格走势</Divider>
  71. <div class="chart">
  72. <component :is="componentMap.get('chart')" :loading="loading" :data-list="chartData" />
  73. </div>
  74. </template>
  75. <Divider>商品详情</Divider>
  76. <div class="gallery">
  77. <template v-for="(url, index) in goodsImages" :key="index">
  78. <img :src="url" alt="" />
  79. </template>
  80. </div>
  81. </div>
  82. <component ref="componentRef" :is="componentMap.get(componentId)" v-bind="{ formData }" @updated="updateForm"
  83. @closed="closeComponent" v-if="componentId" />
  84. </app-view>
  85. </template>
  86. <script lang="ts" setup>
  87. import { shallowRef, computed, defineAsyncComponent } from 'vue'
  88. import { CellGroup, Button, Field, Form, FormInstance, showSuccessToast, showFailToast, FieldRule, Divider } from 'vant'
  89. import { fullloading } from '@/utils/vant'
  90. import { getImageUrl, parsePercent } from '@/filters'
  91. import { getGoodsUnitName } from '@/constants/unit'
  92. import { useComponent } from '@/hooks/component'
  93. import { useNavigation } from '@/hooks/navigation'
  94. import { useWrstandardDetails } from '@/business/goods'
  95. import { usePurchaseOrderDesting } from '@/business/trade'
  96. import AppSelect from '@mobile/components/base/select/index.vue'
  97. import Long from 'long'
  98. const componentMap = new Map<string, unknown>([
  99. ['address', defineAsyncComponent(() => import('./components/address/index.vue'))],
  100. ['chart', defineAsyncComponent(() => import('@mobile/components/modules/echarts-line/index.vue'))],
  101. ])
  102. const { componentRef, componentId, openComponent, closeComponent } = useComponent()
  103. const { router, getQueryStringToNumber } = useNavigation()
  104. const wrstandardid = getQueryStringToNumber('wrstandardid')
  105. const formRef = shallowRef<FormInstance>()
  106. const { loading, details, chartData, getWrstandardDetails } = useWrstandardDetails(wrstandardid)
  107. const { formData, formSubmit } = usePurchaseOrderDesting()
  108. // 交割日期列表
  109. const deliveryDays = shallowRef<Model.THJWrstandardDetailRsp['deliverymonth']>([])
  110. // 当前选中的交割日期
  111. const selectedDate = shallowRef<Model.THJWrstandardDetailRsp['deliverymonth'][number]>()
  112. // 商品信息
  113. const goodsinfo = computed<Partial<Model.THJWrstandardDetailRsp['goodsinfo']>>(() => details.value.goodsinfo ?? {})
  114. // 商品图片列表
  115. const goodsImages = computed(() => {
  116. const pictureurls = goodsinfo.value.pictureurls ?? ''
  117. return pictureurls.split(',').map((path) => getImageUrl(path))
  118. })
  119. // 交割月份列表
  120. const deliveryMonths = computed(() => {
  121. const months = details.value.deliverymonth ?? []
  122. const monthMap = new Map<string, { label: string, value: string; }>()
  123. months.forEach(({ endmonth }) => {
  124. if (!monthMap.has(endmonth)) {
  125. monthMap.set(endmonth, {
  126. label: endmonth,
  127. value: endmonth,
  128. })
  129. }
  130. })
  131. return [...monthMap.values()]
  132. })
  133. // 预售申请列表
  134. const presaleApplyDeposits = computed(() => {
  135. const deposits = details.value.presaleapplydeposits ?? []
  136. const presaleApplyId = selectedDate.value?.presaleapplyid
  137. return deposits.filter((e) => e.presaleapplyid === presaleApplyId).map(({ depositid, depositrate }) => ({
  138. label: parsePercent(depositrate),
  139. value: depositid
  140. }))
  141. })
  142. // 计算定价
  143. const deposit = computed(() => {
  144. const { Qty = 0, DepositID } = formData.value
  145. const { presaleapplydeposits } = details.value
  146. const { unitprice = 0 } = selectedDate.value ?? {}
  147. const apply = presaleapplydeposits?.find((e) => e.depositid === DepositID?.toString()) // 选中的支付方式
  148. if (apply) {
  149. return (unitprice * apply.depositrate * Qty).toFixed(2)
  150. }
  151. return '0.00'
  152. })
  153. // 是否显示收货信息
  154. const showAddressInfo = computed(() => {
  155. const { THJDeliveryMode } = formData.value
  156. return THJDeliveryMode === 2 || THJDeliveryMode === 3
  157. })
  158. // 验证收货信息
  159. const validatorAddressInfo = computed(() => {
  160. const { THJDeliveryMode, ContactName, ContactInfo, DesAddress } = formData.value
  161. switch (THJDeliveryMode) {
  162. case 2: {
  163. if (ContactName && ContactInfo) return true
  164. return false
  165. }
  166. case 3: {
  167. if (ContactName && ContactInfo && DesAddress) return true
  168. return false
  169. }
  170. }
  171. return true
  172. })
  173. // 表单验证规则
  174. const formRules: { [key in keyof Proto.SpotPresaleDestingOrderReq | 'addressInfo']?: FieldRule[] } = {
  175. THJDeliveryMode: [{
  176. message: '请选择交收方式',
  177. validator: () => {
  178. return !!formData.value.THJDeliveryMode
  179. }
  180. }],
  181. PresaleApplyID: [
  182. {
  183. message: '请选择到期日期',
  184. validator: () => {
  185. return !!formData.value.PresaleApplyID
  186. }
  187. }
  188. ],
  189. DepositID: [{
  190. message: '请选择支付方式',
  191. validator: () => {
  192. return !!formData.value.DepositID
  193. }
  194. }],
  195. Qty: [{
  196. message: '请输入采购数量',
  197. validator: (val) => {
  198. if (val) {
  199. const qty = Number(val)
  200. const { remainqty = 0 } = selectedDate.value ?? {}
  201. if (qty > 0 && qty <= remainqty) {
  202. return true
  203. }
  204. return '采购数量不正确'
  205. }
  206. return false
  207. }
  208. }],
  209. addressInfo: [{
  210. message: '请输入收货信息',
  211. validator: () => {
  212. return validatorAddressInfo.value
  213. }
  214. }],
  215. }
  216. // 切换交割月份
  217. const onMonthChange = (value: string) => {
  218. const months = details.value.deliverymonth ?? []
  219. deliveryDays.value = months.filter((e) => e.endmonth === value) // 重新过滤交割日期列表
  220. selectedDate.value = undefined // 清除选中的交割日期
  221. formData.value.PresaleApplyID = undefined
  222. }
  223. // 切换交割日期
  224. const onDayChange = (value: string) => {
  225. const months = details.value.deliverymonth ?? []
  226. selectedDate.value = months.find((e) => e.presaleapplyid === value)
  227. formData.value.PresaleApplyID = Long.fromString(value)
  228. formData.value.DepositID = undefined
  229. formRef.value?.validate('PresaleApplyID')
  230. }
  231. // 切换支付方式
  232. const onDepositChange = (value: string) => {
  233. formData.value.DepositID = Long.fromString(value)
  234. formRef.value?.validate('DepositID')
  235. }
  236. // 更新表单数据
  237. const updateForm = (formValue: Proto.SpotPresaleDestingOrderReq) => {
  238. formData.value = formValue
  239. }
  240. const onSubmit = () => {
  241. fullloading(() => {
  242. formSubmit().then(() => {
  243. showSuccessToast('下单成功')
  244. router.replace({ name: 'my-order' })
  245. }).catch((err) => {
  246. showFailToast(err)
  247. })
  248. })
  249. }
  250. getWrstandardDetails()
  251. </script>
  252. <style lang="less">
  253. @import './index.less';
  254. </style>