You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
19 KiB
1 line
19 KiB
{"ast":null,"code":"import E from 'wangeditor';\nlet editor;\nfunction initWangEditor(content) {\n setTimeout(() => {\n if (!editor) {\n editor = new E('#editor');\n editor.config.placeholder = '请输入内容';\n editor.config.uploadFileName = 'file';\n editor.config.uploadImgServer = 'http://localhost:9090/files/wang/upload';\n editor.create();\n }\n editor.txt.html(content);\n }, 0);\n}\nexport default {\n name: \"Notice\",\n data() {\n return {\n tableData: [],\n // 所有的数据\n pageNum: 1,\n // 当前的页码\n pageSize: 10,\n // 每页显示的个数\n total: 0,\n name: null,\n fromVisible: false,\n editorVisible: false,\n form: {},\n user: JSON.parse(localStorage.getItem('xm-user') || '{}'),\n rules: {\n title: [{\n required: true,\n message: '请输入商品名称',\n trigger: 'blur'\n }],\n content: [{\n required: true,\n message: '请输上传商品主图',\n trigger: 'blur'\n }]\n },\n ids: [],\n typeData: [],\n viewData: null\n };\n },\n created() {\n this.load(1);\n this.loadType();\n },\n methods: {\n loadType() {\n this.$request.get('/type/selectAll').then(res => {\n if (res.code === '200') {\n this.typeData = res.data;\n } else {\n this.$message.error(res.msg);\n }\n });\n },\n handleAdd() {\n // 新增数据\n if ('审核通过' !== this.user.status) {\n this.$message.warning('您的店铺信息还未审核通过,暂时不允许发布商品');\n return;\n }\n this.form = {}; // 新增数据的时候清空数据\n initWangEditor('');\n this.fromVisible = true; // 打开弹窗\n },\n\n handleEdit(row) {\n // 编辑数据\n this.form = JSON.parse(JSON.stringify(row)); // 深拷贝数据\n initWangEditor(this.form.description || '');\n this.fromVisible = true; // 打开弹窗\n },\n\n viewEditor(content) {\n this.viewData = content;\n this.editorVisible = true;\n },\n cancel() {\n this.fromVisible = false;\n location.href = '/goods';\n },\n save() {\n // 保存按钮触发的逻辑\n this.$refs.formRef.validate(valid => {\n if (valid) {\n this.form.description = editor.txt.html();\n this.$request({\n url: this.form.id ? '/goods/update' : '/goods/add',\n method: this.form.id ? 'PUT' : 'POST',\n data: this.form\n }).then(res => {\n if (res.code === '200') {\n // 表示成功保存\n this.$message.success('保存成功');\n this.fromVisible = false;\n location.href = '/goods';\n } else {\n this.$message.error(res.msg); // 弹出错误的信息\n }\n });\n }\n });\n },\n\n del(id) {\n // 单个删除\n this.$confirm('您确定删除吗?', '确认删除', {\n type: \"warning\"\n }).then(() => {\n this.$request.delete('/goods/delete/' + id).then(res => {\n if (res.code === '200') {\n // 表示操作成功\n this.$message.success('操作成功');\n this.load(1);\n } else {\n this.$message.error(res.msg); // 弹出错误的信息\n }\n });\n }).catch(() => {});\n },\n handleSelectionChange(rows) {\n // 当前选中的所有的行数据\n this.ids = rows.map(v => v.id);\n },\n delBatch() {\n // 批量删除\n if (!this.ids.length) {\n this.$message.warning('请选择数据');\n return;\n }\n this.$confirm('您确定批量删除这些数据吗?', '确认删除', {\n type: \"warning\"\n }).then(() => {\n this.$request.delete('/goods/delete/batch', {\n data: this.ids\n }).then(res => {\n if (res.code === '200') {\n // 表示操作成功\n this.$message.success('操作成功');\n this.load(1);\n } else {\n this.$message.error(res.msg); // 弹出错误的信息\n }\n });\n }).catch(() => {});\n },\n load(pageNum) {\n // 分页查询\n if (pageNum) this.pageNum = pageNum;\n this.$request.get('/goods/selectPage', {\n params: {\n pageNum: this.pageNum,\n pageSize: this.pageSize,\n name: this.name\n }\n }).then(res => {\n this.tableData = res.data?.list;\n this.total = res.data?.total;\n });\n },\n reset() {\n this.name = null;\n this.load(1);\n },\n handleCurrentChange(pageNum) {\n this.load(pageNum);\n },\n handleAvatarSuccess(response, file, fileList) {\n this.form.img = response.data;\n }\n }\n};","map":{"version":3,"names":["E","editor","initWangEditor","content","setTimeout","config","placeholder","uploadFileName","uploadImgServer","create","txt","html","name","data","tableData","pageNum","pageSize","total","fromVisible","editorVisible","form","user","JSON","parse","localStorage","getItem","rules","title","required","message","trigger","ids","typeData","viewData","created","load","loadType","methods","$request","get","then","res","code","$message","error","msg","handleAdd","status","warning","handleEdit","row","stringify","description","viewEditor","cancel","location","href","save","$refs","formRef","validate","valid","url","id","method","success","del","$confirm","type","delete","catch","handleSelectionChange","rows","map","v","delBatch","length","params","list","reset","handleCurrentChange","handleAvatarSuccess","response","file","fileList","img"],"sources":["src/views/manager/Goods.vue"],"sourcesContent":["<template>\r\n <div>\r\n <div class=\"search\">\r\n <el-input placeholder=\"请输入商品名称查询\" style=\"width: 200px\" v-model=\"name\"></el-input>\r\n <el-button type=\"info\" plain style=\"margin-left: 10px\" @click=\"load(1)\">查询</el-button>\r\n <el-button type=\"warning\" plain style=\"margin-left: 10px\" @click=\"reset\">重置</el-button>\r\n </div>\r\n\r\n <div class=\"operation\">\r\n <!-- 只有角色为商户的用户可以看到“发布商品”按钮 -->\r\n <el-button v-if=\"role === 'business'\" type=\"primary\" plain @click=\"handleAdd\">发布商品</el-button>\r\n <el-button type=\"danger\" plain @click=\"delBatch\">批量删除</el-button>\r\n </div>\r\n\r\n <div class=\"table\">\r\n <el-table :data=\"tableData\" stripe @selection-change=\"handleSelectionChange\">\r\n <el-table-column type=\"selection\" width=\"55\" align=\"center\"></el-table-column>\r\n <el-table-column prop=\"id\" label=\"序号\" width=\"80\" align=\"center\" sortable></el-table-column>\r\n <el-table-column label=\"商品主图\">\r\n <template v-slot=\"scope\">\r\n <div style=\"display: flex; align-items: center\">\r\n <el-image style=\"width: 40px; height: 40px;\" v-if=\"scope.row.img\" :src=\"scope.row.img\" :preview-src-list=\"[scope.row.img]\"></el-image>\r\n </div>\r\n </template>\r\n </el-table-column>\r\n <el-table-column prop=\"name\" label=\"商品名称\" show-overflow-tooltip></el-table-column>\r\n <el-table-column prop=\"description\" label=\"商品描述\">\r\n <template slot-scope=\"scope\">\r\n <el-button type=\"success\" @click=\"viewEditor(scope.row.description)\">点击查看</el-button>\r\n </template>\r\n </el-table-column>\r\n <el-table-column prop=\"price\" label=\"商品价格\" show-overflow-tooltip></el-table-column>\r\n <el-table-column prop=\"unit\" label=\"计件单位\" show-overflow-tooltip></el-table-column>\r\n <el-table-column prop=\"typeName\" label=\"商品分类\" show-overflow-tooltip></el-table-column>\r\n <el-table-column prop=\"businessName\" label=\"所属商家\" show-overflow-tooltip></el-table-column>\r\n <el-table-column prop=\"count\" label=\"商品销量\" show-overflow-tooltip></el-table-column>\r\n <el-table-column label=\"操作\" width=\"180\" align=\"center\">\r\n <template v-slot=\"scope\">\r\n <el-button plain type=\"primary\" @click=\"handleEdit(scope.row)\" size=\"mini\">编辑</el-button>\r\n <el-button plain type=\"danger\" size=\"mini\" @click=\"del(scope.row.id)\">删除</el-button>\r\n </template>\r\n </el-table-column>\r\n </el-table>\r\n\r\n <div class=\"pagination\">\r\n <el-pagination\r\n background\r\n @current-change=\"handleCurrentChange\"\r\n :current-page=\"pageNum\"\r\n :page-sizes=\"[5, 10, 20]\"\r\n :page-size=\"pageSize\"\r\n layout=\"total, prev, pager, next\"\r\n :total=\"total\">\r\n </el-pagination>\r\n </div>\r\n </div>\r\n\r\n <el-dialog title=\"信息\" :visible.sync=\"fromVisible\" width=\"40%\" :close-on-click-modal=\"false\" destroy-on-close @close=\"cancel\">\r\n <el-form label-width=\"100px\" style=\"padding-right: 50px\" :model=\"form\" :rules=\"rules\" ref=\"formRef\">\r\n <el-form-item label=\"商品主图\">\r\n <el-upload\r\n class=\"avatar-uploader\"\r\n :action=\"$baseUrl + '/files/upload'\"\r\n :headers=\"{ token: user.token }\"\r\n list-type=\"picture\"\r\n :on-success=\"handleAvatarSuccess\">\r\n <el-button type=\"primary\">上传图片</el-button>\r\n </el-upload>\r\n </el-form-item>\r\n <el-form-item prop=\"name\" label=\"商品名称\">\r\n <el-input v-model=\"form.name\" autocomplete=\"off\"></el-input>\r\n </el-form-item>\r\n <el-form-item prop=\"price\" label=\"商品价格\">\r\n <el-input v-model=\"form.price\" autocomplete=\"off\"></el-input>\r\n </el-form-item>\r\n <el-form-item prop=\"typeId\" label=\"商品分类\">\r\n <el-select v-model=\"form.typeId\" placeholder=\"请选择分类\" style=\"width: 100%\">\r\n <el-option v-for=\"item in typeData\" :label=\"item.name\" :value=\"item.id\" :key=\"item.id\"></el-option>\r\n </el-select>\r\n </el-form-item>\r\n <el-form-item prop=\"unit\" label=\"计件单位\">\r\n <el-input v-model=\"form.unit\" autocomplete=\"off\"></el-input>\r\n </el-form-item>\r\n <el-form-item prop=\"description\" label=\"商品介绍\">\r\n <div id=\"editor\" style=\"width: 100%\"></div>\r\n </el-form-item>\r\n </el-form>\r\n <div slot=\"footer\" class=\"dialog-footer\">\r\n <el-button @click=\"cancel\">取 消</el-button>\r\n <el-button type=\"primary\" @click=\"save\">确 定</el-button>\r\n </div>\r\n </el-dialog>\r\n\r\n <el-dialog title=\"商品介绍\" :visible.sync=\"editorVisible\" width=\"50%\">\r\n <div v-html=\"viewData\" class=\"w-e-text\"></div>\r\n </el-dialog>\r\n </div>\r\n</template>\r\n\r\n<script>\r\nimport E from 'wangeditor';\r\n\r\nlet editor;\r\nfunction initWangEditor(content) {\r\n setTimeout(() => {\r\n if (!editor) {\r\n editor = new E('#editor');\r\n editor.config.placeholder = '请输入内容';\r\n editor.config.uploadFileName = 'file';\r\n editor.config.uploadImgServer = 'http://localhost:9090/files/wang/upload';\r\n editor.create();\r\n }\r\n editor.txt.html(content);\r\n }, 0);\r\n}\r\n\r\nexport default {\r\n name: \"Notice\",\r\n data() {\r\n return {\r\n tableData: [], // 所有的数据\r\n pageNum: 1, // 当前的页码\r\n pageSize: 10, // 每页显示的个数\r\n total: 0,\r\n name: null,\r\n fromVisible: false,\r\n editorVisible: false,\r\n form: {},\r\n user: JSON.parse(localStorage.getItem('xm-user') || '{}'),\r\n rules: {\r\n title: [\r\n { required: true, message: '请输入商品名称', trigger: 'blur' },\r\n ],\r\n content: [\r\n { required: true, message: '请输上传商品主图', trigger: 'blur' },\r\n ]\r\n },\r\n ids: [],\r\n typeData: [],\r\n viewData: null,\r\n };\r\n },\r\n created() {\r\n this.load(1);\r\n this.loadType();\r\n },\r\n methods: {\r\n loadType() {\r\n this.$request.get('/type/selectAll').then(res => {\r\n if (res.code === '200') {\r\n this.typeData = res.data;\r\n } else {\r\n this.$message.error(res.msg);\r\n }\r\n });\r\n },\r\n handleAdd() { // 新增数据\r\n if ('审核通过' !== this.user.status) {\r\n this.$message.warning('您的店铺信息还未审核通过,暂时不允许发布商品');\r\n return;\r\n }\r\n this.form = {}; // 新增数据的时候清空数据\r\n initWangEditor('');\r\n this.fromVisible = true; // 打开弹窗\r\n },\r\n handleEdit(row) { // 编辑数据\r\n this.form = JSON.parse(JSON.stringify(row)); // 深拷贝数据\r\n initWangEditor(this.form.description || '');\r\n this.fromVisible = true; // 打开弹窗\r\n },\r\n viewEditor(content) {\r\n this.viewData = content;\r\n this.editorVisible = true;\r\n },\r\n cancel() {\r\n this.fromVisible = false;\r\n location.href = '/goods';\r\n },\r\n save() { // 保存按钮触发的逻辑\r\n this.$refs.formRef.validate((valid) => {\r\n if (valid) {\r\n this.form.description = editor.txt.html();\r\n this.$request({\r\n url: this.form.id ? '/goods/update' : '/goods/add',\r\n method: this.form.id ? 'PUT' : 'POST',\r\n data: this.form\r\n }).then(res => {\r\n if (res.code === '200') { // 表示成功保存\r\n this.$message.success('保存成功');\r\n this.fromVisible = false;\r\n location.href = '/goods';\r\n } else {\r\n this.$message.error(res.msg); // 弹出错误的信息\r\n }\r\n });\r\n }\r\n });\r\n },\r\n del(id) { // 单个删除\r\n this.$confirm('您确定删除吗?', '确认删除', { type: \"warning\" }).then(() => {\r\n this.$request.delete('/goods/delete/' + id).then(res => {\r\n if (res.code === '200') { // 表示操作成功\r\n this.$message.success('操作成功');\r\n this.load(1);\r\n } else {\r\n this.$message.error(res.msg); // 弹出错误的信息\r\n }\r\n });\r\n }).catch(() => {});\r\n },\r\n handleSelectionChange(rows) { // 当前选中的所有的行数据\r\n this.ids = rows.map(v => v.id);\r\n },\r\n delBatch() { // 批量删除\r\n if (!this.ids.length) {\r\n this.$message.warning('请选择数据');\r\n return;\r\n }\r\n this.$confirm('您确定批量删除这些数据吗?', '确认删除', { type: \"warning\" }).then(() => {\r\n this.$request.delete('/goods/delete/batch', { data: this.ids }).then(res => {\r\n if (res.code === '200') { // 表示操作成功\r\n this.$message.success('操作成功');\r\n this.load(1);\r\n } else {\r\n this.$message.error(res.msg); // 弹出错误的信息\r\n }\r\n });\r\n }).catch(() => {});\r\n },\r\n load(pageNum) { // 分页查询\r\n if (pageNum) this.pageNum = pageNum;\r\n this.$request.get('/goods/selectPage', {\r\n params: {\r\n pageNum: this.pageNum,\r\n pageSize: this.pageSize,\r\n name: this.name,\r\n }\r\n }).then(res => {\r\n this.tableData = res.data?.list;\r\n this.total = res.data?.total;\r\n });\r\n },\r\n reset() {\r\n this.name = null;\r\n this.load(1);\r\n },\r\n handleCurrentChange(pageNum) {\r\n this.load(pageNum);\r\n },\r\n handleAvatarSuccess(response, file, fileList) {\r\n this.form.img = response.data;\r\n },\r\n }\r\n};\r\n</script>\r\n\r\n<style scoped>\r\n/* Add any necessary scoped styles here */\r\n</style>"],"mappings":"AAoGA,OAAAA,CAAA;AAEA,IAAAC,MAAA;AACA,SAAAC,eAAAC,OAAA;EACAC,UAAA;IACA,KAAAH,MAAA;MACAA,MAAA,OAAAD,CAAA;MACAC,MAAA,CAAAI,MAAA,CAAAC,WAAA;MACAL,MAAA,CAAAI,MAAA,CAAAE,cAAA;MACAN,MAAA,CAAAI,MAAA,CAAAG,eAAA;MACAP,MAAA,CAAAQ,MAAA;IACA;IACAR,MAAA,CAAAS,GAAA,CAAAC,IAAA,CAAAR,OAAA;EACA;AACA;AAEA;EACAS,IAAA;EACAC,KAAA;IACA;MACAC,SAAA;MAAA;MACAC,OAAA;MAAA;MACAC,QAAA;MAAA;MACAC,KAAA;MACAL,IAAA;MACAM,WAAA;MACAC,aAAA;MACAC,IAAA;MACAC,IAAA,EAAAC,IAAA,CAAAC,KAAA,CAAAC,YAAA,CAAAC,OAAA;MACAC,KAAA;QACAC,KAAA,GACA;UAAAC,QAAA;UAAAC,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