SelectAllGood.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div class="user">
  3. <div class="tree">
  4. <AllTreeList title="分类" submitType="2" :hiddenBtn="true" :data="treeListData" v-model="sourceList.pagination.productClassifyId"
  5. @change="treeChange">
  6. </AllTreeList>
  7. </div>
  8. <div class="content">
  9. <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" :selectConfig="selectConfig"
  10. highlight-current-row :action-list="[
  11. ]" @get-list="getList">
  12. <template #pic="{ item }">
  13. <div v-if="item.fileList.length > 0">
  14. <img :src="item.fileList[0].fileUrl" class="pic" @click="handleClickFile(item.fileList[0])" />
  15. </div>
  16. <div v-else></div>
  17. </template>
  18. <template #name="{ item }">
  19. <div>
  20. <span class="el-click">{{ item.name }}</span>
  21. </div>
  22. </template>
  23. <template #size="{ item }">
  24. <div v-if="item['length'] && item.width && item.height">
  25. <span>{{ item['length'] }}cm</span>*
  26. <span>{{ item.width }}cm</span>*
  27. <span>{{ item.height }}cm</span>
  28. </div>
  29. <div v-else></div>
  30. </template>
  31. <template #price="{ item }">
  32. <div v-if="item.price">
  33. <span>{{ item.currency }} {{ moneyFormat(item.price ,2)}}</span>
  34. </div>
  35. <div v-else></div>
  36. </template>
  37. <template #costPrice="{ item }">
  38. <div v-if="item.costPrice">
  39. <span>{{ item.currency }} {{ moneyFormat(item.costPrice ,2)}}</span>
  40. </div>
  41. <div v-else></div>
  42. </template>
  43. </byTable>
  44. </div>
  45. </div>
  46. </template>
  47. <script setup>
  48. import { computed, ref } from "vue";
  49. import byTable from "@/components/byTable/index";
  50. import useUserStore from "@/store/modules/user";
  51. import AllTreeList from "@/components/product/allTreeList.vue";
  52. import { ElMessage, ElMessageBox } from "element-plus";
  53. const { proxy } = getCurrentInstance();
  54. const props = defineProps({
  55. selectStatus: Boolean,
  56. warehouseId: String,
  57. rowId: {
  58. type: String,
  59. default: "",
  60. },
  61. });
  62. const warehouseList = ref([]);
  63. const sourceList = ref({
  64. data: [],
  65. pagination: {
  66. total: 0,
  67. pageNum: 1,
  68. pageSize: 10,
  69. keyword: "",
  70. companyId: "",
  71. definition: "",
  72. productClassifyId: "",
  73. },
  74. });
  75. const productUnit = ref([]);
  76. const definition = ref([
  77. {
  78. label: "产品",
  79. value: "1",
  80. },
  81. {
  82. label: "物料",
  83. value: "2",
  84. },
  85. ]);
  86. const loading = ref(false);
  87. const companyData = ref([]);
  88. const selectConfig = computed(() => {
  89. return [
  90. {
  91. label: "归属公司",
  92. prop: "companyId",
  93. data: companyData.value,
  94. isShowAll: false,
  95. },
  96. {
  97. label: "物品类型",
  98. prop: "definition",
  99. data: definition.value,
  100. },
  101. ];
  102. });
  103. const config = computed(() => {
  104. return [
  105. {
  106. attrs: {
  107. label: "图片",
  108. slot: "pic",
  109. align: "center",
  110. width: 80,
  111. },
  112. },
  113. {
  114. attrs: {
  115. label: "物料分类",
  116. prop: "classifyName",
  117. "min-width": 150,
  118. },
  119. },
  120. {
  121. attrs: {
  122. label: "物料编码",
  123. prop: "customCode",
  124. width: 120,
  125. },
  126. },
  127. {
  128. attrs: {
  129. label: " 物料名称",
  130. slot: "name",
  131. "min-width": 150,
  132. },
  133. },
  134. {
  135. attrs: {
  136. label: "物料材质",
  137. prop: "material",
  138. width: 120,
  139. },
  140. },
  141. {
  142. attrs: {
  143. label: "物料型号",
  144. prop: "spec",
  145. width: 120,
  146. },
  147. },
  148. {
  149. attrs: {
  150. label: "单位",
  151. prop: "unit",
  152. width: 80,
  153. },
  154. render(val) {
  155. return proxy.dictKeyValue(val, materialUnitData.value);
  156. },
  157. },
  158. {
  159. attrs: {
  160. label: "尺寸",
  161. slot: "size",
  162. width: 180,
  163. },
  164. },
  165. {
  166. attrs: {
  167. label: "净重",
  168. prop: "netWeight",
  169. width: 100,
  170. },
  171. render(val) {
  172. if (val) {
  173. return val + " kg";
  174. }
  175. },
  176. },
  177. {
  178. attrs: {
  179. label: "成本价",
  180. slot: "costPrice",
  181. width: 100,
  182. },
  183. },
  184. // {
  185. // attrs: {
  186. // label: "操作",
  187. // slot: "btn",
  188. // width: 120,
  189. // fixed: "right",
  190. // align: "center",
  191. // },
  192. // },
  193. ];
  194. });
  195. const treeListData = ref([]);
  196. const arrayRecursion = (arr, definition) => {
  197. arr.forEach((item) => {
  198. item.definition = definition;
  199. if (item.children && item.children.length > 0) {
  200. arrayRecursion(item.children, definition);
  201. }
  202. });
  203. return arr;
  204. };
  205. const getDict = () => {
  206. proxy
  207. .get("/tenantDept/list", {
  208. pageNum: 1,
  209. pageSize: 9999,
  210. keyword: "",
  211. tenantId: proxy.useUserStore().user.tenantId,
  212. type: 0,
  213. })
  214. .then((res) => {
  215. companyData.value = res.data.map((x) => ({
  216. ...x,
  217. label: x.deptName,
  218. value: x.deptId,
  219. }));
  220. if (res.data && res.data.length > 0) {
  221. sourceList.value.pagination.companyId = companyData.value[0].value;
  222. }
  223. getList();
  224. });
  225. Promise.all([
  226. proxy.post("/productClassify/tree", {
  227. parentId: "",
  228. name: "",
  229. definition: "1",
  230. }),
  231. proxy.post("/productClassify/tree", {
  232. parentId: "",
  233. name: "",
  234. definition: "2",
  235. }),
  236. ]).then((res) => {
  237. if (res && res.length > 1) {
  238. res[1].forEach((x) => {
  239. x.id = x.id + "";
  240. });
  241. treeListData.value = [
  242. {
  243. id: "-1",
  244. label: "全部",
  245. parentId: "",
  246. children: [
  247. {
  248. id: "1",
  249. definition: "1",
  250. label: "产品",
  251. parentId: "-1",
  252. children: arrayRecursion(res[0], "1"),
  253. },
  254. {
  255. id: "2",
  256. definition: "2",
  257. label: "物料",
  258. parentId: "-1",
  259. children: arrayRecursion(res[1], "2"),
  260. },
  261. ],
  262. },
  263. ];
  264. }
  265. });
  266. };
  267. const getList = (req) => {
  268. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  269. loading.value = true;
  270. proxy.post("/productInfo/page", sourceList.value.pagination).then((res) => {
  271. sourceList.value.data = res.rows;
  272. sourceList.value.pagination.total = res.total;
  273. setTimeout(() => {
  274. loading.value = false;
  275. }, 200);
  276. const productIdList = res.rows.map((x) => x.id);
  277. // 请求文件数据并回显
  278. if (productIdList.length > 0) {
  279. proxy.getFile(productIdList, sourceList.value.data, "id");
  280. }
  281. });
  282. };
  283. const treeChange = (e) => {
  284. if (e.id != undefined && e.id != "-1") {
  285. let productClassifyId = "";
  286. if (["1", "2"].includes(e.id)) {
  287. sourceList.value.pagination.productClassifyId = "";
  288. sourceList.value.pagination.definition = e.id;
  289. } else {
  290. if (e.id != e.definition) {
  291. productClassifyId = e.id;
  292. }
  293. sourceList.value.pagination.productClassifyId = productClassifyId;
  294. sourceList.value.pagination.definition = e.definition;
  295. }
  296. getList();
  297. } else {
  298. sourceList.value.pagination.productClassifyId = "";
  299. sourceList.value.pagination.definition = "";
  300. getList();
  301. }
  302. };
  303. getDict();
  304. const checkTheFlow = (item) => {
  305. proxy.$router.replace({
  306. path: "/purchaseSales/stockManage/record",
  307. query: {
  308. productId: item.productId,
  309. warehouseId: item.warehouseId,
  310. },
  311. });
  312. };
  313. const deriveExcel = () => {
  314. console.log("deriveExcel");
  315. };
  316. // const clickSelect = (item) => {
  317. // proxy.$emit("select", item);
  318. // };
  319. const goodList = ref([]);
  320. const clickSelect = (row) => {
  321. const flag = goodList.value.some((x) => x.id === row.id);
  322. if (flag)
  323. return ElMessage({
  324. message: "该物品已选择",
  325. type: "info",
  326. });
  327. goodList.value.push({
  328. ...row,
  329. goodType: sourceList.value.pagination.definition,
  330. });
  331. return ElMessage({
  332. message: "选择成功",
  333. type: "success",
  334. });
  335. proxy.$emit("select", item);
  336. };
  337. const handleRemove = (index) => {
  338. goodList.value.splice(index, 1);
  339. return ElMessage({
  340. message: "删除成功",
  341. type: "success",
  342. });
  343. };
  344. const handleCancel = () => {
  345. goodList.value = [];
  346. proxy.$emit("cancel");
  347. };
  348. const handleSubmit = () => {
  349. if (!goodList.value.length > 0)
  350. return ElMessage({
  351. message: "请添加货品",
  352. type: "info",
  353. });
  354. proxy.$emit("select", goodList.value);
  355. goodList.value = [];
  356. };
  357. </script>
  358. <style lang="scss" scoped>
  359. .user {
  360. padding: 10px;
  361. display: flex;
  362. justify-content: space-between;
  363. .tree {
  364. width: 300px;
  365. }
  366. .content {
  367. width: calc(100% - 310px);
  368. }
  369. }
  370. .pic {
  371. object-fit: contain;
  372. width: 50px;
  373. height: 50px;
  374. cursor: pointer;
  375. vertical-align: middle;
  376. }
  377. </style>