mixin.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. }
  232. /*
  233. * 根据产品发布询价
  234. * */
  235. export const seekProduct = {
  236. data () {
  237. return {
  238. applyObj: {
  239. unitPrice: '',
  240. currency: 'RMB',
  241. encapsulation: '',
  242. produceDate: '',
  243. amount: '',
  244. deadline: ''
  245. },
  246. validObj: {
  247. unitPrice: true,
  248. amount: true,
  249. deadline: true
  250. },
  251. pickerOptions: {
  252. disabledDate (time) {
  253. // 大于等于今天 小于三个月后
  254. return time.getTime() < Date.now() - 1000 * 60 * 60 * 24 || time.getTime() > Date.now() + 1000 * 60 * 60 * 24 * 30 * 3
  255. }
  256. },
  257. hasDialog: false
  258. }
  259. },
  260. methods: {
  261. // 时间格式化
  262. setDeadLineValid: function () {
  263. this.applyObj.deadline = this.baseUtils.formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  264. this.validObj.deadline = true
  265. },
  266. // 检查单价预算
  267. checkUnitPrice () {
  268. this.validObj.unitPrice = this.applyObj.unitPrice === '' ? true : this.applyObj.unitPrice > 0 && this.applyObj.unitPrice < 100000000
  269. if (!this.validObj.unitPrice && this.applyObj.unitPrice <= 0) {
  270. this.$message.error('单价必须是大于0的数字')
  271. }
  272. return this.validObj.unitPrice
  273. },
  274. // 检查采购数量
  275. checkAmount () {
  276. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  277. return this.validObj.amount
  278. },
  279. // 检查时间是否有输入
  280. checkDeadline () {
  281. this.validObj.deadline = Boolean(this.applyObj.deadline)
  282. return this.validObj.deadline
  283. },
  284. // 检查各个字段输入正常数据
  285. checkAll () {
  286. return this.checkDeadline() && this.checkUnitPrice() && this.checkAmount()
  287. },
  288. emptyForm () {
  289. for (let attr in this.applyObj) {
  290. this.applyObj[attr] = attr === 'currency' ? 'RMB' : ''
  291. }
  292. },
  293. // 请求询价信息
  294. goPublish () {
  295. // let _this = this
  296. // this.isClick = true
  297. // setTimeout(function () {
  298. // _this.isClick = false
  299. // }, 1000)
  300. if (this.checkAll()) {
  301. let inquiry = {}
  302. let inquiryItem = {}
  303. if (this.user.data.enterprise) {
  304. inquiry.enUU = this.user.data.enterprise.uu
  305. }
  306. let date = new Date()
  307. let currency = this.applyObj.unitPrice ? this.applyObj.currency : null
  308. inquiry.recorderUU = this.user.data.userUU
  309. inquiry.code = 'MALL' + date.getTime()
  310. inquiry.date = date
  311. inquiry.recorder = this.user.data.userName
  312. inquiry.endDate = this.applyObj.deadline
  313. inquiry.sourceapp = 'MALL'
  314. inquiry.amount = 1
  315. inquiryItem.userUU = this.user.data.userUU
  316. inquiryItem.source = 'MALL'
  317. inquiryItem.userName = this.user.data.userName
  318. inquiryItem.userTel = this.user.data.userTel
  319. inquiryItem.needquantity = this.applyObj.amount
  320. inquiryItem.inbrand = this.productItem.brand
  321. inquiryItem.currency = currency
  322. inquiryItem.cmpCode = this.productItem.cmpCode.toUpperCase()
  323. inquiryItem.unitPrice = this.applyObj.unitPrice
  324. inquiryItem.produceDate = this.applyObj.produceDate
  325. inquiryItem.date = date
  326. inquiryItem.endDate = this.applyObj.deadline
  327. inquiryItem.encapsulation = this.applyObj.encapsulation
  328. inquiryItem.spec = this.productItem.spec
  329. inquiryItem.prodTitle = this.productItem.prodName
  330. let inquiryItems = []
  331. inquiryItems.push(inquiryItem)
  332. inquiry.inquiryItems = inquiryItems
  333. inquiry.currency = this.applyObj.unitPrice ? this.applyObj.currency : null
  334. this.$http.post('/inquiry/buyer/save', inquiry)
  335. .then(res => {
  336. this.$message.success('发布成功')
  337. this.emptyForm()
  338. this.showObj.show = false
  339. }, error => {
  340. console.log(error)
  341. this.$message.error('发布失败')
  342. })
  343. } else {
  344. if (!this.validObj.deadline) {
  345. this.$message.error('截止日期不能为空')
  346. } else if (!this.validObj.amount) {
  347. this.$message.error('请输入正确的数值')
  348. }
  349. }
  350. }
  351. }
  352. }