PublishSeek.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <template>
  2. <div class="publish_seek_mobile">
  3. <div class="publish-seek">
  4. <div class="content-line">
  5. <span><i>*</i>型号:</span>
  6. <input type="text" v-model="applyObj.code" @blur="checkCode" @input="onCodeChange" placeholder="请勿填中文符号">
  7. <ul class="similar" v-show="showSimilarCodeList && applyObj.code">
  8. <li v-for="sCode in similarCode" @click.stop="setCode(sCode.code)">{{sCode.code}}</li>
  9. </ul>
  10. </div>
  11. <div class="content-line">
  12. <span><i>*</i>品牌:</span>
  13. <input type="text" v-model="applyObj.brand" @blur="checkBrand" @input="onBrandChange" placeholder="请勿填中文符号">
  14. <ul class="similar brand-similar-list" v-show="showSimilarBrandList && applyObj.brand">
  15. <li v-for="sBrand in similarBrand" @click.stop="setBrand(sBrand.nameEn)">{{sBrand.nameEn}}</li>
  16. </ul>
  17. </div>
  18. <div class="content-line">
  19. <span><i>*</i>物料名称:</span>
  20. <input type="text" v-model="applyObj.prodTitle" @blur="checkProdTitle" @input="onProdTitleInput">
  21. </div>
  22. <div class="content-line">
  23. <span>规格:</span>
  24. <input type="text" v-model="applyObj.spec" @blur="checkSpec" @input="onSpecInput">
  25. </div>
  26. <div class="content-line">
  27. <span><i>*</i>截止日期:</span>
  28. <input type="date" v-model="applyObj.deadline" :min="minDay" :max="maxDay" @blur="deadlineChange">
  29. <!--<el-date-picker-->
  30. <!--v-model="applyObj.deadline"-->
  31. <!--type="date"-->
  32. <!--:editable="false"-->
  33. <!--:clearable="true"-->
  34. <!--size="mini">-->
  35. <!--</el-date-picker>-->
  36. </div>
  37. <!--<div class="content-line">
  38. <span>币种:</span>
  39. <a v-text="applyObj.currency" @click="setShowCurrencyList(!showCurrencyList, $event)"></a>
  40. <img v-if="!showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-down.png" alt="">
  41. <img v-if="showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-up.png" alt="">
  42. <ul v-if="showCurrencyList">
  43. <li @click="setCurrency('不限')">不限</li>
  44. <li @click="setCurrency('RMB')">RMB</li>
  45. <li @click="setCurrency('USD')">USD</li>
  46. </ul>
  47. </div>-->
  48. <div class="content-line">
  49. <span>数量(PCS):</span>
  50. <input type="text" v-model="applyObj.amount" @blur="checkAmount" @input="onAmountInput">
  51. </div>
  52. <!--<div class="content-line">
  53. <span>生产日期:</span>
  54. <input type="text" v-model="applyObj.produceDate" @input="onProduceDateChange">
  55. </div>-->
  56. </div>
  57. <a @click.stop="authorityInterceptor(baseUrls.userPublishSeek, goPublish)">确认发布</a>
  58. </div>
  59. </template>
  60. <script>
  61. export default {
  62. props: ['dataObj', 'isNumberReg'],
  63. data () {
  64. return {
  65. applyObj: {
  66. code: '',
  67. brand: '',
  68. unitPrice: '',
  69. currency: '不限',
  70. encapsulation: '',
  71. produceDate: '',
  72. amount: '',
  73. deadline: '',
  74. prodTitle: ''
  75. },
  76. validObj: {
  77. code: true,
  78. brand: true,
  79. unitPrice: true,
  80. amount: true,
  81. deadline: true,
  82. prodTitle: true
  83. },
  84. showCurrencyList: false,
  85. showSimilarCodeList: false,
  86. showSimilarBrandList: false,
  87. similarCode: [],
  88. similarBrand: []
  89. }
  90. },
  91. computed: {
  92. user () {
  93. return this.$store.state.option.user
  94. },
  95. minDay: function () {
  96. return this.baseUtils.formatDate(new Date(), 'yyyy-MM-dd')
  97. },
  98. maxDay: function () {
  99. let deadDate = new Date().getTime() + 1000 * 60 * 60 * 24 * 90
  100. deadDate = this.baseUtils.formatDate(new Date(deadDate), 'yyyy-MM-dd')
  101. return deadDate
  102. }
  103. },
  104. mounted () {
  105. let _this = this
  106. if (this.dataObj) {
  107. this.applyObj = this.dataObj
  108. } else {
  109. this.emptyForm()
  110. }
  111. document.body.onclick = function () {
  112. _this.showSimilarCodeList = false
  113. _this.showSimilarBrandList = false
  114. }
  115. },
  116. methods: {
  117. emptyForm: function () {
  118. for (let attr in this.applyObj) {
  119. this.applyObj[attr] = attr === 'currency' ? '不限' : ''
  120. }
  121. },
  122. setRemindText: function (str) {
  123. this.$emit('remindAction', str)
  124. },
  125. setShowCurrencyList: function (flag, e) {
  126. if (e) {
  127. e.stopPropagation()
  128. }
  129. this.showCurrencyList = flag
  130. },
  131. getMaterialKind: function (code, brand) {
  132. return this.$http.get('/productuser/match/getKind', {params: {cmpCode: code, brand: brand}})
  133. },
  134. goPublish: function () {
  135. if (this.checkAll()) {
  136. this.getMaterialKind(this.applyObj.code, this.applyObj.brand).then(response => {
  137. let inquiry = {}
  138. let inquiryItem = {}
  139. if (this.user.data.enterprise) {
  140. inquiry.enUU = this.user.data.enterprise.uu
  141. }
  142. let date = new Date()
  143. let endDate = this.baseUtils.formatDate(this.baseUtils.getFullDay(new Date(this.baseUtils.getClearDay(new Date(this.applyObj.deadline)))), 'yyyy-MM-dd hh:mm:ss')
  144. // let currency = this.applyObj.currency === '不限' ? null : this.applyObj.currency
  145. let currency = null
  146. inquiry.recorderUU = this.user.data.userUU
  147. inquiry.code = 'MALL' + date.getTime()
  148. inquiry.date = date
  149. inquiry.recorder = this.user.data.userName
  150. inquiry.endDate = endDate
  151. inquiry.sourceapp = 'MALL'
  152. inquiry.amount = 1
  153. inquiryItem.prodTitle = response.data && response.data.length ? response.data : this.applyObj.prodTitle
  154. inquiryItem.userUU = this.user.data.userUU
  155. inquiryItem.source = 'MALL'
  156. inquiryItem.userName = this.user.data.userName
  157. inquiryItem.userTel = this.user.data.userTel
  158. inquiryItem.needquantity = this.applyObj.amount
  159. inquiryItem.inbrand = this.applyObj.brand
  160. inquiryItem.spec = this.applyObj.spec
  161. inquiryItem.custCurrency = currency
  162. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  163. inquiryItem.unitPrice = this.applyObj.unitPrice
  164. inquiryItem.produceDate = null
  165. inquiryItem.date = date
  166. inquiryItem.endDate = endDate
  167. inquiryItem.encapsulation = this.applyObj.encapsulation
  168. let inquiryItems = []
  169. inquiryItems.push(inquiryItem)
  170. inquiry.inquiryItems = inquiryItems
  171. inquiry.currency = currency
  172. this.$http.post('/inquiry/buyer/save', inquiry)
  173. .then(response => {
  174. this.setRemindText('发布成功')
  175. this.emptyForm()
  176. this.$emit('reloadAction')
  177. }, error => {
  178. console.log(error)
  179. this.setRemindText('发布失败')
  180. })
  181. })
  182. } else {
  183. if (!this.validObj.code) {
  184. this.setRemindText('型号不能为空')
  185. } else if (!this.validObj.brand) {
  186. this.setRemindText('品牌不能为空')
  187. } else if (!this.validObj.deadline) {
  188. this.setRemindText('截止日期不能为空')
  189. } else if (!this.validObj.amount && !this.isNumberReg) {
  190. this.setRemindText('请输入正确的数值')
  191. }
  192. }
  193. },
  194. setCurrency: function (type) {
  195. this.applyObj.currency = type
  196. },
  197. isValidDate: function (date) {
  198. let now = new Date(this.baseUtils.formatDate(new Date(), 'yyyy-MM-dd')).getTime()
  199. let time = new Date(date).getTime()
  200. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 90)
  201. },
  202. deadlineChange: function () {
  203. // this.applyObj.deadline = this.baseUtils.formatDate(this.baseUtils.getFullDay(new Date(this.baseUtils.getClearDay(new Date(this.applyObj.deadline)))), 'yyyy-MM-dd hh:mm:ss')
  204. if (!this.isValidDate(this.applyObj.deadline)) {
  205. this.setRemindText('日期需不小于今天且在90天以内')
  206. this.applyObj.deadline = ''
  207. this.validObj.deadline = false
  208. } else {
  209. this.validObj.deadline = true
  210. }
  211. },
  212. checkAll: function () {
  213. if (this.isNumberReg) {
  214. return this.checkCode() && this.checkBrand() && this.checkProdTitle() && this.checkDeadline() && this.checkSpec()
  215. } else {
  216. return this.checkCode() && this.checkBrand() && this.checkProdTitle() && this.checkDeadline() && this.checkSpec() && this.checkAmount()
  217. }
  218. },
  219. checkCode: function () {
  220. this.validObj.code = this.applyObj.code && this.applyObj.code !== ''
  221. if (!this.validObj.code) {
  222. this.setRemindText('型号不能为空')
  223. }
  224. return this.validObj.code
  225. },
  226. checkBrand: function () {
  227. this.validObj.brand = this.applyObj.brand && this.applyObj.brand !== ''
  228. if (!this.validObj.brand) {
  229. this.setRemindText('品牌不能为空')
  230. }
  231. return this.validObj.brand
  232. },
  233. checkProdTitle: function () {
  234. let prodTitle = this.applyObj.prodTitle.trim()
  235. this.validObj.prodTitle = prodTitle && prodTitle !== ''
  236. if (!this.validObj.prodTitle) {
  237. this.setRemindText('物料名称不能为空')
  238. }
  239. return this.validObj.prodTitle
  240. },
  241. checkSpec: function () {
  242. let nullStrFlag = this.baseUtils.checkNullStr(this.applyObj.spec)
  243. this.validObj.spec = nullStrFlag
  244. if (!nullStrFlag) {
  245. this.setRemindText('规格输入不合法')
  246. }
  247. return this.validObj.spec
  248. },
  249. checkAmount: function () {
  250. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  251. return this.validObj.amount
  252. },
  253. checkDeadline: function () {
  254. this.validObj.deadline = Boolean(this.applyObj.deadline)
  255. return this.validObj.deadline
  256. },
  257. onProduceDateChange: function () {
  258. if (this.applyObj.produceDate && this.baseUtils.getRealLen(this.applyObj.produceDate) > 12) {
  259. this.applyObj.produceDate = this.baseUtils.cutOutString(this.applyObj.produceDate, 12)
  260. }
  261. },
  262. getSimilarCode: function () {
  263. if (this.applyObj.code) {
  264. this.$http.get('/search/similarComponents', {params: {keyword: this.applyObj.code}})
  265. .then(response => {
  266. this.similarCode = response.data
  267. this.showSimilarCodeList = response.data.length > 0
  268. })
  269. } else {
  270. this.showSimilarCodeList = false
  271. }
  272. },
  273. getSimilarBrand: function () {
  274. if (this.applyObj.brand) {
  275. this.$http.get('/search/similarBrands', {params: {keyword: this.applyObj.brand}})
  276. .then(response => {
  277. this.similarBrand = response.data
  278. this.showSimilarBrandList = response.data.length > 0
  279. })
  280. } else {
  281. this.showSimilarBrandList = false
  282. }
  283. },
  284. onCodeChange: function () {
  285. this.applyObj.code = this.applyObj.code.trim()
  286. if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
  287. let chineseIndex = -1
  288. for (let i = 0; i < this.applyObj.code.length; i++) {
  289. if ((/[^\x00-\xff]/g).test(this.applyObj.code.charAt(i))) {
  290. chineseIndex = i
  291. break
  292. }
  293. }
  294. this.applyObj.code = this.baseUtils.cutOutString(this.applyObj.code, chineseIndex)
  295. } else if (this.applyObj.code && this.baseUtils.getRealLen(this.applyObj.code) > 100) {
  296. this.applyObj.code = this.baseUtils.cutOutString(this.applyObj.code, 100)
  297. } else {
  298. this.getSimilarCode()
  299. }
  300. },
  301. onBrandChange: function () {
  302. this.applyObj.brand = this.applyObj.brand.trim()
  303. if ((/[^\x00-\xff]/g).test(this.applyObj.brand)) {
  304. let chineseIndex = -1
  305. for (let i = 0; i < this.applyObj.brand.length; i++) {
  306. if ((/[^\x00-\xff]/g).test(this.applyObj.brand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.applyObj.brand.charAt(i))) {
  307. chineseIndex = i
  308. break
  309. }
  310. }
  311. if (chineseIndex > -1) {
  312. this.applyObj.brand = this.applyObj.brand.substring(0, chineseIndex)
  313. }
  314. } else if (this.applyObj.brand && this.baseUtils.getRealLen(this.applyObj.brand) > 50) {
  315. this.applyObj.brand = this.baseUtils.cutOutString(this.applyObj.brand, 50)
  316. } else {
  317. this.getSimilarBrand()
  318. }
  319. },
  320. onProdTitleInput: function () {
  321. if (this.applyObj.prodTitle && this.baseUtils.getRealLen(this.applyObj.prodTitle) > 40) {
  322. this.applyObj.prodTitle = this.baseUtils.cutOutString(this.applyObj.prodTitle, 40)
  323. }
  324. },
  325. onSpecInput: function () {
  326. if (this.applyObj.spec && this.baseUtils.getRealLen(this.applyObj.spec) > 100) {
  327. this.applyObj.spec = this.baseUtils.cutOutString(this.applyObj.spec, 100)
  328. }
  329. },
  330. onAmountInput: function () {
  331. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  332. let chineseIndex = -1
  333. for (let i = 0; i < this.applyObj.amount.length; i++) {
  334. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  335. chineseIndex = i
  336. break
  337. }
  338. }
  339. this.applyObj.amount = this.baseUtils.cutOutString(this.applyObj.amount, chineseIndex)
  340. } else if (this.applyObj.amount.length > 9) {
  341. this.applyObj.amount = this.baseUtils.cutOutString(this.applyObj.amount, 9)
  342. }
  343. },
  344. setCode: function (code) {
  345. this.$http.get('/search/201819', {params: {page: 1, count: 1, type: 'component', keyword: code}})
  346. .then(res => {
  347. if (res.data && res.data.futures && res.data.futures.content) {
  348. let obj = res.data.futures.content[0]
  349. if (obj) {
  350. this.applyObj.brand = obj.pbrand || obj.pbranden || ''
  351. this.applyObj.prodTitle = obj.kind || obj.kinden || ''
  352. this.applyObj.spec = obj.spec || ''
  353. }
  354. }
  355. this.applyObj.code = code
  356. this.showSimilarCodeList = false
  357. }, err => {
  358. this.applyObj.code = code
  359. this.showSimilarCodeList = false
  360. console.log(err.response.data || err)
  361. })
  362. },
  363. setBrand: function (brand) {
  364. this.applyObj.brand = brand
  365. this.showSimilarBrandList = false
  366. }
  367. }
  368. }
  369. </script>
  370. <style lang="scss" scoped>
  371. .publish_seek_mobile{
  372. padding:.2rem;
  373. .publish-seek {
  374. background: #fff;
  375. padding: .1rem;
  376. border-radius:.1rem;
  377. .content-line {
  378. position: relative;
  379. height: 1rem;
  380. line-height: 1rem;
  381. font-size: .26rem;
  382. text-align: left;
  383. border-bottom:1px solid #d3d3d3;
  384. &:last-child{
  385. border:none;
  386. }
  387. input {
  388. width: 3.49rem;
  389. height: .52rem;
  390. line-height: .52rem;
  391. border: none;
  392. font-size: .26rem;
  393. vertical-align: middle;
  394. background: #fff;
  395. border-radius: 0;
  396. }
  397. > span {
  398. display: inline-block;
  399. width: 2.5rem;
  400. text-align: right;
  401. color:#3176e9;
  402. i {
  403. color: #ff0000;
  404. margin-right: .05rem;
  405. font-style: normal;
  406. }
  407. }
  408. > a {
  409. font-size: .26rem;
  410. color: #666;
  411. }
  412. > img {
  413. width: .12rem;
  414. height: .06rem;
  415. margin-left: .04rem;
  416. }
  417. .similar {
  418. position: absolute;
  419. width: 3.49rem;
  420. max-height: 2.5rem;
  421. overflow-y: auto;
  422. z-index: 12;
  423. border: 1px solid #7e7e7e;
  424. border-radius: .05rem;
  425. left: 2.5rem;
  426. top: .7rem;
  427. background: #fff;
  428. li {
  429. height: .5rem;
  430. line-height: .5rem;
  431. font-size: .26rem;
  432. color: #999;
  433. padding-left: .19rem;
  434. &:focus, &:active, &:hover {
  435. background: #999;
  436. color: #fff;
  437. }
  438. }
  439. }
  440. }
  441. }
  442. > a {
  443. display: block;
  444. width: 5.19rem;
  445. height: .84rem;
  446. text-align: center;
  447. line-height: .84rem;
  448. font-size: .38rem;
  449. margin: .3rem auto 0;
  450. background: #3176e9;
  451. color: #fff;
  452. border-radius: .08rem;
  453. }
  454. }
  455. .datepicker-overlay {
  456. z-index: 9999;
  457. .cov-date-body {
  458. width: 4rem;
  459. font-size: .16rem;
  460. .cov-date-monthly {
  461. height: 1.5rem;
  462. div {
  463. height: 1.5rem;
  464. }
  465. .cov-date-caption {
  466. font-size: .24rem;
  467. padding: .5rem 0 !important;
  468. }
  469. .cov-date-next {
  470. text-indent: -3rem;
  471. }
  472. }
  473. .cov-date-box {
  474. .cov-picker-box {
  475. padding: .25rem;
  476. width: 4rem;
  477. height: 2.8rem;
  478. .week {
  479. ul {
  480. margin: 0 0 .08rem;
  481. }
  482. }
  483. .day {
  484. height: .34rem;
  485. line-height: .34rem;
  486. }
  487. }
  488. }
  489. }
  490. .button-box {
  491. height: .5rem;
  492. line-height: .5rem;
  493. padding-right: .2rem;
  494. span {
  495. padding: .1rem .2rem;
  496. }
  497. }
  498. }
  499. </style>