add_order_details.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div class="mainContentBox">
  3. <avue-form
  4. ref="formRef"
  5. v-model:search="search"
  6. v-model="form"
  7. :data="data"
  8. :option="option2"
  9. v-model:page="page"
  10. @row-save="createRow"
  11. @row-update="updateRow"
  12. @row-del="deleteRow"
  13. @search-change="searchChange"
  14. @size-change="dataList"
  15. @current-change="dataList"
  16. @selection-change="selectionChange"
  17. />
  18. <avue-crud
  19. ref="crudRef"
  20. v-model="form"
  21. :data="data"
  22. :option="option"
  23. v-model:page="page"
  24. @row-save="createRow"
  25. @row-update="updateRow"
  26. @row-del="deleteRow"
  27. >
  28. <template #menu-left="{ size }">
  29. <el-button type="primary" icon="el-icon-plus" circle @click="addSkill"
  30. /></template>
  31. </avue-crud>
  32. <el-dialog
  33. v-model="dialog1.visible"
  34. :title="dialog1.title"
  35. width="950px"
  36. @close="dialog1.visible = false"
  37. >
  38. <choice-item-page @material-info="materialInfo" :enabled="null" />
  39. </el-dialog>
  40. <el-dialog
  41. v-model="dialog2.visible"
  42. :title="dialog2.title"
  43. width="950px"
  44. @close="dialog2.visible = false"
  45. >
  46. <choice_out_materials @material-info="materialInfo" />
  47. </el-dialog>
  48. <div class="detail-footer">
  49. <el-button type="primary" @click="onHandle"> 确定 </el-button>
  50. <el-button @click="cancelWindow">取消</el-button>
  51. </div>
  52. </div>
  53. </template>
  54. <script setup>
  55. import { ref, getCurrentInstance } from "vue";
  56. import { useCrud } from "@/hooks/userCrud";
  57. import { getAreaAndPlaceByCode, saveWmsOrder } from "@/api/storage";
  58. import { useCommonStoreHook, useDictionaryStore } from "@/store";
  59. import dictDataUtil from "@/common/configs/dictDataUtil";
  60. const { isShowTable, tableType } = toRefs(useCommonStoreHook());
  61. // 数据字典相关
  62. const { dicts } = useDictionaryStore();
  63. const data2 = ref(null);
  64. // 传入一个url,后面不带/
  65. const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  66. useCrud({
  67. src: "/api/v1/sys/skillScore",
  68. });
  69. const emit = defineEmits(["closeDialog"]);
  70. const cancelWindow = () => {
  71. emit("closeDialog", 11);
  72. };
  73. const {
  74. dataList,
  75. createRow,
  76. updateRow,
  77. deleteRow,
  78. searchChange,
  79. dataNoPageList,
  80. } = Methords; //增删改查
  81. const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
  82. const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
  83. const formRef = ref(null);
  84. const option2 = ref(null);
  85. const ctableRef = ref(null); //crudRef.value 获取avue-crud对象
  86. const router = useRouter();
  87. const dialog1 = reactive({
  88. title: "物料选择",
  89. visible: false,
  90. });
  91. const dialog2 = reactive({
  92. title: "出库选择",
  93. visible: false,
  94. });
  95. onMounted(() => {
  96. /* const bom = ref({
  97. batchCode: "",
  98. $cellEdit: true,
  99. });
  100. data.value.push(bom.value);*/
  101. });
  102. const addSkill = () => {
  103. const bom = ref({
  104. batchCode: "",
  105. $cellEdit: true,
  106. });
  107. data.value.push(bom.value);
  108. };
  109. const props = defineProps({
  110. dialog: {
  111. type: Object,
  112. default: () => {
  113. return {};
  114. },
  115. },
  116. });
  117. const materialInfo = (value) => {
  118. if (form.value.type === "4") {
  119. let item = {
  120. unit: value.unit,
  121. id: value.id,
  122. batchCode: value.batchCode,
  123. num: value.num,
  124. materialNo: value.materialNo,
  125. materialName: value.materialName,
  126. spec: value.spec,
  127. $cellEdit: true,
  128. };
  129. data.value[clickIndex.value] = item;
  130. dialog2.visible = false;
  131. } else {
  132. let item = {
  133. unit: value.unitDictValue,
  134. materialNo: value.materialCode,
  135. materialName: value.materialName,
  136. spec: value.spec,
  137. $cellEdit: true,
  138. };
  139. data.value[clickIndex.value] = item;
  140. dialog1.visible = false;
  141. }
  142. };
  143. const onHandle = () => {
  144. formRef.value.validate((valid) => {
  145. if (valid) {
  146. if (data.value.length === 0) {
  147. ElMessage({
  148. message: "没有要保存数据",
  149. type: "error",
  150. });
  151. return false;
  152. }
  153. if (data.value.length > 0) {
  154. for (let i = 0; i < data.value.length; i++) {
  155. if (
  156. data.value[i].materialNo === undefined ||
  157. data.value[i].materialNo === null ||
  158. data.value[i].materialNo === ""
  159. ) {
  160. ElMessage({
  161. message: "第" + (i + 1) + "项没有选择物料",
  162. type: "error",
  163. });
  164. return false;
  165. }
  166. if (
  167. data.value[i].batchCode === undefined ||
  168. data.value[i].batchCode === null ||
  169. data.value[i].batchCode === ""
  170. ) {
  171. ElMessage({
  172. message: "第" + (i + 1) + "项没有输入批号",
  173. type: "error",
  174. });
  175. return false;
  176. }
  177. if (
  178. data.value[i].num === undefined ||
  179. data.value[i].num === null ||
  180. data.value[i].num === ""
  181. ) {
  182. ElMessage({
  183. message: "第" + (i + 1) + "项没有输入数量",
  184. type: "error",
  185. });
  186. return false;
  187. }
  188. }
  189. }
  190. //进行保存
  191. const saveData = { detailsList: data.value, ...form.value };
  192. saveData.vehicleCode = new Date().getTime();
  193. saveWmsOrder(saveData).then((res) => {
  194. ElMessage.success("操作成功");
  195. cancelWindow();
  196. });
  197. }
  198. });
  199. };
  200. const areaArray = ref([]);
  201. const placeArray = ref([]);
  202. const houseNoChange = async ({ value }) => {
  203. if (value) {
  204. let res = await getAreaAndPlaceByCode(value);
  205. areaArray.value = res.data;
  206. formRef.value.updateDic("locationNo", areaArray.value);
  207. }
  208. };
  209. const areaChange = async (obj) => {
  210. let places = obj?.item?.positions ?? [];
  211. placeArray.value = places;
  212. formRef.value.updateDic("coordinate", placeArray.value);
  213. };
  214. // 设置表格列或者其他自定义的option
  215. option2.value = {
  216. selection: true,
  217. submitBtn: false,
  218. clearAbleBtn: false,
  219. emptyBtn: false,
  220. column: [
  221. {
  222. label: "操作类型",
  223. prop: "type",
  224. width: 60,
  225. overHidden: true,
  226. type: "select",
  227. search: true,
  228. change: () => {
  229. data.value = [];
  230. },
  231. rules: [
  232. {
  233. required: true,
  234. message: "操作类型不能为空",
  235. trigger: "trigger",
  236. },
  237. ],
  238. dicData: [
  239. { label: "原材料入库", value: "1" },
  240. { label: "工装入库", value: "2" },
  241. { label: "退料", value: "3" },
  242. { label: "出库", value: "4" },
  243. ],
  244. },
  245. {
  246. label: "仓库编码",
  247. prop: "houseNo",
  248. type: "select",
  249. search: true,
  250. width: 90,
  251. overHidden: true,
  252. editDisabled: true,
  253. dicUrl: dictDataUtil.request_url + dictDataUtil.TYPE_CODE.warehouse_type,
  254. props: {
  255. label: "dictLabel",
  256. value: "dictValue",
  257. },
  258. rules: [
  259. {
  260. required: true,
  261. message: "仓库编码不能为空",
  262. trigger: "trigger",
  263. },
  264. ],
  265. change: houseNoChange,
  266. },
  267. {
  268. label: "任务单号",
  269. width: 130,
  270. search: true,
  271. overHidden: true,
  272. prop: "taskNo",
  273. rules: [
  274. {
  275. required: true,
  276. message: "任务单号不能为空",
  277. trigger: "trigger",
  278. },
  279. ],
  280. },
  281. {
  282. label: "货区",
  283. width: 110,
  284. overHidden: true,
  285. type: "select",
  286. dictData: [],
  287. prop: "locationNo",
  288. props: {
  289. label: "area",
  290. value: "area",
  291. },
  292. rules: [
  293. {
  294. required: true,
  295. message: "货位不能为空",
  296. trigger: "trigger",
  297. },
  298. ],
  299. change: areaChange,
  300. },
  301. {
  302. label: "货位",
  303. overHidden: true,
  304. prop: "coordinate",
  305. type: "select",
  306. dictData: [],
  307. props: {
  308. label: "name",
  309. value: "name",
  310. },
  311. rules: [
  312. {
  313. required: true,
  314. message: "货位不能为空",
  315. trigger: "trigger",
  316. },
  317. ],
  318. },
  319. ],
  320. };
  321. const clickIndex = ref(0);
  322. // 设置表格列或者其他自定义的option
  323. option.value = Object.assign(option.value, {
  324. selection: false,
  325. addBtn: false,
  326. viewBtn: false,
  327. editBtn: false,
  328. saveBtn: false,
  329. search: false,
  330. cellBtn: true,
  331. menuWidth: 100,
  332. column: [
  333. {
  334. label: "物料编码",
  335. prop: "materialNo",
  336. readonly: true,
  337. cell: true,
  338. overHidden: true,
  339. click: ({ value, column, index }) => {
  340. clickIndex.value = index;
  341. if (!form.value.type) {
  342. ElMessage.error("请选择操作类型");
  343. } else {
  344. if (form.value.type === "4") {
  345. dialog2.visible = true;
  346. } else {
  347. dialog1.visible = true;
  348. }
  349. }
  350. },
  351. },
  352. {
  353. label: "物料名称",
  354. prop: "materialName",
  355. readonly: true,
  356. overHidden: true,
  357. },
  358. {
  359. label: "物料型号",
  360. prop: "spec",
  361. readonly: true,
  362. overHidden: true,
  363. },
  364. {
  365. label: "批次号",
  366. overHidden: true,
  367. prop: "batchCode",
  368. cell: true,
  369. },
  370. {
  371. label: "数量",
  372. prop: "num",
  373. type: "number",
  374. cell: true,
  375. min: 0,
  376. max: 99999,
  377. },
  378. {
  379. label: "单位",
  380. prop: "unit",
  381. width: 60,
  382. },
  383. ],
  384. });
  385. </script>
  386. <style type="text/css">
  387. .title-detail {
  388. width: 30%;
  389. height: 50px;
  390. line-height: 50px;
  391. margin: 25px 20px 25px 0;
  392. float: left;
  393. }
  394. .detail {
  395. margin: 0 auto;
  396. width: 100%;
  397. }
  398. .avue-crud {
  399. float: left;
  400. }
  401. .detail-footer {
  402. float: right;
  403. margin-top: 15px;
  404. }
  405. .el-select__selection {
  406. width: 150px;
  407. }
  408. </style>