PublishSeek.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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.brand" @blur="checkBrand" @input="onBrandChange" placeholder="请勿填中文符号">
  7. <ul class="similar brand-similar-list" v-show="showSimilarBrandList && applyObj.brand">
  8. <li v-for="sBrand in similarBrand" @click="setBrand(sBrand.nameEn)">{{sBrand.nameEn}}</li>
  9. </ul>
  10. </div>
  11. <div class="content-line">
  12. <span><i>*</i>物料名称(类目):</span>
  13. <input type="text" v-model="applyObj.prodTitle" @blur="checkProdTitle" @input="onProdTitleInput">
  14. </div>
  15. <div class="content-line">
  16. <span><i>*</i>型号:</span>
  17. <input type="text" v-model="applyObj.code" @blur="checkCode" @input="onCodeChange" placeholder="请勿填中文符号">
  18. <ul class="similar" v-show="showSimilarCodeList && applyObj.code">
  19. <li v-for="sCode in similarCode" @click="setCode(sCode.code)">{{sCode.code}}</li>
  20. </ul>
  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="authorityInterceptor(baseUrls.userPublishSeek, goPublish)">确认发布</a>
  58. </div>
  59. </template>
  60. <script>
  61. export default {
  62. props: ['dataObj'],
  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. console.log('12', this.applyObj)
  136. if (this.checkAll()) {
  137. this.getMaterialKind(this.applyObj.code, this.applyObj.brand).then(response => {
  138. let inquiry = {}
  139. let inquiryItem = {}
  140. if (this.user.data.enterprise) {
  141. inquiry.enUU = this.user.data.enterprise.uu
  142. }
  143. let date = new Date()
  144. let endDate = this.baseUtils.formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  145. // let currency = this.applyObj.currency === '不限' ? null : this.applyObj.currency
  146. let currency = null
  147. inquiry.recorderUU = this.user.data.userUU
  148. inquiry.code = 'MALL' + date.getTime()
  149. inquiry.date = date
  150. inquiry.recorder = this.user.data.userName
  151. inquiry.endDate = endDate
  152. inquiry.sourceapp = 'MALL'
  153. inquiry.amount = 1
  154. inquiryItem.prodTitle = response.data && response.data.length ? response.data : this.applyObj.prodTitle
  155. inquiryItem.userUU = this.user.data.userUU
  156. inquiryItem.source = 'MALL'
  157. inquiryItem.userName = this.user.data.userName
  158. inquiryItem.userTel = this.user.data.userTel
  159. inquiryItem.needquantity = this.applyObj.amount
  160. inquiryItem.inbrand = this.applyObj.brand
  161. inquiryItem.spec = this.applyObj.spec
  162. inquiryItem.custCurrency = currency
  163. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  164. inquiryItem.unitPrice = this.applyObj.unitPrice
  165. inquiryItem.produceDate = null
  166. inquiryItem.date = date
  167. inquiryItem.endDate = endDate
  168. inquiryItem.encapsulation = this.applyObj.encapsulation
  169. let inquiryItems = []
  170. inquiryItems.push(inquiryItem)
  171. inquiry.inquiryItems = inquiryItems
  172. inquiry.currency = currency
  173. this.$http.post('/inquiry/buyer/save', inquiry)
  174. .then(response => {
  175. this.setRemindText('发布成功')
  176. this.emptyForm()
  177. this.$emit('reloadAction')
  178. }, error => {
  179. console.log(error)
  180. this.setRemindText('发布失败')
  181. })
  182. })
  183. } else {
  184. if (!this.validObj.code) {
  185. this.setRemindText('型号不能为空')
  186. } else if (!this.validObj.brand) {
  187. this.setRemindText('品牌不能为空')
  188. } else if (!this.validObj.deadline) {
  189. this.setRemindText('截止日期不能为空')
  190. } else if (!this.validObj.amount) {
  191. this.setRemindText('请输入正确的数值')
  192. }
  193. }
  194. },
  195. setCurrency: function (type) {
  196. this.applyObj.currency = type
  197. },
  198. isValidDate: function (date) {
  199. let now = new Date(this.baseUtils.formatDate(new Date(), 'yyyy-MM-dd')).getTime()
  200. let time = new Date(date).getTime()
  201. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 90)
  202. },
  203. deadlineChange: function () {
  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. return this.checkBrand() && this.checkProdTitle() && this.checkCode() && this.checkDeadline() && this.checkSpec() && this.checkAmount()
  214. },
  215. checkCode: function () {
  216. this.validObj.code = this.applyObj.code && this.applyObj.code !== ''
  217. if (!this.validObj.code) {
  218. this.setRemindText('型号不能为空')
  219. }
  220. return this.validObj.code
  221. },
  222. checkBrand: function () {
  223. this.validObj.brand = this.applyObj.brand && this.applyObj.brand !== ''
  224. if (!this.validObj.brand) {
  225. this.setRemindText('品牌不能为空')
  226. }
  227. return this.validObj.brand
  228. },
  229. checkProdTitle: function () {
  230. let prodTitle = this.applyObj.prodTitle.trim()
  231. this.validObj.prodTitle = prodTitle && prodTitle !== ''
  232. if (!this.validObj.prodTitle) {
  233. this.setRemindText('物料名称(类目)不能为空')
  234. }
  235. return this.validObj.prodTitle
  236. },
  237. checkSpec: function () {
  238. let nullStrFlag = this.baseUtils.checkNullStr(this.applyObj.spec)
  239. this.validObj.spec = nullStrFlag
  240. if (!nullStrFlag) {
  241. this.setRemindText('规格输入不合法')
  242. }
  243. return this.validObj.spec
  244. },
  245. checkAmount: function () {
  246. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  247. return this.validObj.amount
  248. },
  249. checkDeadline: function () {
  250. this.validObj.deadline = Boolean(this.applyObj.deadline)
  251. return this.validObj.deadline
  252. },
  253. onProduceDateChange: function () {
  254. if (this.applyObj.produceDate && this.baseUtils.getRealLen(this.applyObj.produceDate) > 12) {
  255. this.applyObj.produceDate = this.baseUtils.cutOutString(this.applyObj.produceDate, 12)
  256. }
  257. },
  258. getSimilarCode: function () {
  259. if (this.applyObj.code) {
  260. this.$http.get('/search/similarComponents', {params: {keyword: this.applyObj.code}})
  261. .then(response => {
  262. this.similarCode = response.data
  263. this.showSimilarCodeList = response.data.length > 0
  264. })
  265. } else {
  266. this.showSimilarCodeList = false
  267. }
  268. },
  269. getSimilarBrand: function () {
  270. if (this.applyObj.brand) {
  271. this.$http.get('/search/similarBrands', {params: {keyword: this.applyObj.brand}})
  272. .then(response => {
  273. this.similarBrand = response.data
  274. this.showSimilarBrandList = response.data.length > 0
  275. })
  276. } else {
  277. this.showSimilarBrandList = false
  278. }
  279. },
  280. onCodeChange: function () {
  281. this.applyObj.code = this.applyObj.code.trim()
  282. if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
  283. let chineseIndex = -1
  284. for (let i = 0; i < this.applyObj.code.length; i++) {
  285. if ((/[^\x00-\xff]/g).test(this.applyObj.code.charAt(i))) {
  286. chineseIndex = i
  287. break
  288. }
  289. }
  290. this.applyObj.code = this.baseUtils.cutOutString(this.applyObj.code, chineseIndex)
  291. } else if (this.applyObj.code && this.baseUtils.getRealLen(this.applyObj.code) > 100) {
  292. this.applyObj.code = this.baseUtils.cutOutString(this.applyObj.code, 100)
  293. } else {
  294. this.getSimilarCode()
  295. }
  296. },
  297. onBrandChange: function () {
  298. this.applyObj.brand = this.applyObj.brand.trim()
  299. if ((/[^\x00-\xff]/g).test(this.applyObj.brand)) {
  300. let chineseIndex = -1
  301. for (let i = 0; i < this.applyObj.brand.length; i++) {
  302. if ((/[^\x00-\xff]/g).test(this.applyObj.brand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.applyObj.brand.charAt(i))) {
  303. chineseIndex = i
  304. break
  305. }
  306. }
  307. if (chineseIndex > -1) {
  308. this.applyObj.brand = this.applyObj.brand.substring(0, chineseIndex)
  309. }
  310. } else if (this.applyObj.brand && this.baseUtils.getRealLen(this.applyObj.brand) > 50) {
  311. this.applyObj.brand = this.baseUtils.cutOutString(this.applyObj.brand, 50)
  312. } else {
  313. this.getSimilarBrand()
  314. }
  315. },
  316. onProdTitleInput: function () {
  317. if (this.applyObj.prodTitle && this.baseUtils.getRealLen(this.applyObj.prodTitle) > 40) {
  318. this.applyObj.prodTitle = this.baseUtils.cutOutString(this.applyObj.prodTitle, 40)
  319. }
  320. },
  321. onSpecInput: function () {
  322. if (this.applyObj.spec && this.baseUtils.getRealLen(this.applyObj.spec) > 100) {
  323. this.applyObj.spec = this.baseUtils.cutOutString(this.applyObj.spec, 100)
  324. }
  325. },
  326. onAmountInput: function () {
  327. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  328. let chineseIndex = -1
  329. for (let i = 0; i < this.applyObj.amount.length; i++) {
  330. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  331. chineseIndex = i
  332. break
  333. }
  334. }
  335. this.applyObj.amount = this.baseUtils.cutOutString(this.applyObj.amount, chineseIndex)
  336. } else if (this.applyObj.amount.length > 9) {
  337. this.applyObj.amount = this.baseUtils.cutOutString(this.applyObj.amount, 9)
  338. }
  339. },
  340. setCode: function (code) {
  341. this.applyObj.code = code
  342. this.showSimilarCodeList = false
  343. },
  344. setBrand: function (brand) {
  345. this.applyObj.brand = brand
  346. this.showSimilarBrandList = false
  347. }
  348. }
  349. }
  350. </script>
  351. <style lang="scss" scoped>
  352. .publish_seek_mobile{
  353. padding:.2rem;
  354. .publish-seek {
  355. background: #fff;
  356. padding: .1rem;
  357. border-radius:.1rem;
  358. .content-line {
  359. position: relative;
  360. height: 1rem;
  361. line-height: 1rem;
  362. font-size: .26rem;
  363. text-align: left;
  364. border-bottom:1px solid #d3d3d3;
  365. &:last-child{
  366. border:none;
  367. }
  368. input {
  369. width: 3.49rem;
  370. height: .52rem;
  371. border: none;
  372. font-size: .26rem;
  373. vertical-align: middle;
  374. background: #fff;
  375. border-radius: 0;
  376. }
  377. > span {
  378. display: inline-block;
  379. width: 2.5rem;
  380. text-align: right;
  381. color:#3176e9;
  382. i {
  383. color: #ff0000;
  384. margin-right: .05rem;
  385. font-style: normal;
  386. }
  387. }
  388. > a {
  389. font-size: .26rem;
  390. color: #666;
  391. }
  392. > img {
  393. width: .12rem;
  394. height: .06rem;
  395. margin-left: .04rem;
  396. }
  397. .similar {
  398. position: absolute;
  399. width: 3.52rem;
  400. max-height: 2.5rem;
  401. overflow-y: auto;
  402. z-index: 12;
  403. border: 1px solid #7e7e7e;
  404. border-radius: .05rem;
  405. left: 2.25rem;
  406. top: .7rem;
  407. background: #fff;
  408. li {
  409. height: .5rem;
  410. line-height: .5rem;
  411. font-size: .26rem;
  412. color: #999;
  413. padding-left: .19rem;
  414. &:focus, &:active, &:hover {
  415. background: #999;
  416. color: #fff;
  417. }
  418. }
  419. }
  420. }
  421. }
  422. > a {
  423. display: block;
  424. width: 5.19rem;
  425. height: .84rem;
  426. text-align: center;
  427. line-height: .84rem;
  428. font-size: .38rem;
  429. margin: .3rem auto 0;
  430. background: #3176e9;
  431. color: #fff;
  432. border-radius: .08rem;
  433. }
  434. }
  435. .datepicker-overlay {
  436. z-index: 9999;
  437. .cov-date-body {
  438. width: 4rem;
  439. font-size: .16rem;
  440. .cov-date-monthly {
  441. height: 1.5rem;
  442. div {
  443. height: 1.5rem;
  444. }
  445. .cov-date-caption {
  446. font-size: .24rem;
  447. padding: .5rem 0 !important;
  448. }
  449. .cov-date-next {
  450. text-indent: -3rem;
  451. }
  452. }
  453. .cov-date-box {
  454. .cov-picker-box {
  455. padding: .25rem;
  456. width: 4rem;
  457. height: 2.8rem;
  458. .week {
  459. ul {
  460. margin: 0 0 .08rem;
  461. }
  462. }
  463. .day {
  464. height: .34rem;
  465. line-height: .34rem;
  466. }
  467. }
  468. }
  469. }
  470. .button-box {
  471. height: .5rem;
  472. line-height: .5rem;
  473. padding-right: .2rem;
  474. span {
  475. padding: .1rem .2rem;
  476. }
  477. }
  478. }
  479. </style>