PublishSeek.vue 18 KB

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