index.vue 13 KB

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