Browse Source

业务用户

YY 2 years ago
parent
commit
84f7dada2c

+ 5 - 0
src/router/module/account.js

@@ -23,5 +23,10 @@ export default [
     path: '/admin/business',
     meta: { title: '业务用户' },
     component: () => import('@/views/admin/business/index.vue')
+  },
+  {
+    path: '/admin/business/detail',
+    meta: { title: '信息管理' },
+    component: () => import('@/views/admin/business/detail.vue')
   }
 ];

+ 118 - 0
src/views/admin/business/detail.vue

@@ -0,0 +1,118 @@
+<template>
+  <div id="detail">
+    <el-row>
+      <el-col :span="24" class="main">
+        <el-col :span="24" class="one">
+          <cSearch :is_back="true" @toBack="toBack"></cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cForm :span="24" :fields="formFields" :form="form" :rules="rules" @save="onSubmit">
+            <template #pid>
+              <el-option v-for="(i, index) in pidList" :key="index" :label="i.name" :value="i.id"></el-option>
+            </template>
+            <template #type>
+              <el-option v-for="(i, index) in typeList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #code>
+              <el-option v-for="(i, index) in codeList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #password>
+              <el-input v-model="form.password" placeholder="请输入密码" :disabled="form._id ? true : false" show-password></el-input>
+            </template>
+            <template #role>
+              <el-select v-model="form.role" multiple placeholder="请选择角色" style="width: 100%">
+                <el-option v-for="i in roleList" :key="i._id" :label="i.name" :value="i._id"> </el-option>
+              </el-select>
+            </template>
+          </cForm>
+        </el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script setup lang="ts">
+import type { FormRules } from 'element-plus';
+import type { Ref } from 'vue';
+import { ref, reactive, onMounted } from 'vue';
+import { ElMessage } from 'element-plus';
+import { useRoute } from 'vue-router';
+import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
+import { RoleStore } from '@common/src/stores/system/role'; // 角色
+import { AdminStore } from '@common/src/stores/admins/admin'; // 角色
+import type { IQueryResult } from '@/util/types.util';
+const admin = AdminStore();
+const dictData = DictDataStore();
+const role = RoleStore();
+const route = useRoute();
+let form: Ref<any> = ref({});
+let roleList: Ref<any> = ref([]);
+let pidList: Ref<any> = ref([]);
+let codeList: Ref<any> = ref([]);
+let typeList: Ref<any> = ref([
+  { label: '超级管理员', value: '0' },
+  { label: '管理员', value: '1' },
+  { label: '机构用户', value: '2' },
+  { label: '业务用户', value: '3' }
+]);
+
+// 表单
+let formFields: Ref<any[]> = ref([
+  { label: '所属上级', model: 'pid', type: 'select' },
+  { label: '用户类型', model: 'type', type: 'select', options: { disabled: true } },
+  { label: '邀请码', model: 'code', type: 'select' },
+  { label: '账号', model: 'account' },
+  { label: '密码', model: 'password', custom: true },
+  { label: '名称', model: 'name' },
+  { label: '手机号', model: 'phone' },
+  { label: '机构名称', model: 'dept_name' },
+  { label: '角色', model: 'role', custom: true }
+]);
+const rules = reactive<FormRules>({
+  name: [{ required: true, message: '名称', trigger: 'blur' }],
+  account: [{ required: true, message: '账号', trigger: 'blur' }],
+  type: [{ required: true, message: '用户类型', trigger: 'blur' }]
+});
+onMounted(async () => {
+  await searchOther();
+  await search();
+});
+const search = async () => {
+  if (route.query.id) {
+    let res: IQueryResult = await admin.fetch(route.query.id);
+    if (res.errcode == 0) {
+      form.value = res.data as {};
+    }
+  } else form.value.type = '3';
+};
+// 提交
+const onSubmit = async (data) => {
+  let res: IQueryResult;
+  if (data._id) res = await admin.update(data);
+  else res = await admin.create(data);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `维护信息成功` });
+    toBack();
+  }
+};
+// 返回上一页
+const toBack = () => {
+  window.history.go(-1);
+};
+const searchOther = async () => {
+  let res: IQueryResult;
+  // 邀请码
+  res = await dictData.query({ type: 'account_code' });
+  if (res.errcode == 0) {
+    let data: any = res.data;
+    codeList.value = data.filter((i) => i.value != 'CJGLY');
+  }
+  // 角色
+  res = await role.query();
+  if (res.errcode == 0) roleList.value = res.data;
+  // 管理员
+  res = await admin.query({ type: '2' });
+  if (res.errcode == 0) pidList.value = res.data;
+};
+</script>
+<style scoped lang="scss"></style>

