index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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: '添加spu',
  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' ? '添加spu' : '编辑'"
  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.productInfos">
  52. <el-table-column prop="code" label="产品编码" />
  53. <el-table-column prop="name" label="产品名称" />
  54. <el-table-column prop="spec" label="规格" />
  55. <el-table-column prop="zip" label="操作" width="100">
  56. <template #default="{ $index }">
  57. <el-button type="primary" link @click="handleRemove($index)"
  58. >删除</el-button
  59. >
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. </div>
  64. </template>
  65. </byForm>
  66. <template #footer>
  67. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  68. <el-button
  69. type="primary"
  70. @click="submitForm('byform')"
  71. size="large"
  72. :loading="submitLoading"
  73. >
  74. 确 定
  75. </el-button>
  76. </template>
  77. </el-dialog>
  78. <el-dialog
  79. v-model="openProduct"
  80. title="选择产品"
  81. width="70%"
  82. append-to-body
  83. >
  84. <SelectProduct @handleSelect="handleSelect"></SelectProduct>
  85. <template #footer>
  86. <span class="dialog-footer">
  87. <el-button @click="openProduct = false">取消</el-button>
  88. </span>
  89. </template>
  90. </el-dialog>
  91. </div>
  92. </template>
  93. <script setup>
  94. /* eslint-disable vue/no-unused-components */
  95. import { ElMessage, ElMessageBox } from "element-plus";
  96. import byTable from "@/components/byTable/index";
  97. import byForm from "@/components/byForm/index";
  98. import { computed, defineComponent, ref } from "vue";
  99. import useUserStore from "@/store/modules/user";
  100. import SelectProduct from "@/components/WDLY/product/SelectProduct";
  101. const loading = ref(false);
  102. const submitLoading = ref(false);
  103. const sourceList = ref({
  104. data: [],
  105. pagination: {
  106. total: 3,
  107. pageNum: 1,
  108. pageSize: 10,
  109. },
  110. });
  111. let dialogVisible = ref(false);
  112. let openProduct = ref(false);
  113. let roomDialogVisible = ref(false);
  114. let modalType = ref("add");
  115. let rules = ref({
  116. code: [{ required: true, message: "请输入spu编码", trigger: "blur" }],
  117. name: [{ required: true, message: "请输入spu名称", trigger: "blur" }],
  118. });
  119. const { proxy } = getCurrentInstance();
  120. const selectConfig = reactive([
  121. // {
  122. // label: "spu类型",
  123. // prop: "type",
  124. // data: [],
  125. // },
  126. ]);
  127. const config = computed(() => {
  128. return [
  129. {
  130. attrs: {
  131. label: "spu编码",
  132. prop: "code",
  133. },
  134. },
  135. {
  136. attrs: {
  137. label: "spu名称",
  138. prop: "name",
  139. },
  140. },
  141. {
  142. attrs: {
  143. label: "关联产品数",
  144. prop: "count",
  145. },
  146. },
  147. {
  148. attrs: {
  149. label: "spu说明",
  150. prop: "remark",
  151. },
  152. },
  153. {
  154. attrs: {
  155. label: "操作",
  156. width: "200",
  157. align: "right",
  158. },
  159. // 渲染 el-button,一般用在最后一列。
  160. renderHTML(row) {
  161. return [
  162. {
  163. attrs: {
  164. label: "修改",
  165. type: "primary",
  166. text: true,
  167. },
  168. el: "button",
  169. click() {
  170. getDtl(row);
  171. },
  172. },
  173. {
  174. attrs: {
  175. label: "删除",
  176. type: "danger",
  177. text: true,
  178. },
  179. el: "button",
  180. click() {
  181. // 弹窗提示是否删除
  182. ElMessageBox.confirm(
  183. "此操作将永久删除该数据, 是否继续?",
  184. "提示",
  185. {
  186. confirmButtonText: "确定",
  187. cancelButtonText: "取消",
  188. type: "warning",
  189. }
  190. ).then(() => {
  191. // 删除
  192. proxy
  193. .post("/productSpu/delete", {
  194. id: row.id,
  195. })
  196. .then((res) => {
  197. ElMessage({
  198. message: "删除成功",
  199. type: "success",
  200. });
  201. getList();
  202. });
  203. });
  204. },
  205. },
  206. ];
  207. },
  208. },
  209. ];
  210. });
  211. let formData = reactive({
  212. data: {},
  213. treeData: [],
  214. });
  215. const formOption = reactive({
  216. inline: true,
  217. labelWidth: 100,
  218. itemWidth: 100,
  219. rules: [],
  220. });
  221. const byform = ref(null);
  222. const treeData = ref([]);
  223. const formConfig = reactive([
  224. {
  225. type: "input",
  226. prop: "code",
  227. label: "spu编码",
  228. },
  229. {
  230. type: "input",
  231. prop: "name",
  232. label: "spu名称",
  233. },
  234. {
  235. type: "input",
  236. itemType: "textarea",
  237. prop: "remark",
  238. label: "spu说明",
  239. },
  240. {
  241. type: "slot",
  242. slotName: "products",
  243. prop: "keeperId",
  244. label: "关联产品",
  245. },
  246. ]);
  247. const getList = async (req) => {
  248. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  249. loading.value = true;
  250. proxy
  251. .post("/productSpu/page", sourceList.value.pagination)
  252. .then((message) => {
  253. sourceList.value.data = message.rows;
  254. sourceList.value.pagination.total = message.total;
  255. setTimeout(() => {
  256. loading.value = false;
  257. }, 200);
  258. });
  259. };
  260. const openModal = () => {
  261. dialogVisible.value = true;
  262. modalType.value = "add";
  263. formData.data = {
  264. productInfos: [],
  265. };
  266. };
  267. const submitForm = () => {
  268. byform.value.handleSubmit((valid) => {
  269. submitLoading.value = true;
  270. proxy.post("/productSpu/" + modalType.value, formData.data).then(
  271. (res) => {
  272. ElMessage({
  273. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  274. type: "success",
  275. });
  276. dialogVisible.value = false;
  277. submitLoading.value = false;
  278. getList();
  279. },
  280. (err) => (submitLoading.value = false)
  281. );
  282. });
  283. };
  284. const getDtl = (row) => {
  285. modalType.value = "edit";
  286. proxy.post("/productSpu/detail", { id: row.id }).then((res) => {
  287. res.productInfos = res.productInfoList;
  288. formData.data = res;
  289. dialogVisible.value = true;
  290. });
  291. };
  292. const warehouseType = ref([]);
  293. const getDict = () => {
  294. // // 币种数据
  295. proxy
  296. .post("/dictTenantData/page", {
  297. pageNum: 1,
  298. pageSize: 999,
  299. tenantId: useUserStore().user.tenantId,
  300. dictCode: "warehouse_type",
  301. })
  302. .then((res) => {
  303. warehouseType.value = res.rows;
  304. selectConfig[0].data = res.rows.map((x) => ({
  305. label: x.dictValue,
  306. value: x.dictKey,
  307. }));
  308. formConfig[0].data = res.rows.map((x) => ({
  309. label: x.dictValue,
  310. value: x.dictKey,
  311. }));
  312. });
  313. };
  314. getList();
  315. // getDict();
  316. const handleSelect = (row) => {
  317. const flag = formData.data.productInfos.some((x) => x.id === row.id);
  318. if (flag)
  319. return ElMessage({
  320. message: "该产品已选择",
  321. type: "info",
  322. });
  323. formData.data.productInfos.push({
  324. name: row.name,
  325. code: row.customCode,
  326. spec: row.spec,
  327. id: row.id,
  328. });
  329. return ElMessage({
  330. message: "选择成功",
  331. type: "success",
  332. });
  333. };
  334. const handleRemove = (index) => {
  335. formData.data.productInfos.splice(index, 1);
  336. return ElMessage({
  337. message: "删除成功",
  338. type: "success",
  339. });
  340. };
  341. </script>
  342. <style lang="scss" scoped>
  343. .tenant {
  344. padding: 20px;
  345. }
  346. </style>