index.vue 8.3 KB

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