Browse Source

对接分类

谢杰标 2 năm trước cách đây
mục cha
commit
015abd4dd1

+ 34 - 0
src/api/goods/index.js

@@ -17,3 +17,37 @@ export function restorePwd(data) {
     data,
   });
 }
+
+//类目树
+export function goodscategorytree(data) {
+  return request({
+    url: "/goods/category/tree",
+    method: "get",
+    params: data,
+  });
+}
+
+//新增类目
+export function addCategory(data) {
+  return request({
+    url: "/goods/category/save",
+    method: "post",
+    data,
+  });
+}
+//修改类目
+export function editCategory(data) {
+  return request({
+    url: "/goods/category/update",
+    method: "post",
+    data,
+  });
+}
+
+// 分类详情
+export function getCategoryDetail(id) {
+  return request({
+    url: "/goods/category/detail/" + id,
+    method: "get",
+  });
+}

+ 13 - 5
src/api/menu.js

@@ -1,9 +1,17 @@
-import request from '@/utils/request'
+import request from "@/utils/request";
 
 // 获取路由
 export const getRouters = () => {
   return request({
-    url: '/getRouters',
-    method: 'get'
-  })
-}
+    url: "/getRouters",
+    method: "get",
+  });
+};
+
+// 获得配置信息
+export const getStoreConfig = () => {
+  return request({
+    url: "/getStoreConfig",
+    method: "get",
+  });
+};

+ 17 - 0
src/components/tableList.vue

@@ -172,6 +172,23 @@
           <div v-else-if="item.scope === 'solt'">
             <slot :name="item.soltName" :scope="scope"></slot>
           </div>
