ReturnGood.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <div style="width: 100%; padding: 0px 15px">
  3. <byForm
  4. :formConfig="formConfig"
  5. :formOption="formOption"
  6. v-model="formData.data"
  7. :rules="rules"
  8. ref="formDom"
  9. >
  10. <template #details>
  11. <div style="width: 100%">
  12. <el-button
  13. type="primary"
  14. @click="openProduct = true"
  15. style="margin-bottom: 10px"
  16. >
  17. 添加物品
  18. </el-button>
  19. <el-table :data="formData.data.salesReturnDetailList">
  20. <el-table-column
  21. prop="goodType"
  22. label="货品类型"
  23. :formatter="(row) => (row.goodType == 1 ? '产品' : '物料')"
  24. />
  25. <el-table-column prop="productCode" label="货品编码" />
  26. <el-table-column prop="productName" label="货品名称" />
  27. <el-table-column prop="productSpec" label="规格型号" />
  28. <el-table-column
  29. prop="productUnit"
  30. label="单位"
  31. :formatter="
  32. (row) =>
  33. row.goodType == 1
  34. ? dictValueLabel(row.productUnit, productUnit)
  35. : dictValueLabel(row.productUnit, productUnitOne)
  36. "
  37. />
  38. <el-table-column prop="count" label="退货数量" min-width="150">
  39. <template #default="{ row, $index }">
  40. <el-form-item
  41. :prop="'salesReturnDetailList.' + $index + '.count'"
  42. :rules="rules.count"
  43. :inline-message="true"
  44. >
  45. <el-input-number
  46. onmousewheel="return false;"
  47. v-model="row.count"
  48. :precision="4"
  49. :controls="false"
  50. :min="0"
  51. />
  52. </el-form-item>
  53. </template>
  54. </el-table-column>
  55. <el-table-column prop="remark" label="退货原因" min-width="150">
  56. <template #default="{ row, $index }">
  57. <el-form-item
  58. :prop="'salesReturnDetailList.' + $index + '.remark'"
  59. :rules="rules.remark"
  60. :inline-message="true"
  61. >
  62. <el-input
  63. v-model="row.remark"
  64. placeholder="请输入"
  65. type="textarea"
  66. />
  67. </el-form-item>
  68. </template>
  69. </el-table-column>
  70. <el-table-column prop="zip" label="操作" width="100">
  71. <template #default="{ $index }">
  72. <el-button type="primary" link @click="handleRemove($index)"
  73. >删除</el-button
  74. >
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. </div>
  79. </template>
  80. </byForm>
  81. <el-dialog
  82. v-if="openProduct"
  83. v-model="openProduct"
  84. title="选择货品"
  85. width="70%"
  86. append-to-body
  87. >
  88. <SelectGoods
  89. :selectList="acquireSelectList()"
  90. @cancel="openProduct = false"
  91. @pushGoods="pushGoods"
  92. ></SelectGoods>
  93. </el-dialog>
  94. </div>
  95. </template>
  96. <script setup>
  97. import byForm from "@/components/byForm/index";
  98. import { ElMessage } from "element-plus";
  99. import SelectGoods from "@/components/product/SelectGoods";
  100. import useUserStore from "@/store/modules/user";
  101. const { proxy } = getCurrentInstance();
  102. const route = useRoute();
  103. let formData = reactive({
  104. data: {
  105. supplyId: "",
  106. salesReturnDetailList: [],
  107. returnName: "",
  108. },
  109. });
  110. let rules = ref({
  111. supplyId: [{ required: true, message: "请选择供应商", trigger: "change" }],
  112. count: [{ required: true, message: "请输入退货数量", trigger: "blur" }],
  113. remark: [{ required: true, message: "请输入退货原因", trigger: "blur" }],
  114. });
  115. const formOption = reactive({
  116. inline: true,
  117. labelWidth: 100,
  118. itemWidth: 100,
  119. });
  120. const formConfig = computed(() => {
  121. return [
  122. {
  123. type: "input",
  124. prop: "returnDept",
  125. label: "申请部门",
  126. itemWidth: 25,
  127. disabled: true,
  128. style: {
  129. "margin-right": "10px",
  130. },
  131. },
  132. {
  133. type: "input",
  134. prop: "returnName",
  135. label: "申请人",
  136. itemWidth: 25,
  137. disabled: true,
  138. style: {
  139. "margin-right": "10px",
  140. },
  141. },
  142. {
  143. type: "date",
  144. prop: "purchaseTime",
  145. label: "申请时间",
  146. itemWidth: 25,
  147. disabled: true,
  148. style: {
  149. "margin-right": "10px",
  150. },
  151. },
  152. {
  153. type: "select",
  154. prop: "supplyId",
  155. label: "供应商",
  156. isLoad: {
  157. url: "/supplierInfo/page",
  158. req: {
  159. pageNum: 1,
  160. pageSize: 9999,
  161. },
  162. labelKey: "name",
  163. labelVal: "id",
  164. method: "post",
  165. resUrl: "rows",
  166. },
  167. },
  168. {
  169. type: "slot",
  170. slotName: "details",
  171. label: "退货明细",
  172. },
  173. ];
  174. });
  175. const formDom = ref(null);
  176. const handleSubmit = async () => {
  177. const vaild = await formDom.value.handleSubmit(() => {}); //拿到内部表单是否验证通过
  178. if (vaild) {
  179. if (formData.data.salesReturnDetailList.length > 0) {
  180. const list = formData.data.salesReturnDetailList;
  181. for (let i = 0; i < list.length; i++) {
  182. const e = list[i];
  183. if (e.count == 0) {
  184. ElMessage({
  185. message: "退货数量不能为0!",
  186. type: "info",
  187. });
  188. return false;
  189. }
  190. }
  191. return true;
  192. }
  193. ElMessage({
  194. message: "请添加退货明细!",
  195. type: "info",
  196. });
  197. return false;
  198. }
  199. };
  200. let openProduct = ref(false);
  201. const handleRemove = (index) => {
  202. formData.data.salesReturnDetailList.splice(index, 1);
  203. return ElMessage({
  204. message: "删除成功!",
  205. type: "success",
  206. });
  207. };
  208. const pushGoods = (goods) => {
  209. if (goods && goods.length > 0) {
  210. let afterFiltering = [];
  211. if (
  212. formData.data.salesReturnDetailList &&
  213. formData.data.salesReturnDetailList.length > 0
  214. ) {
  215. afterFiltering = goods.filter((item) => {
  216. let data = formData.data.salesReturnDetailList.filter(
  217. (itemProduct) => itemProduct.bussinessId === item.id
  218. );
  219. if (data && data.length > 0) {
  220. return false;
  221. }
  222. return true;
  223. });
  224. } else {
  225. afterFiltering = goods;
  226. }
  227. const arr = afterFiltering.map((x) => ({
  228. goodType: x.goodType,
  229. productCode: x.code,
  230. productName: x.name,
  231. productSpec: x.spec,
  232. productUnit: x.unit,
  233. count: 0,
  234. bussinessId: x.id,
  235. remark: "",
  236. }));
  237. formData.data.salesReturnDetailList =
  238. formData.data.salesReturnDetailList.concat(arr);
  239. openProduct.value = false;
  240. return ElMessage({
  241. message: "添加成功!",
  242. type: "success",
  243. });
  244. } else {
  245. ElMessage("请选择至少一件物品");
  246. }
  247. };
  248. // 接收父组件的传值
  249. const props = defineProps({
  250. queryData: String,
  251. });
  252. // 获取用户信息并赋默认值
  253. const userInfo = useUserStore().user;
  254. onMounted(() => {
  255. if (!route.query.processType) {
  256. formData.data.purchaseTime = proxy.parseTime(new Date());
  257. formData.data.returnDept = userInfo.dept.deptName;
  258. formData.data.returnName = userInfo.nickName;
  259. }
  260. });
  261. const judgeStatus = () => {
  262. if (route.query.processType == 20 || route.query.processType == 10) {
  263. return true;
  264. }
  265. if (props.queryData.recordList && props.queryData.recordList.length > 0) {
  266. let data = props.queryData.recordList.filter(
  267. (item) => item.status === 2 && item.nodeType !== 1
  268. );
  269. if (data && data.length > 0) {
  270. return true;
  271. }
  272. }
  273. return false;
  274. };
  275. watch(
  276. props.queryData,
  277. () => {
  278. formOption.disabled = judgeStatus();
  279. if (
  280. props.queryData &&
  281. ["10", "20", "30"].includes(route.query.processType)
  282. ) {
  283. for (const key in props.queryData) {
  284. formData.data[key] = props.queryData[key];
  285. }
  286. }
  287. },
  288. {
  289. deep: true,
  290. }
  291. );
  292. const productUnit = ref([]);
  293. const productUnitOne = ref([]);
  294. const getDict = () => {
  295. proxy.getDictOne(["unit", "material_unit"]).then((res) => {
  296. productUnit.value = res["unit"].map((x) => ({
  297. label: x.dictValue,
  298. value: x.dictKey,
  299. }));
  300. productUnitOne.value = res["material_unit"].map((x) => ({
  301. label: x.dictValue,
  302. value: x.dictKey,
  303. }));
  304. });
  305. };
  306. getDict();
  307. const getFormData = () => {
  308. return proxy.deepClone(formData.data);
  309. };
  310. // 向父组件暴露
  311. defineExpose({
  312. getFormData,
  313. handleSubmit,
  314. });
  315. const acquireSelectList = () => {
  316. let data = [];
  317. if (
  318. formData.data.salesReturnDetailList &&
  319. formData.data.salesReturnDetailList.length > 0
  320. ) {
  321. data = formData.data.salesReturnDetailList.map((item) => {
  322. return {
  323. id: item.bussinessId,
  324. name: item.productName,
  325. };
  326. });
  327. }
  328. return data;
  329. };
  330. </script>
  331. <style lang="scss" scoped></style>