PublishSeek.vue 17 KB

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