mixin.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. if (this.$store.state.option.isMobile === true) {
  31. this.remindText = '品牌输入不合法'
  32. this.timeoutCount++
  33. } else {
  34. this.$message.error('品牌输入不合法')
  35. }
  36. } else {
  37. if (this.$store.state.option.isMobile === true) {
  38. this.remindText = '品牌不能为空'
  39. this.timeoutCount++
  40. } else {
  41. this.$message.error('品牌不能为空')
  42. }
  43. }
  44. }
  45. return this.validSayPrice.brand
  46. },
  47. checkCode: function () {
  48. let code = this.sayPriceObj.replaceCmpCode.trim()
  49. let nullStrFlag = this.baseUtils.checkNullStr(code)
  50. this.validSayPrice.replaceCmpCode = code && code !== '' && nullStrFlag
  51. if (!this.validSayPrice.replaceCmpCode) {
  52. if (!nullStrFlag) {
  53. if (this.$store.state.option.isMobile === true) {
  54. this.remindText = '型号输入不合法'
  55. this.timeoutCount++
  56. } else {
  57. this.$message.error('型号输入不合法')
  58. }
  59. } else {
  60. if (this.$store.state.option.isMobile === true) {
  61. this.remindText = '型号不能为空'
  62. this.timeoutCount++
  63. } else {
  64. this.$message.error('型号不能为空')
  65. }
  66. }
  67. }
  68. return this.validSayPrice.replaceCmpCode
  69. },
  70. onBrandChange: function () {
  71. this.sayPriceObj.replaceBrand = this.sayPriceObj.replaceBrand.trim()
  72. if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceBrand)) {
  73. let chineseIndex = -1
  74. for (let i = 0; i < this.sayPriceObj.replaceBrand.length; i++) {
  75. if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceBrand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.sayPriceObj.replaceBrand.charAt(i))) {
  76. chineseIndex = i
  77. break
  78. }
  79. }
  80. if (chineseIndex > -1) {
  81. this.sayPriceObj.replaceBrand = this.sayPriceObj.replaceBrand.substring(0, chineseIndex)
  82. }
  83. } else if (this.sayPriceObj.replaceBrand && this.baseUtils.getRealLen(this.sayPriceObj.replaceBrand) > 50) {
  84. this.sayPriceObj.replaceBrand = this.baseUtils.cutOutString(this.sayPriceObj.replaceBrand, 50)
  85. } else {
  86. this.getSimilarBrand()
  87. }
  88. },
  89. onCodeChange: function () {
  90. if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceCmpCode)) {
  91. let chineseIndex = -1
  92. for (let i = 0; i < this.sayPriceObj.replaceCmpCode.length; i++) {
  93. if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceCmpCode.charAt(i))) {
  94. chineseIndex = i
  95. break
  96. }
  97. }
  98. this.sayPriceObj.replaceCmpCode = this.baseUtils.cutOutString(this.sayPriceObj.replaceCmpCode, chineseIndex)
  99. } else if (this.sayPriceObj.replaceCmpCode && this.baseUtils.getRealLen(this.sayPriceObj.replaceCmpCode) > 100) {
  100. this.sayPriceObj.replaceCmpCode = this.baseUtils.cutOutString(this.sayPriceObj.replaceCmpCode, 100)
  101. } else {
  102. this.getSimilarCode()
  103. }
  104. },
  105. getSimilarBrand: function () {
  106. if (this.sayPriceObj.replaceBrand) {
  107. this.$http.get('/search/similarBrands', {params: {keyword: this.sayPriceObj.replaceBrand}})
  108. .then(response => {
  109. this.similarBrand = response.data
  110. this.showSimilarBrandList = response.data.length > 0
  111. })
  112. } else {
  113. this.showSimilarBrandList = false
  114. }
  115. },
  116. getSimilarCode: function () {
  117. if (this.sayPriceObj.replaceCmpCode) {
  118. this.$http.get('/search/similarComponents', {params: {keyword: this.sayPriceObj.replaceCmpCode}})
  119. .then(response => {
  120. this.similarCode = response.data
  121. this.showSimilarCodeList = response.data.length > 0
  122. })
  123. } else {
  124. this.showSimilarCodeList = false
  125. }
  126. },
  127. setBrand: function (brand) {
  128. this.sayPriceObj.replaceBrand = brand
  129. this.showSimilarBrandList = false
  130. },
  131. setCode: function (code) {
  132. this.sayPriceObj.replaceCmpCode = code
  133. this.showSimilarCodeList = false
  134. }
  135. }
  136. }
  137. /*
  138. * 商品购买数量操作
  139. * */
  140. export const goodsPurchaseOperate = {
  141. methods: {
  142. initGoodsStatus (goodsItem, purchaseNumber) {
  143. let pack = goodsItem.perQty || goodsItem.minPackQty
  144. if (goodsItem.breakUp) {
  145. goodsItem.purchaseNumber = purchaseNumber || goodsItem.minBuyQty
  146. goodsItem.canSub = false
  147. goodsItem.canAdd = goodsItem.purchaseNumber < goodsItem.reserve
  148. } else {
  149. if (pack >= goodsItem.minBuyQty) {
  150. goodsItem.purchaseNumber = purchaseNumber || pack
  151. } else {
  152. let max = Math.max(pack, goodsItem.minBuyQty)
  153. goodsItem.purchaseNumber = purchaseNumber || (max + max % pack)
  154. }
  155. goodsItem.canSub = false
  156. goodsItem.canAdd = goodsItem.purchaseNumber + goodsItem.minPackQty <= goodsItem.reserve
  157. }
  158. goodsItem.currentPrice = Number((this.baseUtils.getPriceByLevel(goodsItem.prices, goodsItem.purchaseNumber, goodsItem.currencyName) * goodsItem.purchaseNumber).toFixed(6))
  159. },
  160. onPurchaseNumberInput: function (goods) {
  161. let showPrice = this.baseUtils.getPriceByLevel(goods.goods.prices, goods.goods.purchaseNumber, goods.goods.currencyName)
  162. goods.goods.currentPrice = Number(((showPrice || goods.goods.currentPrice) * goods.goods.purchaseNumber).toFixed(6))
  163. // console.log(goods.goods.currentPrice)
  164. },
  165. checkPurchaseNumber: function (goods) {
  166. if ((/^[\d]*$/).test(goods.goods.purchaseNumber)) {
  167. this.changeNum(goods.goods.purchaseNumber, goods)
  168. } else {
  169. this.setRemindText('请输入整数')
  170. goods.goods.purchaseNumber = goods.goods.minBuyQty
  171. }
  172. },
  173. setGoods: function (type, goods) {
  174. if (type === 'set') {
  175. this.checkPurchaseNumber(goods)
  176. } else {
  177. let isAdd = type === 'add'
  178. let pack = goods.goods.perQty || goods.goods.minPackQty
  179. let newNum = 0
  180. if (goods.goods.breakUp) {
  181. newNum = isAdd ? goods.goods.purchaseNumber + 1 : goods.goods.purchaseNumber - 1
  182. } else {
  183. newNum = isAdd ? goods.goods.purchaseNumber + pack : goods.goods.purchaseNumber - pack
  184. }
  185. this.changeNum(newNum, goods)
  186. }
  187. },
  188. changeNum: function (newNum, goods) {
  189. let pack = goods.goods.perQty || goods.goods.minPackQty
  190. let buy = goods.goods.minBuyQty
  191. let reserve = goods.goods.reserve
  192. let breakUp = goods.goods.breakUp
  193. if (!newNum && newNum !== 0) {
  194. goods.goods.purchaseNumber = buy
  195. } else {
  196. newNum = parseInt(newNum)
  197. if (breakUp) {
  198. if (newNum < buy) {
  199. this.setRemindText('最小起订量为' + buy)
  200. goods.goods.purchaseNumber = buy
  201. goods.goods.canSub = false
  202. // goods.goods.canAdd = true
  203. } else if (newNum > reserve) {
  204. this.setRemindText('库存不足')
  205. goods.goods.purchaseNumber = reserve
  206. goods.goods.canAdd = false
  207. // goods.goods.canSub = true
  208. } else {
  209. goods.goods.canSub = true
  210. goods.goods.canAdd = true
  211. goods.goods.purchaseNumber = newNum
  212. newNum === buy && (goods.goods.canSub = false)
  213. newNum === reserve && (goods.goods.canAdd = false)
  214. }
  215. } else {
  216. if (newNum < buy) {
  217. this.setRemindText('最小起订量为' + buy)
  218. goods.goods.purchaseNumber = buy
  219. goods.goods.canSub = false
  220. if (newNum > reserve) {
  221. this.setRemindText('库存不足')
  222. goods.goods.purchaseNumber = reserve - (reserve % pack)
  223. goods.goods.canAdd = false
  224. }
  225. } else if (newNum > reserve) {
  226. goods.goods.canSub = true
  227. goods.goods.canAdd = false
  228. this.setRemindText('库存不足')
  229. goods.goods.purchaseNumber = reserve - (reserve % pack)
  230. } else {
  231. goods.goods.canSub = true
  232. goods.goods.canAdd = true
  233. let remainder = newNum % pack
  234. if (remainder !== 0) {
  235. // console.log(this.fragment.num)
  236. this.setRemindText('不支持拆包且包装量为' + pack)
  237. // 这个直接赋值的,应该给这个值进行判断(Math.floor(newNum / pack) + 1) * pack
  238. let res = (Math.floor(newNum / pack) + 1) * pack
  239. goods.goods.purchaseNumber = res > reserve ? Math.floor(newNum / pack) * pack : res
  240. } else {
  241. goods.goods.purchaseNumber = newNum
  242. }
  243. newNum === buy && (goods.goods.canSub = false)
  244. newNum === reserve && (goods.goods.canAdd = false)
  245. }
  246. }
  247. }
  248. this.onPurchaseNumberInput(goods)
  249. }
  250. }
  251. }
  252. /*
  253. * 根据产品发布询价
  254. * */
  255. export const seekProduct = {
  256. data () {
  257. return {
  258. applyObj: {
  259. unitPrice: '',
  260. currency: 'RMB',
  261. encapsulation: '',
  262. produceDate: '',
  263. amount: '',
  264. deadline: ''
  265. },
  266. validObj: {
  267. unitPrice: true,
  268. amount: true,
  269. deadline: true
  270. },
  271. pickerOptions: {
  272. disabledDate (time) {
  273. // 大于等于今天 小于三个月后
  274. return time.getTime() < Date.now() - 1000 * 60 * 60 * 24 || time.getTime() > Date.now() + 1000 * 60 * 60 * 24 * 30 * 3
  275. }
  276. },
  277. hasDialog: false
  278. }
  279. },
  280. methods: {
  281. // 时间格式化
  282. setDeadLineValid: function () {
  283. this.applyObj.deadline = this.baseUtils.formatDate(this.baseUtils.getFullDay(new Date(this.applyObj.deadline)), 'yyyy-MM-dd hh:mm:ss')
  284. this.validObj.deadline = true
  285. },
  286. // 检查单价预算
  287. checkUnitPrice () {
  288. this.validObj.unitPrice = this.applyObj.unitPrice === '' ? true : this.applyObj.unitPrice > 0 && this.applyObj.unitPrice < 100000000
  289. if (!this.validObj.unitPrice && this.applyObj.unitPrice <= 0) {
  290. this.$message.error('单价必须是大于0的数字')
  291. }
  292. return this.validObj.unitPrice
  293. },
  294. // 检查采购数量
  295. checkAmount () {
  296. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  297. return this.validObj.amount
  298. },
  299. // 检查时间是否有输入
  300. checkDeadline () {
  301. this.validObj.deadline = Boolean(this.applyObj.deadline)
  302. return this.validObj.deadline
  303. },
  304. // 检查各个字段输入正常数据
  305. checkAll () {
  306. return this.checkDeadline() && this.checkUnitPrice() && this.checkAmount()
  307. },
  308. emptyForm () {
  309. for (let attr in this.applyObj) {
  310. this.applyObj[attr] = attr === 'currency' ? 'RMB' : ''
  311. }
  312. },
  313. // 请求询价信息
  314. goPublish () {
  315. // let _this = this
  316. // this.isClick = true
  317. // setTimeout(function () {
  318. // _this.isClick = false
  319. // }, 1000)
  320. if (this.checkAll()) {
  321. let inquiry = {}
  322. let inquiryItem = {}
  323. if (this.user.data.enterprise) {
  324. inquiry.enUU = this.user.data.enterprise.uu
  325. }
  326. let date = new Date()
  327. let currency = this.applyObj.unitPrice ? this.applyObj.currency : null
  328. inquiry.recorderUU = this.user.data.userUU
  329. inquiry.code = 'MALL' + date.getTime()
  330. inquiry.date = date
  331. inquiry.recorder = this.user.data.userName
  332. inquiry.endDate = this.applyObj.deadline
  333. inquiry.sourceapp = 'MALL'
  334. inquiry.amount = 1
  335. inquiryItem.userUU = this.user.data.userUU
  336. inquiryItem.source = 'MALL'
  337. inquiryItem.userName = this.user.data.userName
  338. inquiryItem.userTel = this.user.data.userTel
  339. inquiryItem.needquantity = this.applyObj.amount
  340. inquiryItem.inbrand = this.productItem.brand
  341. inquiryItem.currency = currency
  342. inquiryItem.cmpCode = this.productItem.cmpCode.toUpperCase()
  343. inquiryItem.unitPrice = this.applyObj.unitPrice
  344. inquiryItem.produceDate = this.applyObj.produceDate
  345. inquiryItem.date = date
  346. inquiryItem.endDate = this.applyObj.deadline
  347. inquiryItem.encapsulation = this.applyObj.encapsulation
  348. inquiryItem.spec = this.productItem.spec
  349. inquiryItem.prodTitle = this.productItem.prodName
  350. let inquiryItems = []
  351. inquiryItems.push(inquiryItem)
  352. inquiry.inquiryItems = inquiryItems
  353. inquiry.currency = this.applyObj.unitPrice ? this.applyObj.currency : null
  354. this.$http.post('/inquiry/buyer/save', inquiry)
  355. .then(res => {
  356. this.$message.success('发布成功')
  357. this.emptyForm()
  358. this.showObj.show = false
  359. }, error => {
  360. console.log(error)
  361. this.$message.error('发布失败')
  362. })
  363. } else {
  364. if (!this.validObj.deadline) {
  365. this.$message.error('截止日期不能为空')
  366. } else if (!this.validObj.amount) {
  367. this.$message.error('请输入正确的数值')
  368. }
  369. }
  370. }
  371. }
  372. }