1 line
12 KiB
JSON
1 line
12 KiB
JSON
|
{"ast":null,"code":"import \"core-js/modules/es.array.splice.js\";\nimport \"core-js/modules/es.array.slice.js\";\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\nimport API from \"@/utils/request\";\nvar url = \"/api/good\";\nexport default {\n name: \"GoodInfo\",\n data: function data() {\n return {\n good: {},\n standards: [],\n index: 0,\n standard: {},\n fileList: [],\n dialogFormVisible: false,\n categoryItems: [],\n checkedCategory: {}\n };\n },\n created: function created() {\n var _this = this;\n\n this.request.get(\"/api/category\").then(function (res) {\n if (res.code === '200') {\n _this.categoryItems = res.data;\n }\n\n if (_this.$route.query.good) {\n _this.good = JSON.parse(_this.$route.query.good);\n _this.fileList = [{\n name: '原始图片',\n url: 'this.good.imgs'\n }];\n _this.checkedCategory = _this.categoryItems[_this.good.categoryId]; //从服务器获取商品规格信息\n\n _this.request.get(url + \"/standard/\" + _this.good.id).then(function (res) {\n if (res.code === '200') {\n var standards = JSON.parse(res.data);\n _this.standards = standards;\n } else {//没有规格\n }\n });\n }\n });\n },\n methods: {\n /*\r\n 规格操作\r\n */\n editStandard: function editStandard(index) {\n this.standard = this.standards[index];\n this.index = index;\n this.dialogFormVisible = true;\n },\n addStandard: function addStandard() {\n this.standard = {};\n this.index = this.standards.length;\n this.dialogFormVisible = true;\n },\n saveStandard: function saveStandard() {\n this.standards[this.index] = this.standard;\n this.dialogFormVisible = false;\n },\n handleClose: function handleClose(standard) {\n this.standards.splice(this.standards.indexOf(standard), 1);\n },\n\n /*\r\n 文件上传操作\r\n */\n handleImgSuccess: function handleImgSuccess(res) {\n this.good.imgs = res.data;\n this.save();\n },\n handleChange: function handleChange(file, fileList) {\n this.fileList = fileList.slice(-3);\n },\n handleRemove: function handleRemove() {\n this.fileList.pop();\n },\n\n /*\r\n 保存数据操作\r\n */\n //点击提交按钮\n submit: function submit() {\n if (this.fileList.length === 0) {\n this.$confirm(\"请上传图片\");\n return false;\n } // 先上传图片再保存数据\n\n\n if (this.fileList[0].status === 'ready') {\n console.log('上传中');\n console.log(this.fileList);\n this.$refs.upload.submit();\n } //没有修改初始的图片。直接保存数据\n else if (this.fileList[0].status === 'success') {\n this.save();\n }\n },\n //保存数据\n save: function save() {\n var _this2 = this;\n\n API.post(url, this.good).then(function (res2) {\n if (res2.code === '200') {\n _this2.good.id = res2.data;\n\n _this2.request.post(url + \"/standard?goodId=\" + _this2.good.id, _this2.standards).then(function (res) {\n if (res.code === '200') {\n _this2.$message({\n type: \"success\",\n message: \"操作成功\",\n showClose: true\n });\n\n _this2.$router.go(-1);\n } else {\n _this2.$message({\n type: \"error\",\n message: \"操作失败\",\n showClose: true\n });\n }\n });\n } else {\n _this2.$message({\n type: \"error\",\n message: res2.msg\n });\n
|