index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. :source="sourceList.data"
  7. :pagination="sourceList.pagination"
  8. :config="config"
  9. :loading="loading"
  10. highlight-current-row
  11. :selectConfig="selectConfig"
  12. :table-events="{
  13. //element talbe事件都能传
  14. select: select,
  15. }"
  16. :action-list="[
  17. {
  18. text: '发起盘点',
  19. action: () => openModal('add'),
  20. },
  21. ]"
  22. @get-list="getList"
  23. >
  24. <template #slotName="{ item }">
  25. {{ item.createTime }}
  26. </template>
  27. </byTable>
  28. </div>
  29. <el-dialog
  30. :title="modalType == 'add' ? '发起盘点' : '盘点详情'"
  31. v-model="dialogVisible"
  32. width="800"
  33. v-loading="loading"
  34. >
  35. <byForm
  36. :formConfig="formConfig"
  37. :formOption="formOption"
  38. v-model="formData.data"
  39. :rules="rules"
  40. ref="byform"
  41. >
  42. <template #products>
  43. <div style="width: 100%">
  44. <el-button
  45. type="primary"
  46. @click="openProduct = true"
  47. style="margin-bottom: 10px"
  48. >
  49. 添加物品
  50. </el-button>
  51. <el-table :data="formData.data.stockWaitDetailsList">
  52. <el-table-column prop="name" label="物品编码" />
  53. <el-table-column prop="name" label="物品名称" />
  54. <el-table-column prop="name" label="规格型号" />
  55. <el-table-column prop="name" label="单位" />
  56. <el-table-column prop="name" label="库存数量" />
  57. <el-table-column prop="quantity" label="盘点数量" min-width="150">
  58. <template #default="{ row, $index }">
  59. <el-form-item
  60. :prop="'stockWaitDetailsList.' + $index + '.quantity'"
  61. :rules="rules.quantity"
  62. :inline-message="true"
  63. >
  64. <el-input-number
  65. v-model="row.quantity"
  66. :precision="4"
  67. :controls="false"
  68. :min="0"
  69. />
  70. </el-form-item>
  71. </template>
  72. </el-table-column>
  73. <el-table-column prop="name" label="盘点结果" />
  74. <el-table-column prop="zip" label="操作" width="100">
  75. <template #default="{ $index }">
  76. <el-button type="primary" link @click="handleRemove($index)"
  77. >删除</el-button
  78. >
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. </div>
  83. </template>
  84. </byForm>
  85. <template #footer>
  86. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  87. <el-button
  88. type="primary"
  89. @click="submitForm('byform')"
  90. size="large"
  91. :loading="submitLoading"
  92. >
  93. 确 定
  94. </el-button>
  95. </template>
  96. </el-dialog>
  97. <el-dialog
  98. v-model="openProduct"
  99. title="选择物品"
  100. width="70%"
  101. append-to-body
  102. >
  103. <SelectGoods
  104. @cancel="openProduct = false"
  105. @pushGoods="pushGoods"
  106. ></SelectGoods>
  107. </el-dialog>
  108. </div>
  109. </template>
  110. <script setup>
  111. /* eslint-disable vue/no-unused-components */
  112. import { ElMessage, ElMessageBox } from "element-plus";
  113. import byTable from "@/components/byTable/index";
  114. import byForm from "@/components/byForm/index";
  115. import { computed, defineComponent, ref } from "vue";
  116. import useUserStore from "@/store/modules/user";
  117. import SelectGoods from "@/components/product/SelectGoods";
  118. const loading = ref(false);
  119. const submitLoading = ref(false);
  120. const sourceList = ref({
  121. data: [],
  122. pagination: {
  123. total: 3,
  124. pageNum: 1,
  125. pageSize: 10,
  126. },
  127. });
  128. let dialogVisible = ref(false);
  129. let openProduct = ref(false);
  130. let roomDialogVisible = ref(false);
  131. let modalType = ref("add");
  132. let rules = ref({
  133. code: [{ required: true, message: "请输入spu编码", trigger: "blur" }],
  134. name: [{ required: true, message: "请输入spu名称", trigger: "blur" }],
  135. });
  136. const { proxy } = getCurrentInstance();
  137. const selectConfig = reactive([
  138. {
  139. label: "盘点结论",
  140. prop: "type",
  141. data: [
  142. {
  143. label: "正常",
  144. value: "1",
  145. },
  146. {
  147. label: "异常",
  148. value: "2",
  149. },
  150. ],
  151. },
  152. ]);
  153. const config = computed(() => {
  154. return [
  155. {
  156. attrs: {
  157. label: "单号",
  158. prop: "code",
  159. },
  160. },
  161. {
  162. attrs: {
  163. label: "调出仓库",
  164. prop: "name",
  165. },
  166. },
  167. {
  168. attrs: {
  169. label: "调出人",
  170. prop: "remark",
  171. },
  172. },
  173. {
  174. attrs: {
  175. label: "调出时间",
  176. prop: "remark",
  177. },
  178. },
  179. {
  180. attrs: {
  181. label: "接收状态",
  182. prop: "remark",
  183. },
  184. },
  185. {
  186. attrs: {
  187. label: "调入仓库",
  188. prop: "remark",
  189. },
  190. },
  191. {
  192. attrs: {
  193. label: "接收人",
  194. prop: "remark",
  195. },
  196. },
  197. {
  198. attrs: {
  199. label: "接收时间",
  200. prop: "remark",
  201. },
  202. },
  203. {
  204. attrs: {
  205. label: "操作",
  206. width: "200",
  207. align: "right",
  208. },
  209. // 渲染 el-button,一般用在最后一列。
  210. renderHTML(row) {
  211. return [
  212. {
  213. attrs: {
  214. label: "接收",
  215. type: "primary",
  216. text: true,
  217. },
  218. el: "button",
  219. click() {
  220. getDtl(row);
  221. },
  222. },
  223. {
  224. attrs: {
  225. label: "打印",
  226. type: "primary",
  227. text: true,
  228. },
  229. el: "button",
  230. click() {
  231. getDtl(row);
  232. },
  233. },
  234. ];
  235. },
  236. },
  237. ];
  238. });
  239. let formData = reactive({
  240. data: {},
  241. treeData: [],
  242. });
  243. const formOption = reactive({
  244. inline: true,
  245. labelWidth: 100,
  246. itemWidth: 100,
  247. rules: [],
  248. });
  249. const byform = ref(null);
  250. const treeData = ref([]);
  251. const formConfig = reactive([
  252. {
  253. type: "select",
  254. prop: "warehouseId",
  255. label: "盘点仓库",
  256. itemWidth: 33,
  257. isLoad: {
  258. url: "/warehouse/page",
  259. req: {
  260. pageNum: 1,
  261. pageSize: 9999,
  262. },
  263. labelKey: "name",
  264. labelVal: "id",
  265. method: "post",
  266. resUrl: "rows",
  267. },
  268. },
  269. {
  270. type: "title",
  271. title: "盘点明细",
  272. },
  273. {
  274. type: "slot",
  275. slotName: "products",
  276. label: "",
  277. },
  278. ]);
  279. const getList = async (req) => {
  280. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  281. loading.value = true;
  282. proxy
  283. .post("/productSpu/page", sourceList.value.pagination)
  284. .then((message) => {
  285. console.log(message);
  286. sourceList.value.data = message.rows;
  287. sourceList.value.pagination.total = message.total;
  288. setTimeout(() => {
  289. loading.value = false;
  290. }, 200);
  291. });
  292. };
  293. const openModal = () => {
  294. dialogVisible.value = true;
  295. modalType.value = "add";
  296. formData.data = {
  297. stockWaitDetailsList: [],
  298. };
  299. };
  300. const submitForm = () => {
  301. console.log(byform.value);
  302. byform.value.handleSubmit((valid) => {
  303. submitLoading.value = true;
  304. proxy.post("/productSpu/" + modalType.value, formData.data).then(
  305. (res) => {
  306. ElMessage({
  307. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  308. type: "success",
  309. });
  310. dialogVisible.value = false;
  311. submitLoading.value = false;
  312. getList();
  313. },
  314. (err) => (submitLoading.value = false)
  315. );
  316. });
  317. };
  318. const getDtl = (row) => {
  319. modalType.value = "edit";
  320. proxy.post("/productSpu/detail", { id: row.id }).then((res) => {
  321. res.stockWaitDetailsList = res.productInfoList;
  322. formData.data = res;
  323. dialogVisible.value = true;
  324. });
  325. };
  326. getList();
  327. const handleSelect = (row) => {
  328. const flag = formData.data.stockWaitDetailsList.some((x) => x.id === row.id);
  329. if (flag)
  330. return ElMessage({
  331. message: "该物品已选择",
  332. type: "info",
  333. });
  334. formData.data.stockWaitDetailsList.push({
  335. name: row.name,
  336. code: row.code,
  337. id: row.id,
  338. });
  339. return ElMessage({
  340. message: "选择成功",
  341. type: "success",
  342. });
  343. };
  344. const pushGoods = (goods) => {
  345. const arr = goods.map((x) => ({
  346. linkProductId: x.id,
  347. linkQuantity: "",
  348. name: x.name,
  349. code: x.code,
  350. }));
  351. formData.data.stockWaitDetailsList =
  352. formData.data.stockWaitDetailsList.concat(arr);
  353. return ElMessage({
  354. message: "添加成功!",
  355. type: "success",
  356. });
  357. };
  358. const handleRemove = (index) => {
  359. formData.data.stockWaitDetailsList.splice(index, 1);
  360. return ElMessage({
  361. message: "删除成功",
  362. type: "success",
  363. });
  364. };
  365. </script>
  366. <style lang="scss" scoped>
  367. .tenant {
  368. padding: 20px;
  369. }
  370. </style>