ReturnGood.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div style="width: 100%; padding: 0px 15px">
  3. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="formDom">
  4. <template #details>
  5. <div style="width: 100%">
  6. <el-button type="primary" @click="openProduct = true" style="margin-bottom: 10px"> 添加物品 </el-button>
  7. <el-table :data="formData.data.salesReturnDetailList">
  8. <el-table-column prop="productCode" label="货品编码" />
  9. <el-table-column prop="productName" label="货品名称" />
  10. <el-table-column prop="productSpec" label="规格" />
  11. <el-table-column prop="productUnit" label="单位" />
  12. <el-table-column prop="count" label="退货数量" min-width="150">
  13. <template #default="{ row, $index }">
  14. <el-form-item :prop="'salesReturnDetailList.' + $index + '.count'" :rules="rules.count" :inline-message="true">
  15. <el-input-number onmousewheel="return false;" v-model="row.count" :precision="4" :controls="false" :min="0" />
  16. </el-form-item>
  17. </template>
  18. </el-table-column>
  19. <el-table-column prop="remark" label="退货原因" min-width="150">
  20. <template #default="{ row, $index }">
  21. <el-form-item :prop="'salesReturnDetailList.' + $index + '.remark'" :rules="rules.remark" :inline-message="true">
  22. <el-input v-model="row.remark" placeholder="请输入" />
  23. </el-form-item>
  24. </template>
  25. </el-table-column>
  26. <el-table-column prop="zip" label="操作" width="100">
  27. <template #default="{ $index }">
  28. <el-button type="primary" link @click="handleRemove($index)">删除</el-button>
  29. </template>
  30. </el-table-column>
  31. </el-table>
  32. </div>
  33. </template>
  34. </byForm>
  35. <el-dialog v-model="openProduct" title="选择货品" width="70%" append-to-body>
  36. <SelectGoods @cancel="openProduct = false" @pushGoods="pushGoods"></SelectGoods>
  37. </el-dialog>
  38. </div>
  39. </template>
  40. <script setup>
  41. import byForm from "@/components/byForm/index";
  42. import { ElMessage, ElMessageBox } from "element-plus";
  43. import SelectGoods from "@/components/product/SelectGoods";
  44. import useUserStore from "@/store/modules/user";
  45. const { proxy } = getCurrentInstance();
  46. let formData = reactive({
  47. data: {
  48. supplyId: "",
  49. salesReturnDetailList: [],
  50. returnName: "",
  51. },
  52. });
  53. let rules = ref({
  54. supplyId: [{ required: true, message: "请选择供应商", trigger: "change" }],
  55. count: [{ required: true, message: "请输入退货数量", trigger: "blur" }],
  56. remark: [{ required: true, message: "请输入退货原因", trigger: "blur" }],
  57. });
  58. const formOption = reactive({
  59. inline: true,
  60. labelWidth: 100,
  61. itemWidth: 100,
  62. });
  63. const formConfig = computed(() => {
  64. return [
  65. {
  66. type: "input",
  67. prop: "returnDept",
  68. label: "申请部门",
  69. itemWidth: 25,
  70. disabled: true,
  71. style: {
  72. "margin-right": "10px",
  73. },
  74. },
  75. {
  76. type: "input",
  77. prop: "returnName",
  78. label: "申请人",
  79. itemWidth: 25,
  80. disabled: true,
  81. style: {
  82. "margin-right": "10px",
  83. },
  84. },
  85. {
  86. type: "date",
  87. prop: "purchaseTime",
  88. label: "申请时间",
  89. itemWidth: 25,
  90. disabled: true,
  91. style: {
  92. "margin-right": "10px",
  93. },
  94. },
  95. {
  96. type: "select",
  97. prop: "supplyId",
  98. label: "供应商",
  99. isLoad: {
  100. url: "/supplierInfo/page",
  101. req: {
  102. pageNum: 1,
  103. pageSize: 9999,
  104. },
  105. labelKey: "name",
  106. labelVal: "id",
  107. method: "post",
  108. resUrl: "rows",
  109. },
  110. },
  111. {
  112. type: "slot",
  113. slotName: "details",
  114. label: "退货明细",
  115. },
  116. ];
  117. });
  118. const formDom = ref(null);
  119. const handleSubmit = async () => {
  120. const vaild = await formDom.value.handleSubmit(() => {}); //拿到内部表单是否验证通过
  121. if (vaild) {
  122. if (formData.data.salesReturnDetailList.length > 0) {
  123. const list = formData.data.salesReturnDetailList;
  124. for (let i = 0; i < list.length; i++) {
  125. const e = list[i];
  126. if (e.count == 0) {
  127. ElMessage({
  128. message: "退货数量不能为0!",
  129. type: "info",
  130. });
  131. return false;
  132. }
  133. }
  134. return true;
  135. }
  136. ElMessage({
  137. message: "请添加退货明细!",
  138. type: "info",
  139. });
  140. return false;
  141. }
  142. };
  143. let openProduct = ref(false);
  144. const handleRemove = (index) => {
  145. formData.data.salesReturnDetailList.splice(index, 1);
  146. return ElMessage({
  147. message: "删除成功!",
  148. type: "success",
  149. });
  150. };
  151. const pushGoods = (goods) => {
  152. const arr = goods.map((x) => ({
  153. goodType: x.goodType,
  154. productCode: x.code,
  155. productName: x.name,
  156. productSpec: x.spec,
  157. productUnit: x.unit,
  158. count: 0,
  159. bussinessId: x.id,
  160. remark: "",
  161. }));
  162. formData.data.salesReturnDetailList = formData.data.salesReturnDetailList.concat(arr);
  163. openProduct.value = false;
  164. return ElMessage({
  165. message: "添加成功!",
  166. type: "success",
  167. });
  168. };
  169. // 接收父组件的传值
  170. const props = defineProps({
  171. queryData: String,
  172. });
  173. // 获取用户信息并赋默认值
  174. const userInfo = useUserStore().user;
  175. onMounted(() => {
  176. formData.data.purchaseTime = proxy.parseTime(new Date());
  177. formData.data.returnDept = userInfo.dept.deptName;
  178. formData.data.returnName = userInfo.nickName;
  179. });
  180. // 向父组件暴露
  181. defineExpose({
  182. submitData: formData.data,
  183. handleSubmit,
  184. });
  185. </script>
  186. <style lang="scss" scoped></style>