1 line
19 KiB
JSON
1 line
19 KiB
JSON
|
{"ast":null,"code":"import \"core-js/modules/es.number.constructor.js\";\nimport \"core-js/modules/es.array.map.js\";\nimport \"core-js/modules/es.json.stringify.js\";\nimport \"core-js/modules/es.number.to-fixed.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//\n//\nimport API from \"@/utils/request\";\nexport default {\n name: \"GoodView\",\n data: function data() {\n return {\n baseApi: this.$store.state.baseApi,\n good: {},\n goodId: Number,\n price: -1,\n isDiscount: false,\n discount: \"\",\n standards: [],\n checkedStandard: \"\",\n store: 0,\n showStore: false,\n count: 1\n };\n },\n methods: {\n getPriceRange: function getPriceRange(standards) {\n var arr = standards.map(function (item) {\n return item.price;\n }); //选择排序\n\n for (var i = 0; i < arr.length; i++) {\n // 第一次循环,假设第一个值为最小值,后面i++依此类推\n var min = i;\n\n for (var j = i + 1; j < arr.length; j++) {\n // 将第一个值循环与后面的值比较,如果后面的值比第一个值小,则将索引赋值给min,直到找到最小值\n if (arr[j] < arr[min]) {\n min = j;\n }\n }\n\n var _ref = [arr[min], arr[i]];\n arr[i] = _ref[0];\n arr[min] = _ref[1];\n }\n\n if (arr[0] === arr[arr.length - 1]) {\n return arr[0];\n } else {\n return arr[0] + \"元 ~ \" + arr[arr.length - 1];\n }\n },\n change: function change(standard) {\n this.showStore = true;\n this.price = standard.price;\n this.store = standard.store;\n },\n goToOrder: function goToOrder() {\n if (this.standards.length !== 0) {\n if (this.checkedStandard === \"\") {\n this.$message.warning(\"请选择规格\");\n return false;\n }\n }\n\n console.log(this.good);\n console.log(this.checkedStandard);\n this.$router.push({\n name: \"preOrder\",\n query: {\n good: JSON.stringify(this.good),\n realPrice: this.realPrice,\n num: this.count,\n standard: this.checkedStandard\n }\n });\n },\n addToCart: function addToCart() {\n var _this = this;\n\n //未登录,拦截\n console.log(localStorage.getItem(\"user\"));\n\n if (!localStorage.getItem(\"user\")) {\n this.$router.push(\"/login\");\n }\n\n if (!this.checkedStandard) {\n this.$message.error(\"请选择规格\");\n return false;\n } // 从服务器获取当前用户的id,保证安全\n\n\n this.request.get(\"/userid\").then(function (res) {\n var userId = res;\n var cart = {\n userId: userId,\n goodId: _this.goodId,\n standard: _this.checkedStandard,\n count: _this.count\n };\n\n _this.request.post(\"/api/cart\", cart).then(function (res) {\n if (res.code === \"200\") {\n _this.$message.success(\"成功添加购物车\");\n }\n });\n });\n }\n },\n created: function created() {\n var _this2 = this;\n\n //初始化商品信息\n // this.good = JSON.parse(this.$route.query.good)\n this.goodId = this.$route.params.goodId;\n this.request.get(\"/api/good/\" + this.goodId).then(function (res) {\n if (res.code === \"200\") {\n _this2.good = res.data;\n var discount = _this2.good.discount;\n\n if (discount < 1) {\n _this2.isDiscount = true;\n _this2.discount = discount * 10 + \"折\";\n }\n } else {\n _th
|