+ 88 - 5
src/views/admin/business/index.vue

@@ -1,13 +1,96 @@
 <template>
   <div id="index">
     <el-row>
-      <el-col :span="24" class="main"> test </el-col>
+      <el-col :span="24" class="main animate__animated animate__backInRight">
+        <el-col :span="24" class="one">
+          <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch"> </cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cButton @toAdd="toAdd()"> </cButton>
+        </el-col>
+        <el-col :span="24" class="thr">
+          <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @edit="toEdit" @del="toDel" :select="false"> </cTable>
+        </el-col>
+      </el-col>
     </el-row>
   </div>
 </template>
-
-<script setup lang="ts">
+<script lang="ts" setup>
+import _ from 'lodash';
 import type { Ref } from 'vue';
-import { ref, toRefs } from 'vue';
+import { ref, onMounted, getCurrentInstance } from 'vue';
+import { ElMessage } from 'element-plus';
+import { useRouter } from 'vue-router';
+import { AdminStore } from '@common/src/stores/admins/admin'; // 角色
+import type { IQueryResult } from '@/util/types.util';
+const admin = AdminStore();
+const router = useRouter();
+const { proxy } = getCurrentInstance() as any;
+// 列表数据
+let list: Ref<any> = ref([]);
+// 总数
+let total: Ref<number> = ref(0);
+let skip = 0;
+let limit: number = proxy.$limit;
+// 列表
+let fields: Ref<any[]> = ref([
+  { label: '邀请码', model: 'code', isSearch: true },
+  { label: '姓名', model: 'name', isSearch: true },
+  { label: '手机号', model: 'phone', isSearch: true },
+  { label: '机构名称', model: 'dept_name', isSearch: true }
+]);
+// 操作
+let opera: Ref<any[]> = ref([
+  { label: '修改', method: 'edit' },
+  { label: '删除', method: 'del', confirm: true, type: 'danger' }
+]);
+
+// 查询数据
+let searchForm: Ref<any> = ref({});
+
+onMounted(async () => {
+  await search({ skip, limit });
+});
+// 查询
+const search = async (e: { skip: number; limit: number }) => {
+  const { skip, limit } = e;
+  const condition = _.cloneDeep(searchForm.value);
+  let info = { limit: limit, skip: skip, ...condition, type: '3' };
+  let res: IQueryResult = await admin.query(info);
+  if (res.errcode == 0) {
+    list.value = res.data;
+    total.value = res.total;
+  }
+};
+const toSearch = (query) => {
+  searchForm.value = query;
+  search({ skip, limit });
+};
+// 新增
+const toAdd = () => {
+  router.push({ path: '/admin/business/detail' });
+};
+// 修改
+const toEdit = async (data) => {
+  router.push({ path: '/admin/business/detail', query: { id: data._id } });
+};
+
+// 删除
+const toDel = async (data) => {
+  let res: IQueryResult = await admin.del(data._id);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `刪除信息成功` });
+    search({ skip, limit });
+  }
+};
 </script>
-<style scoped lang="scss"></style>
+<style lang="scss" scoped>
+.main {
+  .one {
+    margin: 0 0 10px 0;
+  }
+  .two {
+    margin: 0 0 10px 0;
+  }
+}
+</style>