|
@@ -2,37 +2,215 @@
|
|
|
<div id="index">
|
|
|
<el-row>
|
|
|
<el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
|
|
|
- <el-col :span="24" class="one">系统首页</el-col>
|
|
|
+ <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" @spec="toSpec" @edit="toEdit" @del="toDel"> </cTable>
|
|
|
+ </el-col>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
+ <cDialog :dialog="dialog" @toClose="toClose">
|
|
|
+ <template v-slot:info>
|
|
|
+ <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
|
|
|
+ <cForm :span="24" :fields="formFields" :form="form" :rules="rules" @save="onSubmit">
|
|
|
+ <template #file>
|
|
|
+ <cUpload
|
|
|
+ :model="`${'file'}`"
|
|
|
+ :limit="6"
|
|
|
+ listType="picture"
|
|
|
+ url="/files/material/goods/upload"
|
|
|
+ accept="*"
|
|
|
+ :list="form.file"
|
|
|
+ @change="onUpload"
|
|
|
+ ></cUpload>
|
|
|
+ </template>
|
|
|
+ <template #supplier_id>
|
|
|
+ <el-option v-for="i in supplierList" :key="i._id" :label="i.name" :value="i._id"></el-option>
|
|
|
+ </template>
|
|
|
+ <template #type>
|
|
|
+ <el-option v-for="i in typeList" :key="i.value" :label="i.label" :value="i.value"></el-option>
|
|
|
+ </template>
|
|
|
+ <template #is_use>
|
|
|
+ <el-radio v-for="i in is_useList" :key="i._id" :label="i.value">{{ i.label }}</el-radio>
|
|
|
+ </template>
|
|
|
+ </cForm>
|
|
|
+ </el-col>
|
|
|
+ </template>
|
|
|
+ </cDialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
-
|
|
|
-<script setup lang="ts">
|
|
|
+<script lang="ts" setup>
|
|
|
// 基础
|
|
|
+import _ from 'lodash';
|
|
|
+import type { FormRules } from 'element-plus';
|
|
|
import type { Ref } from 'vue';
|
|
|
-// reactive,
|
|
|
-import { onMounted, ref, getCurrentInstance } from 'vue';
|
|
|
+import { ref, onMounted, getCurrentInstance, reactive } from 'vue';
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
+import { useRouter } from 'vue-router';
|
|
|
+
|
|
|
// 接口
|
|
|
-//import { TestStore } from '@common/src/stores/test';
|
|
|
-//import type { IQueryResult } from '@/util/types.util';
|
|
|
-//const testAxios = TestStore();
|
|
|
+import { GoodStore } from '@/stores/good/goods'; //
|
|
|
+import { UserStore } from '@/stores/users/user';
|
|
|
+import { DictDataStore } from '@/stores/dict/dictData'; // 字典表
|
|
|
+import type { IQueryResult } from '@/util/types.util';
|
|
|
+const dictAxios = DictDataStore();
|
|
|
+const userAxios = UserStore();
|
|
|
+const goodAxios = GoodStore();
|
|
|
+// 路由
|
|
|
+const router = useRouter();
|
|
|
const { proxy } = getCurrentInstance() as any;
|
|
|
// 加载中
|
|
|
-const loading: Ref<any> = ref(false);
|
|
|
-// 分页数据
|
|
|
-// const skip = 0;
|
|
|
-// const limit = proxy.limit;;
|
|
|
-// 请求
|
|
|
+const loading = ref(false);
|
|
|
+// 列表数据
|
|
|
+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: 'name', isSearch: true },
|
|
|
+ { label: '销售数量', model: 'sell_num' },
|
|
|
+ { label: '供应商', model: 'supplier_id', format: (i: any) => getDict(i, 'supplier_id') },
|
|
|
+ { label: '类型', model: 'type', format: (i: any) => getDict(i, 'type') },
|
|
|
+ { label: '是否使用', model: 'is_use', format: (i: any) => getDict(i, 'is_use') }
|
|
|
+]);
|
|
|
+// 操作
|
|
|
+let opera: Ref<any[]> = ref([
|
|
|
+ { label: '商品规格', method: 'spec' },
|
|
|
+ { label: '修改', method: 'edit' },
|
|
|
+ { label: '删除', method: 'del', confirm: true, type: 'danger' }
|
|
|
+]);
|
|
|
+// 弹框
|
|
|
+const dialog: Ref<{ type: string; show: boolean; title: string }> = ref({ type: '1', show: false, title: '信息管理' });
|
|
|
+let form: Ref<{ file: Array<any> }> = ref({ file: [] });
|
|
|
+// 表单
|
|
|
+let formFields: Ref<any[]> = ref([
|
|
|
+ { label: '商品名称', model: 'name' },
|
|
|
+ { label: '销售数量', model: 'sell_num' },
|
|
|
+ { label: '供应商', model: 'supplier_id', type: 'select' },
|
|
|
+ { label: '类型', model: 'type', type: 'select' },
|
|
|
+ { label: '简介', model: 'brief', type: 'textarea' },
|
|
|
+ { label: '图片', model: 'file', custom: true },
|
|
|
+ { label: '是否使用', model: 'is_use', type: 'radio' }
|
|
|
+]);
|
|
|
+const rules = reactive<FormRules>({
|
|
|
+ name: [{ required: true, message: '商品名称', trigger: 'blur' }],
|
|
|
+ supplier_id: [{ required: true, message: '供应商', trigger: 'blur' }],
|
|
|
+ type: [{ required: true, message: '类型', trigger: 'blur' }]
|
|
|
+});
|
|
|
+// 查询数据
|
|
|
+let searchForm: Ref<any> = ref({});
|
|
|
+// 字典表
|
|
|
+let is_useList: Ref<any> = ref([]);
|
|
|
+let typeList: Ref<any> = ref([]);
|
|
|
+let supplierList: Ref<any> = ref([]);
|
|
|
onMounted(async () => {
|
|
|
loading.value = true;
|
|
|
- // await search({ skip, limit });
|
|
|
+ await searchOther();
|
|
|
+ await search({ skip, limit });
|
|
|
loading.value = false;
|
|
|
});
|
|
|
-//const search = async (e: { skip: number; limit: number }) => {
|
|
|
-// const info = { skip: e.skip, limit: e.limit, ...searchInfo.value };
|
|
|
-// const res: IQueryResult = await testAxios.query(info);
|
|
|
-// console.log(res);
|
|
|
-//};
|
|
|
+// 查询
|
|
|
+const search = async (e: { skip: number; limit: number }) => {
|
|
|
+ const { skip, limit } = e;
|
|
|
+ const condition = _.cloneDeep(searchForm.value);
|
|
|
+ let info = { limit: limit, skip: skip, ...condition };
|
|
|
+ let res: IQueryResult = await goodAxios.query(info);
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ list.value = res.data;
|
|
|
+ total.value = res.total;
|
|
|
+ }
|
|
|
+};
|
|
|
+const toSearch = (query: any) => {
|
|
|
+ searchForm.value = query;
|
|
|
+ search({ skip, limit });
|
|
|
+};
|
|
|
+const getDict = (value: any, model: any) => {
|
|
|
+ if (model == 'is_use') {
|
|
|
+ if (value) {
|
|
|
+ let data = is_useList.value.find((i: any) => i.value == value);
|
|
|
+ if (data) return data.label;
|
|
|
+ else return '暂无';
|
|
|
+ }
|
|
|
+ } else if (model == 'type') {
|
|
|
+ if (value) {
|
|
|
+ let data = typeList.value.find((i: any) => i.value == value);
|
|
|
+ if (data) return data.label;
|
|
|
+ else return '暂无';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (value) {
|
|
|
+ let data = supplierList.value.find((i: any) => i._id == value);
|
|
|
+ if (data) return data.name;
|
|
|
+ else return '暂无';
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+// 上传图片
|
|
|
+const onUpload = (e: { model: string; value: Array<[]> }) => {
|
|
|
+ const { model, value } = e;
|
|
|
+ form.value[model] = value;
|
|
|
+};
|
|
|
+// 商品规格
|
|
|
+const toSpec = (data: any) => {
|
|
|
+ router.push({ path: '/spec/index', query: { id: data._id } });
|
|
|
+};
|
|
|
+// 新增
|
|
|
+const toAdd = () => {
|
|
|
+ dialog.value = { title: '信息管理', show: true, type: '1' };
|
|
|
+};
|
|
|
+// 修改
|
|
|
+const toEdit = async (data: any) => {
|
|
|
+ let res: IQueryResult = await goodAxios.fetch(data._id);
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ form.value = res.data as { file: [] };
|
|
|
+ dialog.value = { title: '信息管理', show: true, type: '1' };
|
|
|
+ }
|
|
|
+};
|
|
|
+// 提交
|
|
|
+const onSubmit = async (data: any) => {
|
|
|
+ let res: IQueryResult;
|
|
|
+ if (data._id) res = await goodAxios.update(data);
|
|
|
+ else res = await goodAxios.create(data);
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ ElMessage({ type: `success`, message: `维护信息成功` });
|
|
|
+ toClose();
|
|
|
+ }
|
|
|
+};
|
|
|
+// 删除
|
|
|
+const toDel = async (data: any) => {
|
|
|
+ let res: IQueryResult = await goodAxios.del(data._id);
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ ElMessage({ type: `success`, message: `刪除信息成功` });
|
|
|
+ search({ skip, limit });
|
|
|
+ }
|
|
|
+};
|
|
|
+// 弹框关闭
|
|
|
+const toClose = () => {
|
|
|
+ form.value = { file: [] };
|
|
|
+ searchForm.value = {};
|
|
|
+ dialog.value = { title: '信息管理', show: false, type: '1' };
|
|
|
+ search({ skip, limit });
|
|
|
+};
|
|
|
+
|
|
|
+// 查询其他信息
|
|
|
+const searchOther = async () => {
|
|
|
+ let res: IQueryResult;
|
|
|
+ res = await dictAxios.query({ type: 'goods_type' });
|
|
|
+ if (res.errcode == 0) typeList.value = res.data;
|
|
|
+ res = await dictAxios.query({ type: 'is_use' });
|
|
|
+ if (res.errcode == 0) is_useList.value = res.data;
|
|
|
+ res = await userAxios.query({ role: 'cs', is_use: '0' });
|
|
|
+ if (res.errcode == 0) supplierList.value = res.data;
|
|
|
+};
|
|
|
</script>
|
|
|
-<style scoped lang="scss"></style>
|
|
|
+<style lang="scss" scoped>
|
|
|
+.main {
|
|
|
+ .two {
|
|
|
+ margin: 0 0 10px 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|