mixin.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. }
  117. /*
  118. * 商品购买数量操作
  119. * */
  120. export const goodsPurchaseOperate = {
  121. methods: {
  122. initGoodsStatus (goodsItem, purchaseNumber) {
  123. let pack = goodsItem.perQty || goodsItem.minPackQty
  124. if (goodsItem.breakUp) {
  125. goodsItem.purchaseNumber = purchaseNumber || goodsItem.minBuyQty
  126. goodsItem.canSub = false
  127. goodsItem.canAdd = goodsItem.purchaseNumber < goodsItem.reserve
  128. } else {
  129. if (pack >= goodsItem.minBuyQty) {
  130. goodsItem.purchaseNumber = purchaseNumber || pack
  131. } else {
  132. let max = Math.max(pack, goodsItem.minBuyQty)
  133. goodsItem.purchaseNumber = purchaseNumber || (max + max % pack)
  134. }
  135. goodsItem.canSub = false
  136. goodsItem.canAdd = goodsItem.purchaseNumber + goodsItem.minPackQty <= goodsItem.reserve
  137. }
  138. goodsItem.currentPrice = Number((this.baseUtils.getPriceByLevel(goodsItem.prices, goodsItem.purchaseNumber, goodsItem.currencyName) * goodsItem.purchaseNumber).toFixed(6))
  139. },
  140. onPurchaseNumberInput: function (goods) {
  141. let showPrice = this.baseUtils.getPriceByLevel(goods.goods.prices, goods.goods.purchaseNumber, goods.goods.currencyName)
  142. goods.goods.currentPrice = Number(((showPrice || goods.goods.currentPrice) * goods.goods.purchaseNumber).toFixed(6))
  143. // console.log(goods.goods.currentPrice)
  144. },
  145. checkPurchaseNumber: function (goods) {
  146. if ((/^[\d]*$/).test(goods.goods.purchaseNumber)) {
  147. this.changeNum(goods.goods.purchaseNumber, goods)
  148. } else {
  149. this.setRemindText('请输入整数')
  150. goods.goods.purchaseNumber = goods.goods.minBuyQty
  151. }
  152. },
  153. setGoods: function (type, goods) {
  154. if (type === 'set') {
  155. this.checkPurchaseNumber(goods)
  156. } else {
  157. let isAdd = type === 'add'
  158. let pack = goods.goods.perQty || goods.goods.minPackQty
  159. let newNum = 0
  160. if (goods.goods.breakUp) {
  161. newNum = isAdd ? goods.goods.purchaseNumber + 1 : goods.goods.purchaseNumber - 1
  162. } else {
  163. newNum = isAdd ? goods.goods.purchaseNumber + pack : goods.goods.purchaseNumber - pack
  164. }
  165. this.changeNum(newNum, goods)
  166. }
  167. },
  168. changeNum: function (newNum, goods) {
  169. let pack = goods.goods.perQty || goods.goods.minPackQty
  170. let buy = goods.goods.minBuyQty
  171. let reserve = goods.goods.reserve
  172. let breakUp = goods.goods.breakUp
  173. if (!newNum && newNum !== 0) {
  174. goods.goods.purchaseNumber = buy
  175. } else {
  176. newNum = parseInt(newNum)
  177. if (breakUp) {
  178. if (newNum < buy) {
  179. this.setRemindText('最小起订量为' + buy)
  180. goods.goods.purchaseNumber = buy
  181. goods.goods.canSub = false
  182. // goods.goods.canAdd = true
  183. } else if (newNum > reserve) {
  184. this.setRemindText('库存不足')
  185. goods.goods.purchaseNumber = reserve
  186. goods.goods.canAdd = false
  187. // goods.goods.canSub = true
  188. } else {
  189. goods.goods.canSub = true
  190. goods.goods.canAdd = true
  191. goods.goods.purchaseNumber = newNum
  192. newNum === buy && (goods.goods.canSub = false)
  193. newNum === reserve && (goods.goods.canAdd = false)
  194. }
  195. } else {
  196. if (newNum < buy) {
  197. this.setRemindText('最小起订量为' + buy)
  198. goods.goods.purchaseNumber = buy
  199. goods.goods.canSub = false
  200. if (newNum > reserve) {
  201. this.setRemindText('库存不足')
  202. goods.goods.purchaseNumber = reserve - (reserve % pack)
  203. goods.goods.canAdd = false
  204. }
  205. } else if (newNum > reserve) {
  206. goods.goods.canSub = true
  207. goods.goods.canAdd = false
  208. this.setRemindText('库存不足')
  209. goods.goods.purchaseNumber = reserve - (reserve % pack)
  210. } else {
  211. goods.goods.canSub = true
  212. goods.goods.canAdd = true
  213. let remainder = newNum % pack
  214. if (remainder !== 0) {
  215. // console.log(this.fragment.num)
  216. this.setRemindText('不支持拆包且包装量为' + pack)
  217. // 这个直接赋值的,应该给这个值进行判断(Math.floor(newNum / pack) + 1) * pack
  218. let res = (Math.floor(newNum / pack) + 1) * pack
  219. goods.goods.purchaseNumber = res > reserve ? Math.floor(newNum / pack) * pack : res
  220. } else {
  221. goods.goods.purchaseNumber = newNum
  222. }
  223. newNum === buy && (goods.goods.canSub = false)
  224. newNum === reserve && (goods.goods.canAdd = false)
  225. }
  226. }
  227. }
  228. this.onPurchaseNumberInput(goods)
  229. }
  230. }
  231. }