mixin.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. export const carousel = {
  2. computed: {
  3. isIE () {
  4. return /(MSIE)|(Trident)/.test(this.$store.state.option.userAgent)
  5. },
  6. effect () {
  7. return this.isIE ? 'slide' : 'fade'
  8. }
  9. }
  10. }
  11. export const sayPriceReplace = {
  12. data () {
  13. return {
  14. showSimilarCodeList: false,
  15. showSimilarBrandList: false,
  16. similarCode: [],
  17. similarBrand: []
  18. }
  19. },
  20. methods: {
  21. clearSimilar: function () {
  22. this.showSimilarCodeList = false
  23. this.showSimilarBrandList = false
  24. },
  25. checkBrand: function () {
  26. let nullStrFlag = this.baseUtils.checkNullStr(this.sayPriceObj.replaceBrand)
  27. this.validSayPrice.replaceBrand = this.sayPriceObj.replaceBrand && this.sayPriceObj.replaceBrand !== '' && nullStrFlag
  28. if (!this.validSayPrice.replaceBrand) {
  29. if (!nullStrFlag) {
  30. this.$message.error('品牌输入不合法')
  31. } else {
  32. this.$message.error('品牌不能为空')
  33. }
  34. }
  35. return this.validSayPrice.brand
  36. },
  37. checkCode: function () {
  38. let code = this.sayPriceObj.replaceCmpCode.trim()
  39. let nullStrFlag = this.baseUtils.checkNullStr(code)
  40. this.validSayPrice.replaceCmpCode = code && code !== '' && nullStrFlag
  41. if (!this.validSayPrice.replaceCmpCode) {
  42. if (!nullStrFlag) {
  43. this.$message.error('型号输入不合法')
  44. } else {
  45. this.$message.error('型号不能为空')
  46. }
  47. }
  48. return this.validSayPrice.replaceCmpCode
  49. },
  50. onBrandChange: function () {
  51. this.sayPriceObj.replaceBrand = this.sayPriceObj.replaceBrand.trim()
  52. if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceBrand)) {
  53. let chineseIndex = -1
  54. for (let i = 0; i < this.sayPriceObj.replaceBrand.length; i++) {
  55. if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceBrand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.sayPriceObj.replaceBrand.charAt(i))) {
  56. chineseIndex = i
  57. break
  58. }
  59. }
  60. if (chineseIndex > -1) {
  61. this.sayPriceObj.replaceBrand = this.sayPriceObj.replaceBrand.substring(0, chineseIndex)
  62. }
  63. } else if (this.sayPriceObj.replaceBrand && this.baseUtils.getRealLen(this.sayPriceObj.replaceBrand) > 50) {
  64. this.sayPriceObj.replaceBrand = this.baseUtils.cutOutString(this.sayPriceObj.replaceBrand, 50)
  65. } else {
  66. this.getSimilarBrand()
  67. }
  68. },
  69. onCodeChange: function () {
  70. if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceCmpCode)) {
  71. let chineseIndex = -1
  72. for (let i = 0; i < this.sayPriceObj.replaceCmpCode.length; i++) {
  73. if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceCmpCode.charAt(i))) {
  74. chineseIndex = i
  75. break
  76. }
  77. }
  78. this.sayPriceObj.replaceCmpCode = this.baseUtils.cutOutString(this.sayPriceObj.replaceCmpCode, chineseIndex)
  79. } else if (this.sayPriceObj.replaceCmpCode && this.baseUtils.getRealLen(this.sayPriceObj.replaceCmpCode) > 100) {
  80. this.sayPriceObj.replaceCmpCode = this.baseUtils.cutOutString(this.sayPriceObj.replaceCmpCode, 100)
  81. } else {
  82. this.getSimilarCode()
  83. }
  84. },
  85. getSimilarBrand: function () {
  86. if (this.sayPriceObj.replaceBrand) {
  87. this.$http.get('/search/similarBrands', {params: {keyword: this.sayPriceObj.replaceBrand}})
  88. .then(response => {
  89. this.similarBrand = response.data
  90. this.showSimilarBrandList = response.data.length > 0
  91. })
  92. } else {
  93. this.showSimilarBrandList = false
  94. }
  95. },
  96. getSimilarCode: function () {
  97. if (this.sayPriceObj.replaceCmpCode) {
  98. this.$http.get('/search/similarComponents', {params: {keyword: this.sayPriceObj.replaceCmpCode}})
  99. .then(response => {
  100. this.similarCode = response.data
  101. this.showSimilarCodeList = response.data.length > 0
  102. })
  103. } else {
  104. this.showSimilarCodeList = false
  105. }
  106. },
  107. setBrand: function (brand) {
  108. this.sayPriceObj.replaceBrand = brand
  109. this.showSimilarBrandList = false
  110. },
  111. setCode: function (code) {
  112. this.sayPriceObj.replaceCmpCode = code
  113. this.showSimilarCodeList = false
  114. }
  115. }
  116. }