index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <z-paging ref="paging" v-model="list" bgColor="#f7f7f7" @query="query" safe-area-inset-bottom>
  3. <template #top>
  4. <ut-navbar title="投入物料记录" :fixed="false"></ut-navbar>
  5. </template>
  6. <view>
  7. <view class="pd-24 bg-#fff">
  8. <up-alert title="注意:投入物料记录可用于记录此次任务投入过的物料,不分 管理具体事务、圈舍和时间记录。" type="info" class="b-radius"></up-alert>
  9. </view>
  10. <up-form class="p-rtv" labelPosition="top" :model="form" :rules="rules" labelWidth="auto" ref="upFormRef">
  11. <view class="bg-#fff pd-24 pt-0 mb-20">
  12. <!-- 使用物料 -->
  13. <up-form-item borderBottom label="使用物料" required prop="inputs" id="inputsgpppp">
  14. <view class="d-flex flex-cln w-100%">
  15. <view v-if="!isAdd" class="c-#B52B21 f-s-24">因物料修改涉及退库操作,不支持修改物料信息如有错误,请删除此条管理记录,重新添加。</view>
  16. <view class="w-100%">
  17. <Materialinfo :showClose="isAdd" v-model:datas="MaterialData" v-model:inputs="form.inputs" />
  18. </view>
  19. <view v-if="isAdd" class="d-flex a-c j-c pd-24 b-radius bg-#FBFDFB border-#AFDDBB" @click="goMaterial()">
  20. <view class=""></view>
  21. <view class="f-s-34 c-primary">请选择此次农事使用的物料</view>
  22. </view>
  23. </view>
  24. </up-form-item>
  25. <!-- 操作日期 -->
  26. <view class="h-1" id="operationDatepppp"></view>
  27. <!-- 记录人 -->
  28. <up-form-item borderBottom label="记录人" required prop="mgName" id="mgNamepppp">
  29. <up-input v-model="form.mgName" placeholder="请输入记录人" border="none"></up-input>
  30. </up-form-item>
  31. <!-- 备注 -->
  32. <up-form-item borderBottom label="备注/说明" prop="remark" id="remarkpppp">
  33. <up-input v-model="form.remark" placeholder="如:“防治阔叶杂草”、“花期追肥”" border="none"></up-input>
  34. </up-form-item>
  35. <up-form-item label="过程图片" prop="imgs" borderBottom id="imgspppp">
  36. <ut-upload v-model="form.imgs" :max-count="9" accept="image"></ut-upload>
  37. </up-form-item>
  38. <up-form-item label="过程视频" prop="videos" borderBottom id="videospppp">
  39. <ut-upload v-model="form.videos" :max-count="9" accept="video"></ut-upload>
  40. </up-form-item>
  41. </view>
  42. </up-form>
  43. </view>
  44. <template #bottom>
  45. <view class="pd-24 d-flex j-c gap-20 base-bottom-wrap">
  46. <up-button v-if="+isAdd" type="primary" @click="save()">确认添加</up-button>
  47. <up-button v-else type="primary" @click="change()">确认修改</up-button>
  48. </view>
  49. </template>
  50. </z-paging>
  51. </template>
  52. <script setup lang="ts">
  53. import { ref, reactive, computed, getCurrentInstance, type ComponentInternalInstance } from 'vue';
  54. import { useClientRequest } from '@/utils/request';
  55. import { useInfoStore } from '@/store';
  56. import Baseinfo from '../models/baseinfo.vue';
  57. import Materialinfo from '../models/materialinfo.vue';
  58. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  59. const { yes_no, pt_activity_input_material } = toRefs<any>(proxy?.useDict('yes_no', 'pt_activity_input_material'));
  60. const deawerData = ref();
  61. const infoStore = useInfoStore();
  62. // 表单数据
  63. const form = ref({
  64. taskId: '',
  65. //管理类型 1-农事管理 2-投料
  66. activityType: '2',
  67. opRemark: '',
  68. mgName: infoStore.userInfo?.name,
  69. inputFlag: '1',
  70. //物料列表
  71. inputs: [] as any,
  72. remark: '',
  73. imgs: null as string | null,
  74. videos: null as string | null,
  75. });
  76. const baseId = ref('');
  77. const Material = ref();
  78. //判断是新增还是修改
  79. const isAdd = ref(true);
  80. // 表单验证规则
  81. const rules = reactive({
  82. mgName: [{ required: true, message: '请输入记录人' }],
  83. remark: [{ required: false, message: '请输入备注' }],
  84. });
  85. const paging = ref();
  86. const list = ref();
  87. const upFormRef = ref<any>();
  88. const query = async (pageNo: number, pageSize: number) => {
  89. const res = await useClientRequest.get('/plt-api/app/plantationTask/list', {
  90. pageNo,
  91. pageSize,
  92. });
  93. // return res.data;
  94. };
  95. const MaterialData = ref([]);
  96. // 提交表单
  97. const save = () => {
  98. uni.$u.debounce(
  99. async () => {
  100. try {
  101. console.log('开始提交管理记录');
  102. await upFormRef.value?.validate();
  103. console.log('校验完成');
  104. const params = {
  105. ...form.value,
  106. };
  107. console.log('提交参数:', params);
  108. // 这里需要根据实际 API 进行调整
  109. const res = await useClientRequest.post('/plt-api/app/plantationActivity/saveActivity', params);
  110. if (res.code == 200) {
  111. uni.showToast({
  112. title: '提交成功',
  113. icon: 'success',
  114. duration: 2000,
  115. });
  116. setTimeout(() => {
  117. //发送emit
  118. uni.$emit('updatesuperviselist');
  119. uni.navigateBack({
  120. delta: 1,
  121. });
  122. }, 1000);
  123. }
  124. } catch (error: any) {
  125. console.log('表单验证错误:', error);
  126. // 滚动到第一个错误字段
  127. if (error && error[0]?.field) {
  128. const firstErrorField = error[0].field + 'pppp';
  129. paging.value?.scrollIntoViewById(firstErrorField, 30, true);
  130. }
  131. return;
  132. }
  133. },
  134. 1000,
  135. true,
  136. );
  137. };
  138. //修改提交表单
  139. const change = () => {
  140. uni.$u.debounce(
  141. async () => {
  142. try {
  143. console.log('开始提交管理记录');
  144. await upFormRef.value?.validate();
  145. console.log('校验完成');
  146. const params = {
  147. ...form.value,
  148. };
  149. console.log('提交参数:', params);
  150. // 这里需要根据实际 API 进行调整
  151. const res = await useClientRequest.post('/plt-api/app/plantationActivity/updateActivity', params);
  152. if (res.code == 200) {
  153. uni.showToast({
  154. title: '提交成功',
  155. icon: 'success',
  156. duration: 2000,
  157. });
  158. setTimeout(() => {
  159. //发送emit
  160. uni.$emit('updatesuperviselist');
  161. uni.navigateBack({
  162. delta: 1,
  163. });
  164. }, 1000);
  165. }
  166. } catch (error: any) {
  167. console.log('表单验证错误:', error);
  168. // 滚动到第一个错误字段
  169. if (error && error[0]?.field) {
  170. const firstErrorField = error[0].field + 'pppp';
  171. paging.value?.scrollIntoViewById(firstErrorField, 30, true);
  172. }
  173. return;
  174. }
  175. },
  176. 1000,
  177. true,
  178. );
  179. };
  180. const goMaterial = () => {
  181. if (!+isAdd.value) {
  182. return;
  183. }
  184. uni.$once('updateMaterial', function (data) {
  185. MaterialData.value = data?.data;
  186. data?.data.forEach((i) => {
  187. //判断 MaterialData.value中的id是否有i.id
  188. if (!MaterialData.value.find((item) => item.id === i.id)) {
  189. MaterialData.value.push(i);
  190. }
  191. });
  192. });
  193. uni.$u.route({ type: 'navigateTo', url: '/tools/supervise-material/index', params: { baseId: baseId.value } });
  194. };
  195. onLoad(async (options: any) => {
  196. baseId.value = options?.baseId;
  197. form.value.taskId = options?.taskId;
  198. isAdd.value = Boolean(+options?.add);
  199. if (!+isAdd.value) {
  200. const res = await useClientRequest.get(`/plt-api/app/plantationActivity/getInfo/${options.id}`);
  201. if (!res || res.code !== 200) return;
  202. form.value = res.data;
  203. MaterialData.value = res.data.inputMaterialList;
  204. res.data.inputMaterialList.forEach((i) => {
  205. if (!form.value.inputs) {
  206. form.value.inputs = [];
  207. }
  208. form.value.inputs.push({
  209. id: i.id,
  210. inputAmount: +i.quantity,
  211. });
  212. });
  213. }
  214. });
  215. </script>