+          <div v-else-if="item.scope === 'switch'">
+            <el-switch
+              v-model="scope.row[item.prop]"
+              active-color="#13ce66"
+              inactive-color="#ff4949"
+              :active-value="1"
+              :inactive-value="0"
+              @change="
+                $emit(
+                  'switchChange',
+                  scope.row[item.id || 'id'],
+                  $event,
+                  scope.row
+                )
+              "
+            ></el-switch>
+          </div>
           <span v-else>
             {{ scope.row[item.prop] }}
             {{

+ 16 - 14
src/permission.js

@@ -24,21 +24,23 @@ router.beforeEach((to, from, next) => {
     } else {
       if (store.getters.roles.length === 0) {
         // 判断当前用户是否已拉取完user_info信息
-        store
-          .dispatch("GetInfo")
-          .then(() => {
-            store.dispatch("GenerateRoutes").then((accessRoutes) => {
-              // 根据roles权限生成可访问的路由表
-              router.addRoutes(accessRoutes); // 动态添加可访问路由表
-              next({ ...to, replace: true }); // hack方法 确保addRoutes已完成
+        store.dispatch("GetStoreConfig").then(() => {
+          store
+            .dispatch("GetInfo")
+            .then(() => {
+              store.dispatch("GenerateRoutes").then((accessRoutes) => {
+                // 根据roles权限生成可访问的路由表
+                router.addRoutes(accessRoutes); // 动态添加可访问路由表
+                next({ ...to, replace: true }); // hack方法 确保addRoutes已完成
+              });
+            })
+            .catch((err) => {
+              store.dispatch("LogOut").then(() => {
+                Message.error(err);
+                next({ path: "/" });
+              });
             });
-          })
-          .catch((err) => {
-            store.dispatch("LogOut").then(() => {
-              Message.error(err);
-              next({ path: "/" });
-            });
-          });
+        });
       } else {
         console.log("to:", to);
         next();

+ 14 - 1
src/store/modules/permission.js

@@ -1,5 +1,5 @@
 import { constantRoutes } from "@/router";
-import { getRouters } from "@/api/menu";
+import { getRouters, getStoreConfig } from "@/api/menu";
 import Layout from "@/layout/index";
 import ParentView from "@/components/ParentView";
 import api from "@/api/api";
@@ -13,6 +13,7 @@ const permission = {
     topbarRouters: [],
     sidebarRouters: [],
     dictManages: {}, //字典数据
+    config: null,
   },
   getters: {
     dictManages: (state) => state.dictManages,
@@ -54,6 +55,9 @@ const permission = {
     SET_SIDEBAR_ROUTERS: (state, routes) => {
       state.sidebarRouters = routes;
     },
+    SET_CONFIG: (state, config) => {
+      state.config = config;
+    },
   },
   actions: {
     // 生成路由
@@ -95,6 +99,15 @@ const permission = {
         });
       });
     },
+    GetStoreConfig({ commit }) {
+      return new Promise((resolve) => {
+        // 向后端请求路由数据
+        getStoreConfig().then((res) => {
+          commit("SET_CONFIG", res.data);
+          resolve();
+        });
+      });
+    },
   },
 };
 

+ 8 - 1
src/utils/request.js

@@ -20,12 +20,19 @@ const service = axios.create({
 // request拦截器
 service.interceptors.request.use(
   (config) => {
-    config.headers["TenantId"] = "1"
+    config.headers["TenantId"] = "1";
     // 是否需要设置 token
     const isToken = (config.headers || {}).isToken === false;
     if (getToken() && !isToken) {
       config.headers["AuthorizationToken"] = "Store " + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
     }
+    if (store.state.permission.config) {
+      let { merId, storeId, tenantId } = store.state.permission.config;
+      config.headers["TenantId"] = tenantId;
+      config.headers["MerId"] = merId;
+      if (storeId) config.headers["StoreId"] = storeId;
+    }
+
     // 转换时间戳
     if (config.isProce) {
       config.params = paramMate(config.params);

+ 29 - 20
src/views/goodsMag/classify.vue

@@ -1,7 +1,7 @@
 <template>
   <container title="商品分类">
     <template v-slot:btn>
-      <el-button type="primary" @click="dialogVisible = true"
+      <el-button type="primary" @click="handelEdit(undefined)"
         >添加分类</el-button
       >
       <el-button @click="batchDel">批量删除</el-button>
@@ -19,26 +19,16 @@
       :navText="navText"
       rowKey="categoryId"
       :loading="loading"
+      @switchChange="() => {}"
     >
-      <template slot="status" slot-scope="props">
-        <el-switch
-          v-model="props.scope.row.status"
-          active-color="#13ce66"
-          inactive-color="#ff4949"
-          :active-value="1"
-          :inactive-value="0"
-          @change="statusChange($event, props.scope.row)"
-        >
-        </el-switch>
-      </template>
       <template slot="btn" slot-scope="props">
-        <el-button type="text" @click="handelClick(2, props.scope.row.tpId)"
+        <el-button type="text" @click="handelEdit(props.scope.row.categoryId)"
           >编辑</el-button
         >
-        <el-button type="text" @click="resetPass(props.scope.row.tpId)"
+        <el-button type="text" @click="resetPass(props.scope.row.categoryId)"
           >添加</el-button
         >
-        <el-button type="text" @click="handelDel(props.scope.row.tpId)"
+        <el-button type="text" @click="handelDel(props.scope.row.categoryId)"
           >删除</el-button
         >
       </template>
@@ -49,13 +39,17 @@
       :currentPage.sync="formData.pageNum"
       @search="search"
     />
-    <class-set-dlg :dialogVisible.sync="dialogVisible"></class-set-dlg>
+    <class-set-dlg
+      @search="search"
+      :categoryId="categoryId"
+      :dialogVisible.sync="dialogVisible"
+    ></class-set-dlg>
   </container>
 </template>
 
 <script>
 import ClassSetDlg from "./components/ClassSetDlg";
-import { goodscategorylist } from "../../api/goods/index";
+import { goodscategorylist, editCategory } from "../../api/goods/index";
 export default {
   name: "SaasMemberRecord",
 
@@ -76,11 +70,15 @@ export default {
           label: "分类名称",
           prop: "categoryName",
         },
+        {
+          label: "所属店铺",
+          prop: "storeName",
+        },
         {
           label: "启动状态",
           prop: "status",
-          scope: "solt",
-          soltName: "status",
+          scope: "switch",
+          id: "categoryId",
         },
         {
           label: "创建时间",
@@ -88,7 +86,7 @@ export default {
           scope: "aTimeList",
         },
       ],
-      tableData: [{}],
+      tableData: [],
       total: 0,
       formList: [
         {
@@ -101,6 +99,7 @@ export default {
         },
       ],
       dialogVisible: false,
+      categoryId: "",
     };
   },
 
@@ -142,6 +141,12 @@ export default {
         .then(() => {})
         .catch(() => {});
     },
+    editCategory() {
+      editStore({ storeId, status, merId: "1" }).then((res) => {
+        status == -1 && this.$message.success("删除成功");
+        this.search();
+      });
+    },
     resetPass(id) {
       this.$confirm("确定恢复为初始密码吗?", "提示", {
         confirmButtonText: "确定",
@@ -187,6 +192,10 @@ export default {
       //       return (row.status = e ? 0 : 1);
       //     });
     },
+    handelEdit(categoryId) {
+      this.categoryId = categoryId;
+      this.dialogVisible = true;
+    },
   },
   components: { ClassSetDlg },
 };

+ 73 - 45
src/views/goodsMag/components/ClassSetDlg.vue

@@ -1,9 +1,10 @@
 <template>
   <Base-dialog
-    :title="form.id ? '编辑分类' : '添加分类'"
+    :title="categoryId ? '编辑分类' : '添加分类'"
     :isShow.sync="isShow"
     @close="close"
-    :isShowFooter="false"
+    @open="open"
+    @submit="submitForm"
     width="450px"
   >
     <el-form
@@ -14,8 +15,24 @@
       :rules="rules"
       ref="form"
     >
+      <el-form-item label="所属店铺:" prop="storeId">
+        <el-select
+          :disabled="categoryId"
+          :style="{ width: '100%' }"
+          v-model="form.storeId"
+          placeholder="请选择所属店铺"
+        >
+          <el-option
+            v-for="item in storeList"
+            :key="item.storeId"
+            :label="item.storeName"
+            :value="item.storeId"
+          ></el-option>
+        </el-select>
+      </el-form-item>
       <el-form-item label="上级分类:" prop="parentId">
         <el-cascader
+          :disabled="categoryId"
           placeholder="请选择上级分类"
           :options="computerTree(categorytreeList)"
           :show-all-levels="false"
@@ -28,41 +45,53 @@
           v-model="form.parentId"
         ></el-cascader>
       </el-form-item>
-      <el-form-item label="分类名称:" prop="userName">
-        <el-input v-model.Number="form.userName" placeholder="请输入提现金额">
+      <el-form-item label="分类名称:" prop="categoryName">
+        <el-input
+          v-model.Number="form.categoryName"
+          placeholder="请输入分类名称"
+        >
         </el-input>
       </el-form-item>
       <el-form-item label="状态:" prop="status">
-        <el-radio-group v-model="formData.status">
+        <el-radio-group v-model="form.status">
           <el-radio :label="1">启用</el-radio
           ><el-radio :label="0">禁用</el-radio>
         </el-radio-group>
       </el-form-item>
     </el-form>
-    <div class="btns clearfix">
-      <el-button @click="visible = false">取消</el-button>
-      <el-button type="primary" @click="submitForm">启用</el-button>
-      <el-button type="info">保存</el-button>
-    </div>
   </Base-dialog>
 </template>
 
 <script>
 import { mapGetters } from "vuex";
+import {
+  goodscategorytree,
+  addCategory,
+  editCategory,
+  getCategoryDetail,
+} from "../../../api/goods/index";
 export default {
   props: {
     dialogVisible: {
       type: Boolean,
       default: false,
     },
+    categoryId: {
+      type: [Number, String],
+    },
   },
   data() {
     return {
       form: {},
       rules: {
-        name: [{ required: true, message: "请输入真实姓名", trigger: "blur" }],
+        categoryName: [
+          { required: true, message: "请输入分类名称", trigger: "blur" },
+        ],
         parentId: [
-          { required: true, message: "请选择启动状态", trigger: "change" },
+          { required: true, message: "请选择上级分类", trigger: "change" },
+        ],
+        storeId: [
+          { required: true, message: "请选择所属店铺", trigger: "change" },
         ],
       },
       options: [
@@ -95,36 +124,57 @@ export default {
           ],
         },
       ],
+      categorytreeList: [],
     };
   },
   methods: {
+    open() {
+      this.resetForm();
+      this.goodscategorytree();
+      this.categoryId && this.getDatail();
+    },
     resetForm() {
       this.form = {
-        id: undefined,
-        name: undefined,
+        categoryId: undefined,
+        storeId: undefined,
+        status: 1,
+        categoryName: undefined,
         parentId: undefined,
       };
       this.clearForm("form");
     },
+    getDatail() {
+      getCategoryDetail(this.categoryId).then(({ data }) => {
+        Object.keys(this.form).forEach((key) => {
+          this.form[key] = data[key];
+        });
+      });
+    },
     submitForm() {
       this.$refs.form.validate(async (valid) => {
         if (valid) {
-          withdrawal(this.form).then((res) => {
-            if (res.code == 200) {
-              this.$message.success("提现申请成功");
+          const fn = this.categoryId ? editCategory : addCategory;
+          fn(this.form)
+            .then((res) => {
+              this.$message.success(this.categoryId ? "修改成功" : "新增成功");
+              this.$emit("search");
               this.isShow = false;
-              this.$emit("getSellerInfo");
-            }
-          });
+            })
+            .catch(() => {});
         } else {
           return false;
         }
       });
     },
     close() {
-      //   this.isShow = false;
+      this.resetForm();
       this.clearForm("form");
     },
+    goodscategorytree() {
+      goodscategorytree({ status: 1 }).then((res) => {
+        this.categorytreeList = res.data;
+      });
+    },
   },
   computed: {
     isShow: {
@@ -142,40 +192,18 @@ export default {
             categoryId: 0,
             categoryName: "---无---",
           },
+          ...rows,
         ];
-        if (rows?.length > 0) {
-          array.push(
-            ...rows.filter((i) => i.storeId === this.formData.storeId)
-          );
-        }
         return array;
       };
     },
-    ...mapGetters(["roleList"]),
+    ...mapGetters(["storeList"]),
   },
-  created() {},
   components: {},
-  watch: {
-    dialogVisible: {
-      handler(val) {
-        if (val) {
-          this.resetForm();
-        }
-      },
-      immediate: true,
-    },
-  },
 };
 </script>
 
 <style lang="scss" scoped>
-.btns {
-  .el-button {
-    margin-top: 20px;
-    float: right;
-    margin-left: 14px;
-  }
-}
 /deep/ {
   .el-cascader {
     width: 100%;

+ 3 - 13
src/views/storeMag/index.vue

@@ -17,18 +17,8 @@
       :navText="navText"
       rowKey="id"
       :loading="loading"
+      @switchChange="editStore"
     >
-      <template slot="status" slot-scope="props">
-        <el-switch
-          v-model="props.scope.row.status"
-          active-color="#13ce66"
-          inactive-color="#ff4949"
-          :active-value="1"
-          :inactive-value="0"
-          @change="editStore(props.scope.row.storeId, $event)"
-        >
-        </el-switch>
-      </template>
       <template slot="btn" slot-scope="props">
         <el-button type="text" @click="handelEdit(props.scope.row.storeId)"
           >编辑</el-button
@@ -82,8 +72,8 @@ export default {
         {
           label: "启动状态",
           prop: "status",
-          scope: "solt",
-          soltName: "status",
+          scope: "switch",
+          id: "storeId",
         },
         {
           label: "创建时间",

+ 18 - 29
src/views/storeMag/staff.vue

@@ -20,18 +20,8 @@
       :navText="navText"
       rowKey="id"
       :loading="loading"
+      @switchChange="editUser"
     >
-      <template slot="status" slot-scope="props">
-        <el-switch
-          v-model="props.scope.row.status"
-          active-color="#13ce66"
-          inactive-color="#ff4949"
-          :active-value="1"
-          :inactive-value="0"
-          @change="statusChange(props.scope.row, $event)"
-        >
-        </el-switch>
-      </template>
       <template slot="btn" slot-scope="props">
         <el-button type="text" @click="handelEdit(props.scope.row.userId)"
           >编辑</el-button
@@ -39,7 +29,9 @@
         <el-button type="text" @click="resetPass(props.scope.row.userId)"
           >密码恢复</el-button
         >
-        <el-button type="text" @click="del(props.scope.row)">删除</el-button>
+        <el-button type="text" @click="del(props.scope.row.userId)"
+          >删除</el-button
+        >
       </template>
     </table-list>
     <pagination
@@ -94,8 +86,8 @@ export default {
         {
           label: "启动状态",
           prop: "status",
-          scope: "solt",
-          soltName: "status",
+          scope: "switch",
+          id: "userId",
         },
       ],
       tableData: [],
@@ -113,27 +105,27 @@ export default {
     init() {
       this.search(2);
     },
-    del(row) {
+    del(userId) {
       this.$confirm("确定删除吗?", "提示", {
         confirmButtonText: "确定",
         cancelButtonText: "取消",
         type: "warning",
       })
         .then(() => {
-          this.editUser(row, -1);
+          this.editUser(userId, -1);
         })
         .catch(() => {});
     },
-    editUser(row, status) {
-      var data = {
-        userId: row.userId,
-        status,
-        userName: row.userName,
-      };
-      this.$api.editUser(data).then((res) => {
-        status == -1 && this.$message.success("删除成功");
-        this.search();
-      });
+    editUser(userId, status) {
+      this.$api
+        .editUser({
+          userId,
+          status,
+        })
+        .then((res) => {
+          status == -1 && this.$message.success("删除成功");
+          this.search();
+        });
     },
     handelEdit(userId) {
       this.userId = userId;
@@ -177,9 +169,6 @@ export default {
         })
         .catch(() => {});
     },
-    statusChange(e, row) {
-      this.editUser(e, row);
-    },
     search(v) {
       if (v === 2) {
         this.formData = {