index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <z-paging class="" ref="paging" bgColor="#f7f7f7" paging-class="paging-btm-shadow" safe-area-inset-bottom scroll-with-animation>
  3. <template #top>
  4. <ut-navbar :title="'新增外部鲜货入库'" :fixed="false" border></ut-navbar>
  5. </template>
  6. <up-form class="p-rtv" labelPosition="top" :model="form" :rules="rules" labelWidth="auto" ref="upFormRef">
  7. <!-- 鲜货信息 -->
  8. <view class="pd-24">
  9. <view class="startline-title">鲜货信息</view>
  10. </view>
  11. <view class="pd-24 bg-#fff">
  12. <!-- TODO: 后续按 goodsInfoList 设计鲜货信息明细,此处先留空结构避免表单错误 -->
  13. <up-form-item borderBottom label="添加鲜货信息" required prop="goodsInfoList">
  14. <view class="flex1">
  15. <template v-for="(item, index) in form.goodsInfoList" :key="index">
  16. <view class="bg-#FBFDFB card-info-block pd-24 p-rtv mb-12">
  17. <view class="d-flex flex1 mb-10">
  18. <view class="f-s-34 c-#333 f-w-500 mr-10 flex1">{{ uidMapData[item]?.varietyInfo?.varietyName }}</view>
  19. <view class="pr-60">
  20. <view v-if="uidMapData[item]?.examinReport?.length" class="tag-span c-primary bg-#EBF6EE">已检</view>
  21. <view v-else class="tag-span c-danger bg-#F9ECEA">未检</view>
  22. </view>
  23. </view>
  24. <view class="d-flex">
  25. <view class="f-s-28 pr-10 pd2-4-0">
  26. <span class="c-#666">供应商:</span>
  27. <span class="c-#333 f-w-500">{{ uidMapData[item]?.supplierInfo?.cusName }}</span>
  28. </view>
  29. </view>
  30. <view class="d-flex">
  31. <view class="flex1 f-s-28 pd2-4-0 ov-hd">
  32. <span class="c-#666">入库量:</span>
  33. <span class="c-#333 f-w-500">{{ uidMapData[item]?.capacity }}{{ uidMapData[item]?.unit }}</span>
  34. </view>
  35. <view class="d-flex a-ed" @click="navigateToAddSeedSource(item, 'edit')">
  36. <view class="pd-10 c-primary f-s-20">去编辑{{ '>' }}</view>
  37. </view>
  38. </view>
  39. <view class="close-icon pd-16" @click.stop="deleteRow(index, item)">
  40. <up-icon color="#F81242" name="close" size="32rpx"></up-icon>
  41. </view>
  42. </view>
  43. </template>
  44. <up-button type="primary" plain @click="navigateToAddSeedSource('', 'add')">
  45. <up-icon class="mr-10" name="plus" color="#37A954"></up-icon>
  46. <span>点击添加鲜货信息</span>
  47. </up-button>
  48. </view>
  49. </up-form-item>
  50. </view>
  51. <view class="pd-24">
  52. <view class="startline-title">入库信息</view>
  53. </view>
  54. <view class="pd-24 bg-#fff">
  55. <!-- 入库类型 -->
  56. <up-form-item borderBottom label="入库类型" required prop="instoreType">
  57. <view v-if="form.instoreType" class="f-s-30 c-333 f-w-5 flex1">{{ selectDictLabel(pt_seed_instore_type, form.instoreType) }}</view>
  58. <view v-else class="f-s-30 c-ccc f-w-4 flex1">请选择入库类型</view>
  59. </up-form-item>
  60. <!-- 入库日期 -->
  61. <view class="h-1" id="instoreDatepppp"></view>
  62. <ut-datetime-picker v-model="form.instoreBizInfo.instoreDate" :maxDate="new Date()" mode="date">
  63. <up-form-item borderBottom label="入库日期" required prop="instoreBizInfo.instoreDate">
  64. <up-input v-model="form.instoreBizInfo.instoreDate" readonly placeholder="请选择入库日期" border="none" clearable></up-input>
  65. <template #right>
  66. <up-icon size="22rpx" color="#2A6D52" name="arrow-down-fill"></up-icon>
  67. </template>
  68. </up-form-item>
  69. </ut-datetime-picker>
  70. <!-- 入库批号 -->
  71. <up-form-item borderBottom label="入库批号" required prop="batchCode">
  72. <up-input v-model="form.batchCode" placeholder="请输入入库批号" border="none" clearable></up-input>
  73. <template #right>
  74. <up-button @click="generateBatchCode" type="primary" :customStyle="formItemBtnStyle">随机生成</up-button>
  75. </template>
  76. </up-form-item>
  77. <!-- 库房类型 -->
  78. <up-form-item borderBottom label="库房类型" prop="storageType" required>
  79. <view v-if="form.storageType" class="f-s-30 c-333 f-w-5 flex1">{{ selectDictLabel(pt_warehouse_type, form.storageType) }}</view>
  80. <view v-else class="f-s-30 c-ccc f-w-4 flex1">请选择库房类型</view>
  81. </up-form-item>
  82. <up-form-item borderBottom label="存放库房" prop="warehouses">
  83. <select-warehouse-input v-model="form.warehouses" title="添加鲜货存放库房" :params="{ type: '4' }"></select-warehouse-input>
  84. </up-form-item>
  85. <!-- 入库人 -->
  86. <up-form-item borderBottom label="入库人" required prop="instoreBizInfo.instoreMg">
  87. <up-input v-model="form.instoreBizInfo.instoreMg" placeholder="请输入入库人" border="none" clearable></up-input>
  88. </up-form-item>
  89. <!-- 入库备注 -->
  90. <up-form-item borderBottom label="入库备注" prop="instoreBizInfo.remark">
  91. <up-textarea v-model="form.instoreBizInfo.remark" placeholder="请输入入库备注" autoHeight></up-textarea>
  92. </up-form-item>
  93. </view>
  94. </up-form>
  95. <template #bottom>
  96. <view class="pd-20 d-flex">
  97. <up-button @click="submitForm" type="primary">确认入库</up-button>
  98. </view>
  99. </template>
  100. </z-paging>
  101. </template>
  102. <script setup lang="ts">
  103. import { useClientRequest } from '@/utils/request';
  104. import { FreshGoodsInstoreEnum } from '../models/type';
  105. import { formItemBtnStyle } from '@/assets/styles/uview-plus';
  106. import { generateUniqueId } from '@/utils/public';
  107. import { parseTime } from '@/utils/ruoyi';
  108. import SelectWarehouseInput from '@/models/select-warehouse-input/select-warehouse-input.vue';
  109. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  110. const { pt_seed_instore_type, pt_warehouse_type, pt_seed_type, pt_seed_source } = toRefs<any>(proxy?.useDict('pt_seed_instore_type', 'pt_warehouse_type', 'pt_seed_type', 'pt_seed_source'));
  111. // 表单与分页等基础状态(参考 base-edit 风格)
  112. const paging = ref<any>(null);
  113. const upFormRef = ref<any>(null);
  114. const showArea = ref(false);
  115. const form = ref<FreshGoodsInstoreEnum>({
  116. instoreType: '2',
  117. storageType: '4',
  118. goodsInfoList: [],
  119. warehouses: [],
  120. instoreBizInfo: {
  121. instoreDate: parseTime(new Date(), '{y}-{m}-{d}'),
  122. instoreMg: '',
  123. remark: '',
  124. },
  125. });
  126. const rules = reactive({
  127. goodsInfoList: [{ required: true, message: '请添加鲜货信息', type: 'array', min: 1 }],
  128. instoreType: [{ required: true, message: '请选择入库类型' }],
  129. 'instoreBizInfo.instoreDate': [{ required: true, message: '请选择入库日期' }],
  130. batchCode: [{ required: true, message: '请输入入库批号' }],
  131. 'instoreBizInfo.instoreMg': [{ required: true, message: '请输入入库人' }],
  132. });
  133. const submitForm = async () => {
  134. uni.$u.debounce(
  135. async () => {
  136. try {
  137. await upFormRef.value?.validate();
  138. } catch (error: any) {
  139. // 滚动到第一个错误字段
  140. const firstErrorField = error && error[0].prop + 'pppp';
  141. paging.value?.scrollIntoViewById(firstErrorField, 30, true);
  142. return;
  143. }
  144. // 提交表单
  145. uni.showLoading({
  146. title: '提交中...',
  147. });
  148. const params = form.value.goodsInfoList.map((uid) => {
  149. return {
  150. ...uidMapData.value[uid],
  151. ...form.value,
  152. instoreBizInfo: {
  153. ...form.value.instoreBizInfo,
  154. ...uidMapData.value[uid]?.instoreBizInfo,
  155. },
  156. };
  157. });
  158. try {
  159. const res = await useClientRequest.post('/plt-api/app/storage/batchInstore', params);
  160. if (!res || res.code !== 200) return;
  161. uni.hideLoading();
  162. uni.showToast({
  163. title: '提交成功',
  164. icon: 'success',
  165. });
  166. uni.$emit('refreshStorageRoomList');
  167. // 返回上一页
  168. setTimeout(() => {
  169. uni.navigateBack({
  170. delta: 1,
  171. });
  172. }, 1500);
  173. } catch (error) {
  174. // uni.hideLoading();
  175. }
  176. },
  177. 500,
  178. true,
  179. );
  180. };
  181. // 点击随机生成服务端生成唯一的批号
  182. const generateBatchCode = async () => {
  183. uni.showLoading({
  184. title: '生成中...',
  185. });
  186. const res = await useClientRequest.post('/plt-api/app/plantationTask/getBatchCode', {
  187. plType: 'X',
  188. linkType: 'I',
  189. });
  190. if (res && res.code === 200) {
  191. uni.hideLoading();
  192. form.value.batchCode = res.data;
  193. uni.showToast({
  194. title: '批号生成成功',
  195. icon: 'success',
  196. });
  197. }
  198. };
  199. const uidMapData = ref({} as any);
  200. // 添加鲜货入库跳转
  201. const navigateToAddSeedSource = (uid = '', mode = 'add') => {
  202. uni.$on('submitForm', (data: any) => {
  203. uidMapData.value[data.uid] = data.form;
  204. if (data?.mode == 'add') {
  205. form.value.goodsInfoList.push(data.uid);
  206. }
  207. uni.$off('submitForm');
  208. });
  209. uni.navigateTo({
  210. url: '/plant/storage/fresh-goods/info-edit/index',
  211. success(res) {
  212. res.eventChannel.emit('optionsParam', {
  213. uid: uid || generateUniqueId(),
  214. mode: mode,
  215. form: uid ? uidMapData.value[uid] : {},
  216. });
  217. },
  218. });
  219. };
  220. const deleteRow = (index: number, uid: string) => {
  221. form.value.goodsInfoList.splice(index, 1);
  222. delete uidMapData.value[uid];
  223. };
  224. // 编辑时加载详情
  225. onLoad((optins: any) => {});
  226. </script>
  227. <style lang="scss" scoped>
  228. .card-info-block {
  229. border: 1rpx solid #afddbb;
  230. border-radius: 10rpx;
  231. }
  232. .tag-span {
  233. padding: 4rpx 12rpx;
  234. font-size: 20rpx;
  235. border-radius: 18rpx;
  236. }
  237. .close-icon {
  238. position: absolute;
  239. top: 0;
  240. right: 0;
  241. z-index: 10;
  242. }
  243. </style>