PublishSeek.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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.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. if (!this.isValidDate(this.applyObj.deadline)) {
  204. this.setRemindText('日期需不小于今天且在90天以内')
  205. this.applyObj.deadline = ''
  206. this.validObj.deadline = false
  207. } else {
  208. this.validObj.deadline = true
  209. }
  210. },
  211. checkAll: function () {
  212. if (this.isNumberReg) {
  213. return this.checkCode() && this.checkBrand() && this.checkProdTitle() && this.checkDeadline() && this.checkSpec()
  214. } else {
  215. return this.checkCode() && this.checkBrand() && this.checkProdTitle() && this.checkDeadline() && this.checkSpec() && this.checkAmount()
  216. }
  217. },
  218. checkCode: function () {
  219. this.validObj.code = this.applyObj.code && this.applyObj.code !== ''
  220. if (!this.validObj.code) {
  221. this.setRemindText('型号不能为空')
  222. }
  223. return this.validObj.code
  224. },
  225. checkBrand: function () {
  226. this.validObj.brand = this.applyObj.brand && this.applyObj.brand !== ''
  227. if (!this.validObj.brand) {
  228. this.setRemindText('品牌不能为空')
  229. }
  230. return this.validObj.brand
  231. },
  232. checkProdTitle: function () {
  233. let prodTitle = this.applyObj.prodTitle.trim()
  234. this.validObj.prodTitle = prodTitle && prodTitle !== ''
  235. if (!this.validObj.prodTitle) {
  236. this.setRemindText('物料名称不能为空')
  237. }
  238. return this.validObj.prodTitle
  239. },
  240. checkSpec: function () {
  241. let nullStrFlag = this.baseUtils.checkNullStr(this.applyObj.spec)
  242. this.validObj.spec = nullStrFlag
  243. if (!nullStrFlag) {
  244. this.setRemindText('规格输入不合法')
  245. }
  246. return this.validObj.spec
  247. },
  248. checkAmount: function () {
  249. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  250. return this.validObj.amount
  251. },
  252. checkDeadline: function () {
  253. this.validObj.deadline = Boolean(this.applyObj.deadline)
  254. return this.validObj.deadline
  255. },
  256. onProduceDateChange: function () {
  257. if (this.applyObj.produceDate && this.baseUtils.getRealLen(this.applyObj.produceDate) > 12) {
  258. this.applyObj.produceDate = this.baseUtils.cutOutString(this.applyObj.produceDate, 12)
  259. }
  260. },
  261. getSimilarCode: function () {
  262. if (this.applyObj.code) {
  263. this.$http.get('/search/similarComponents', {params: {keyword: this.applyObj.code}})
  264. .then(response => {
  265. this.similarCode = response.data
  266. this.showSimilarCodeList = response.data.length > 0
  267. })
  268. } else {
  269. this.showSimilarCodeList = false
  270. }
  271. },
  272. getSimilarBrand: function () {
  273. if (this.applyObj.brand) {
  274. this.$http.get('/search/similarBrands', {params: {keyword: this.applyObj.brand}})
  275. .then(response => {
  276. this.similarBrand = response.data
  277. this.showSimilarBrandList = response.data.length > 0
  278. })
  279. } else {
  280. this.showSimilarBrandList = false
  281. }
  282. },
  283. onCodeChange: function () {
  284. this.applyObj.code = this.applyObj.code.trim()
  285. if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
  286. let chineseIndex = -1
  287. for (let i = 0; i < this.applyObj.code.length; i++) {
  288. if ((/[^\x00-\xff]/g).test(this.applyObj.code.charAt(i))) {
  289. chineseIndex = i
  290. break
  291. }
  292. }
  293. this.applyObj.code = this.baseUtils.cutOutString(this.applyObj.code, chineseIndex)
  294. } else if (this.applyObj.code && this.baseUtils.getRealLen(this.applyObj.code) > 100) {
  295. this.applyObj.code = this.baseUtils.cutOutString(this.applyObj.code, 100)
  296. } else {
  297. this.getSimilarCode()
  298. }
  299. },
  300. onBrandChange: function () {
  301. this.applyObj.brand = this.applyObj.brand.trim()
  302. if ((/[^\x00-\xff]/g).test(this.applyObj.brand)) {
  303. let chineseIndex = -1
  304. for (let i = 0; i < this.applyObj.brand.length; i++) {
  305. if ((/[^\x00-\xff]/g).test(this.applyObj.brand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.applyObj.brand.charAt(i))) {
  306. chineseIndex = i
  307. break
  308. }
  309. }
  310. if (chineseIndex > -1) {
  311. this.applyObj.brand = this.applyObj.brand.substring(0, chineseIndex)
  312. }
  313. } else if (this.applyObj.brand && this.baseUtils.getRealLen(this.applyObj.brand) > 50) {
  314. this.applyObj.brand = this.baseUtils.cutOutString(this.applyObj.brand, 50)
  315. } else {
  316. this.getSimilarBrand()
  317. }
  318. },
  319. onProdTitleInput: function () {
  320. if (this.applyObj.prodTitle && this.baseUtils.getRealLen(this.applyObj.prodTitle) > 40) {
  321. this.applyObj.prodTitle = this.baseUtils.cutOutString(this.applyObj.prodTitle, 40)
  322. }
  323. },
  324. onSpecInput: function () {
  325. if (this.applyObj.spec && this.baseUtils.getRealLen(this.applyObj.spec) > 100) {
  326. this.applyObj.spec = this.baseUtils.cutOutString(this.applyObj.spec, 100)
  327. }
  328. },
  329. onAmountInput: function () {
  330. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  331. let chineseIndex = -1
  332. for (let i = 0; i < this.applyObj.amount.length; i++) {
  333. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  334. chineseIndex = i
  335. break
  336. }
  337. }
  338. this.applyObj.amount = this.baseUtils.cutOutString(this.applyObj.amount, chineseIndex)
  339. } else if (this.applyObj.amount.length > 9) {
  340. this.applyObj.amount = this.baseUtils.cutOutString(this.applyObj.amount, 9)
  341. }
  342. },
  343. setCode: function (code) {
  344. this.applyObj.code = code
  345. this.showSimilarCodeList = false
  346. },
  347. setBrand: function (brand) {
  348. this.applyObj.brand = brand
  349. this.showSimilarBrandList = false
  350. }
  351. }
  352. }
  353. </script>
  354. <style lang="scss" scoped>
  355. .publish_seek_mobile{
  356. padding:.2rem;
  357. .publish-seek {
  358. background: #fff;
  359. padding: .1rem;
  360. border-radius:.1rem;
  361. .content-line {
  362. position: relative;
  363. height: 1rem;
  364. line-height: 1rem;
  365. font-size: .26rem;
  366. text-align: left;
  367. border-bottom:1px solid #d3d3d3;
  368. &:last-child{
  369. border:none;
  370. }
  371. input {
  372. width: 3.49rem;
  373. height: .52rem;
  374. line-height: .52rem;
  375. border: none;
  376. font-size: .26rem;
  377. vertical-align: middle;
  378. background: #fff;
  379. border-radius: 0;
  380. }
  381. > span {
  382. display: inline-block;
  383. width: 2.5rem;
  384. text-align: right;
  385. color:#3176e9;
  386. i {
  387. color: #ff0000;
  388. margin-right: .05rem;
  389. font-style: normal;
  390. }
  391. }
  392. > a {
  393. font-size: .26rem;
  394. color: #666;
  395. }
  396. > img {
  397. width: .12rem;
  398. height: .06rem;
  399. margin-left: .04rem;
  400. }
  401. .similar {
  402. position: absolute;
  403. width: 3.49rem;
  404. max-height: 2.5rem;
  405. overflow-y: auto;
  406. z-index: 12;
  407. border: 1px solid #7e7e7e;
  408. border-radius: .05rem;
  409. left: 2.5rem;
  410. top: .7rem;
  411. background: #fff;
  412. li {
  413. height: .5rem;
  414. line-height: .5rem;
  415. font-size: .26rem;
  416. color: #999;
  417. padding-left: .19rem;
  418. &:focus, &:active, &:hover {
  419. background: #999;
  420. color: #fff;
  421. }
  422. }
  423. }
  424. }
  425. }
  426. > a {
  427. display: block;
  428. width: 5.19rem;
  429. height: .84rem;
  430. text-align: center;
  431. line-height: .84rem;
  432. font-size: .38rem;
  433. margin: .3rem auto 0;
  434. background: #3176e9;
  435. color: #fff;
  436. border-radius: .08rem;
  437. }
  438. }
  439. .datepicker-overlay {
  440. z-index: 9999;
  441. .cov-date-body {
  442. width: 4rem;
  443. font-size: .16rem;
  444. .cov-date-monthly {
  445. height: 1.5rem;
  446. div {
  447. height: 1.5rem;
  448. }
  449. .cov-date-caption {
  450. font-size: .24rem;
  451. padding: .5rem 0 !important;
  452. }
  453. .cov-date-next {
  454. text-indent: -3rem;
  455. }
  456. }
  457. .cov-date-box {
  458. .cov-picker-box {
  459. padding: .25rem;
  460. width: 4rem;
  461. height: 2.8rem;
  462. .week {
  463. ul {
  464. margin: 0 0 .08rem;
  465. }
  466. }
  467. .day {
  468. height: .34rem;
  469. line-height: .34rem;
  470. }
  471. }
  472. }
  473. }
  474. .button-box {
  475. height: .5rem;
  476. line-height: .5rem;
  477. padding-right: .2rem;
  478. span {
  479. padding: .1rem .2rem;
  480. }
  481. }
  482. }
  483. </style>