PublishSeek.vue 18 KB

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