index.vue 13 KB

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