|
|
@@ -1,21 +1,103 @@
|
|
|
|
|
|
const NULL_ARR = ['空', '没', '无', '-', '—', 'null', '#N/A']
|
|
|
|
|
|
-// 获取字符串字符长度
|
|
|
-const getRealLength = function (str) {
|
|
|
- let len = 0
|
|
|
- for (let i = 0; i < str.length; i++) {
|
|
|
- if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
|
- len += 2
|
|
|
- } else {
|
|
|
- len++
|
|
|
+// 立即购买或加入购物车
|
|
|
+/*
|
|
|
+ * isBuy: 是否是立即购买
|
|
|
+ * event: 触发事件
|
|
|
+ * $this: 当前对象
|
|
|
+ * item: 操作对象
|
|
|
+ * */
|
|
|
+const _buyNow = function (isBuy, event, $this, item) {
|
|
|
+ if (event) event.stopPropagation()
|
|
|
+ if (!$this.$store.state.option.user.logged) {
|
|
|
+ $this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
|
|
|
+ if (response.data) {
|
|
|
+ window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ if (item && !$this.disabledFlag) {
|
|
|
+ if (isBuy) {
|
|
|
+ $this.$http.post('/trade/order/buyNow', [{
|
|
|
+ uuid: item.uuid,
|
|
|
+ batchCode: item.batchCode,
|
|
|
+ number: item.minBuyQty,
|
|
|
+ storeid: item.storeid ? item.storeid : item.storeId,
|
|
|
+ storeUuid: item.storeid ? item.storeid : item.storeId,
|
|
|
+ currencyName: item.currencyName,
|
|
|
+ minPackQty: item.minPackQty
|
|
|
+ }])
|
|
|
+ .then(response => {
|
|
|
+ // window.location.href = '/user#/order/pay/' + $this.enidfilter(response.data.orderid)
|
|
|
+ if (response.data.success) {
|
|
|
+ if (response.data.message) {
|
|
|
+ $this.$message({
|
|
|
+ message: response.data.message,
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ window.setTimeout(function () {
|
|
|
+ window.location.href = '/user#/order/pay/' + _enidfilter(response.data.data.orderid)
|
|
|
+ }, 1000)
|
|
|
+ } else {
|
|
|
+ window.location.href = '/user#/order/pay/' + _enidfilter(response.data.data.orderid)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (response.data.data && response.data.data.unvailable === 1) {
|
|
|
+ $this.$message.error('产品信息已失效,请刷新页面')
|
|
|
+ } else {
|
|
|
+ $this.$message.error(response.data.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, err => {
|
|
|
+ console.log(err)
|
|
|
+ if (item.minBuyQty > item.reserve) {
|
|
|
+ $this.$message.error('商品' + item.code + '的库存已经不满足起订量')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // $this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
|
|
|
+ $this.$http.post('/trade/cart/add', {
|
|
|
+ uuid: item.uuid,
|
|
|
+ batchCode: item.batchCode,
|
|
|
+ number: item.minBuyQty,
|
|
|
+ storeid: item.storeid ? item.storeid : item.storeId,
|
|
|
+ storeUuid: item.storeid ? item.storeid : item.storeId,
|
|
|
+ currencyName: item.currencyName,
|
|
|
+ minPackQty: item.minPackQty
|
|
|
+ })
|
|
|
+ .then(response => {
|
|
|
+ if (response.data.success) {
|
|
|
+ if (response.data.message) {
|
|
|
+ $this.$message({
|
|
|
+ message: '添加购物车成功,但商品信息有更新',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ $this.$message({
|
|
|
+ message: '添加购物车成功',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // if (response.data.code === 2) {
|
|
|
+ // $this.$message.error('库存已不满足起订量')
|
|
|
+ // } else
|
|
|
+ if (response.data.message === '该产品已失效') {
|
|
|
+ $this.$message.error(response.data.message + ',请刷新页面')
|
|
|
+ } else {
|
|
|
+ $this.$message.error(response.data.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return len
|
|
|
+ // window.location.href = 'user#/order/pay/' + $this.enidfilter($this.buy_info.orderid)
|
|
|
}
|
|
|
|
|
|
// 订单号转换
|
|
|
-export const enidfilter = (str) => {
|
|
|
+const _enidfilter = (str) => {
|
|
|
if (str) {
|
|
|
let encryptStr = '' // 最终返回的加密后的字符串
|
|
|
// 产生三位随机数
|
|
|
@@ -84,12 +166,23 @@ export const enidfilter = (str) => {
|
|
|
}
|
|
|
|
|
|
// 获取字符串字符长度
|
|
|
-export const getRealLen = getRealLength
|
|
|
+const _getRealLen = function (str) {
|
|
|
+ let len = 0
|
|
|
+ for (let i = 0; i < str.length; i++) {
|
|
|
+ if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
|
+ len += 2
|
|
|
+ } else {
|
|
|
+ len++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return len
|
|
|
+}
|
|
|
|
|
|
-// 根据字符长度剪切字符
|
|
|
-export const cutOutString = (str, length) => {
|
|
|
+export const enidfilter = _enidfilter
|
|
|
+
|
|
|
+const _cutOutString = (str, length) => {
|
|
|
for (let i = 1; i <= str.length; i++) {
|
|
|
- if (getRealLength(str.substr(0, i)) > length) {
|
|
|
+ if (_getRealLen(str.substr(0, i)) > length) {
|
|
|
str = str.substr(0, i - 1)
|
|
|
break
|
|
|
}
|
|
|
@@ -97,10 +190,16 @@ export const cutOutString = (str, length) => {
|
|
|
return str
|
|
|
}
|
|
|
|
|
|
+// 获取字符串字符长度
|
|
|
+export const getRealLen = _getRealLen
|
|
|
+
|
|
|
+// 根据字符长度剪切字符
|
|
|
+export const cutOutString = _cutOutString
|
|
|
+
|
|
|
// 根据字符长度剪切字符
|
|
|
export const spliceStr = (str, length) => {
|
|
|
for (let i = 1; i <= str.length; i++) {
|
|
|
- if (getRealLength(str.substr(0, i)) > length) {
|
|
|
+ if (_getRealLen(str.substr(0, i)) > length) {
|
|
|
str = str.substr(0, i - 1) + '...'
|
|
|
break
|
|
|
}
|
|
|
@@ -227,99 +326,9 @@ export function whichTransitionEvent() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-// 立即购买或加入购物车
|
|
|
-/*
|
|
|
- * isBuy: 是否是立即购买
|
|
|
- * event: 触发事件
|
|
|
- * $this: 当前对象
|
|
|
- * item: 操作对象
|
|
|
- * */
|
|
|
-const buyNow = function (isBuy, event, $this, item) {
|
|
|
- if (event) event.stopPropagation()
|
|
|
- if (!$this.$store.state.option.user.logged) {
|
|
|
- $this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
|
|
|
- if (response.data) {
|
|
|
- window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- if (item && !$this.disabledFlag) {
|
|
|
- if (isBuy) {
|
|
|
- $this.$http.post('/trade/order/buyNow', [{
|
|
|
- uuid: item.uuid,
|
|
|
- batchCode: item.batchCode,
|
|
|
- number: item.minBuyQty,
|
|
|
- storeid: item.storeid ? item.storeid : item.storeId,
|
|
|
- storeUuid: item.storeid ? item.storeid : item.storeId,
|
|
|
- currencyName: item.currencyName,
|
|
|
- minPackQty: item.minPackQty
|
|
|
- }])
|
|
|
- .then(response => {
|
|
|
- // window.location.href = '/user#/order/pay/' + $this.enidfilter(response.data.orderid)
|
|
|
- if (response.data.success) {
|
|
|
- if (response.data.message) {
|
|
|
- $this.$message({
|
|
|
- message: response.data.message,
|
|
|
- type: 'success'
|
|
|
- })
|
|
|
- window.setTimeout(function () {
|
|
|
- window.location.href = '/user#/order/pay/' + enidfilter(response.data.data.orderid)
|
|
|
- }, 1000)
|
|
|
- } else {
|
|
|
- window.location.href = '/user#/order/pay/' + enidfilter(response.data.data.orderid)
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (response.data.data && response.data.data.unvailable === 1) {
|
|
|
- $this.$message.error('产品信息已失效,请刷新页面')
|
|
|
- } else {
|
|
|
- $this.$message.error(response.data.message)
|
|
|
- }
|
|
|
- }
|
|
|
- }, err => {
|
|
|
- console.log(err)
|
|
|
- if (item.minBuyQty > item.reserve) {
|
|
|
- $this.$message.error('商品' + item.code + '的库存已经不满足起订量')
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- // $this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
|
|
|
- $this.$http.post('/trade/cart/add', {
|
|
|
- uuid: item.uuid,
|
|
|
- batchCode: item.batchCode,
|
|
|
- number: item.minBuyQty,
|
|
|
- storeid: item.storeid ? item.storeid : item.storeId,
|
|
|
- storeUuid: item.storeid ? item.storeid : item.storeId,
|
|
|
- currencyName: item.currencyName,
|
|
|
- minPackQty: item.minPackQty
|
|
|
- })
|
|
|
- .then(response => {
|
|
|
- if (response.data.success) {
|
|
|
- if (response.data.message) {
|
|
|
- $this.$message({
|
|
|
- message: '添加购物车成功,但商品信息有更新',
|
|
|
- type: 'success'
|
|
|
- })
|
|
|
- } else {
|
|
|
- $this.$message({
|
|
|
- message: '添加购物车成功',
|
|
|
- type: 'success'
|
|
|
- })
|
|
|
- }
|
|
|
- } else {
|
|
|
- // if (response.data.code === 2) {
|
|
|
- // $this.$message.error('库存已不满足起订量')
|
|
|
- // } else
|
|
|
- if (response.data.message === '该产品已失效') {
|
|
|
- $this.$message.error(response.data.message + ',请刷新页面')
|
|
|
- } else {
|
|
|
- $this.$message.error(response.data.message)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // window.location.href = 'user#/order/pay/' + $this.enidfilter($this.buy_info.orderid)
|
|
|
-}
|
|
|
|
|
|
-export const buyOrCar = buyNow
|
|
|
+export const buyOrCar = _buyNow
|
|
|
+
|
|
|
+export const filterStringEllipsis = (str, len) => {
|
|
|
+ return str ? _getRealLen(str) > len ? _cutOutString(str, len) + '...' : str : null
|
|
|
+}
|