{"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//\nimport API from \"@/utils/request\";\nexport default {\n name: \"GoodView\",\n data: function data() {\n return {\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 _this2.$router.go(0);\n }\n }); //从服务器获取商品规格信息\n\n this.request.get(\"/api/good/standard/\" + this.goodId).then(function (res) {\n if (res.code === '200') {\n var standards = JSON.parse(res.data);\n _this2.standards = standards; //默认选择第一个标准\n\n _this2.price = _this2.getPriceRange(standards);\n } else {\n //没有规格\n _this2.price = _this2.good.price;\n _this2.store = _this2.good.store;\n _this2.showStore = true;\n }\n });\n },\n mounted: function mounted() {},\n computed: {\n //折后价,小数点后2位\n realPrice: function realPrice() {\n if (this.good.discount < 1) {\n //价格为范围,即不是数字,则返回一个范围\n if (isNaN(this.price)) {\n var down = this.price.substring(0, this.price.indexOf('元')) * this.good.discount;\n var up = this.price.substring(this.price.lastIndexOf(' ')) * this.good.discount;\n return down.toFixed(2) + \"元 ~ \" + up.toFixed(2);\n } else {\n return (this.price * this.good.discount).toFixed(2);\n }\n }\n\n return this.price;\n }\n }\n};","map":{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA;AAEA;AACAA,kBADA;AAEAC,MAFA,kBAEA;AACA;AACAC,cADA;AAEAC,oBAFA;AAGAC,eAHA;AAIAC,uBAJA;AAKAC,kBALA;AAMAC,mBANA;AAOAC,yBAPA;AAQAC,cARA;AASAC,sBATA;AAUAC;AAVA;AAYA,GAfA;AAgBAC;AACAC,iBADA,yBACAN,SADA,EACA;AACA;AAAA;AAAA,SADA,CAEA;;AACA;AACA;AACA;;AACA;AACA;AACA;AACAO;AACA;AACA;;AARA,mBASA,kBATA;AASAC,cATA;AASAA,gBATA;AAUA;;AACA;AACA;AACA,OAFA,MAEA;AACA;AACA;AACA,KApBA;AAqBAC,UArBA,kBAqBAC,QArBA,EAqBA;AACA;AACA;AACA;AACA,KAzBA;AA0BAC,aA1BA,uBA0BA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAC;AACAA;AACA;AAAAnB;AAAAoB;AAAAlB;AAAAmB;AAAAC;AAAAL;AAAA;AAAA;AACA,KApCA;AAqCAM,aArCA,uBAqCA;AAAA;;AACA;AACAJ;;AACA;AACA;AACA;;AACA;AACA;AACA;AACA,OATA,CAUA;;;AACA;AACA;AACA;AAAAK;AAAArB;AAAAc;AAAAN;AAAA;;AACA;AACA;AACA;AACA;AACA,SAJA;AAKA,OARA;AASA;AAzDA,GAhBA;AA4EAc,SA5EA,qBA4EA;AAAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA,OAPA,MAOA;AACA;AACA;AACA,KAXA,EAJA,CAgBA;;AACA;AACA;AACA;AACA,qCAFA,CAGA;;AACA;AACA,OALA,MAKA;AACA;AACA;AACA;AACA;AACA;AACA,KAZA;AAgBA,GA7GA;AA8GAC,SA9GA,qBA8GA,CAEA,CAhHA;AAiHAC;AACA;AACAN;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAJA,MAIA;AACA;AAEA;AACA;;AACA;AACA;AAfA;AAjHA","names":["name","data","good","goodId","price","isDiscount","discount","standards","checkedStandard","store","showStore","count","methods","getPriceRange","min","arr","change","standard","goToOrder","console","query","realPrice","num","addToCart","userId","created","mounted","computed"],"sourceRoot":"src/views/front/good","sources":["GoodView.vue"],"sourcesContent":["\r\n\r\n\r\n\r\n"]},"metadata":{},"sourceType":"module"}