{"ast":null,"code":"import \"core-js/modules/es.array.splice.js\";\nimport \"core-js/modules/es.array.slice.js\";\nimport \"core-js/modules/es.function.name.js\";\nimport \"core-js/modules/es.string.trim.js\";\nimport \"core-js/modules/es.symbol.js\";\nimport \"core-js/modules/es.symbol.description.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//\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 baseApi: this.$store.state.baseApi,\n good: {\n discount: \"1\"\n },\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 if (this.standard.value == undefined || this.standard.value == \"\") {\n this.$message({\n type: \"error\",\n message: \"请输入规格名称\",\n showClose: true\n });\n return;\n }\n\n if (this.standard.price == undefined || this.standard.price == \"\") {\n this.$message({\n type: \"error\",\n message: \"请输入价格\",\n showClose: true\n });\n return;\n }\n\n if (this.standard.store == undefined || this.standard.store == \"\") {\n this.$message({\n type: \"error\",\n message: \"请输入库存\",\n showClose: true\n });\n return;\n }\n\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.good.name == undefined || this.good.name.trim() == \"\") {\n this.$message({\n type: \"error\",\n message: \"请输入商品名称\",\n showClose: true\n });\n return false;\n }\n\n if (this.good.description == undefined || this.good.description.trim() == \"\") {\n this.$message({\n type: \"error\",\n message: \"请输入商品描述\",\n showClose: true\n });\n return false;\n }\n\n if (this.standards.length === 0) {\n this.$message({\n type: \"error\",\n message: \"请至少添加一个规格\",\n showClose: true\n });\n return false;\n }\n\n console.log(this.good.discount);\n\n if (this.good.discount == undefined || this.good.discount === \"\") {\n this.$message({\n type: \"error\",\n message: \"请输入商品折扣\",\n showClose: true\n });\n return false;\n }\n\n if (this.good.categoryId == undefined) {\n this.$message({\n type: \"error\",\n message: \"请选择商品分类\",\n showClose: true\n });\n return false;\n }\n\n if (this.fileList.length === 0) {\n this.$message({\n type: \"error\",\n message: \"请上传图片\",\n showClose: true\n });\n return false;\n } // 先上传图片再保存数据\n\n\n if (this.fileList[0].status === \"ready\") {\n this.$refs.upload.submit();\n } else if (this.fileList[0].status === \"success\") {\n //没有修改初始的图片。直接保存数据\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 }\n });\n }\n }\n};","map":{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA;AACA;AACA;AACAA,kBADA;AAEAC,MAFA,kBAEA;AACA;AACAC,wCADA;AAEAC;AACAC;AADA,OAFA;AAKAC,mBALA;AAMAC,cANA;AAOAC,kBAPA;AAQAC,kBARA;AASAC,8BATA;AAUAC,uBAVA;AAWAC;AAXA;AAaA,GAhBA;AAiBAC,SAjBA,qBAiBA;AAAA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AAAAZ;AAAAa;AAAA;AACA,2EAHA,CAIA;;AACA;AACA;AACA;AACA;AACA,WAHA,MAGA,CACA;AACA;AACA,SAPA;AAQA;AACA,KAlBA;AAmBA,GArCA;AAsCAC;AACA;AACA;AACA;AACAC,gBAJA,wBAIAT,KAJA,EAIA;AACA;AACA;AACA;AACA,KARA;AASAU,eATA,yBASA;AACA;AACA;AACA;AACA,KAbA;AAcAC,gBAdA,0BAcA;AACA;AAEA;AACAC,uBADA;AAEAC,4BAFA;AAGAC;AAHA;AAKA;AACA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AACA,OA3BA;AA4BA;AA5JA;AAtCA","names":["name","data","baseApi","good","discount","standards","index","standard","fileList","dialogFormVisible","categoryItems","checkedCategory","created","url","methods","editStandard","addStandard","saveStandard","type","message","showClose","handleClose","handleImgSuccess","res","handleChange","file","handleRemove","submit","console","save","API","post","then"],"sourceRoot":"src/views/manage/good","sources":["GoodInfo.vue"],"sourcesContent":["\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n {{ standard.value }}\r\n \r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n 选取文件\r\n \r\n 只能上传一个jpg/png文件,且不超过500kb\r\n \r\n \r\n \r\n \r\n 提交\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n"]},"metadata":{},"sourceType":"module"}