PublishSeek.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="mobile-modal" v-if="showSayPriceBox" @click="setShowCurrencyList(false)">
  3. <div class="mobile-modal-box">
  4. <div class="mobile-modal-header">发布求购<i class="icon-guanbi iconfont" @click="cancel"></i></div>
  5. <div class="publish-seek">
  6. <div class="content-line">
  7. <span><i>*</i>型号:</span>
  8. <input type="text" v-model="applyObj.code" @blur="checkCode" @input="onCodeChange" placeholder="请勿填中文符号">
  9. </div>
  10. <div class="content-line">
  11. <span><i>*</i>品牌:</span>
  12. <input type="text" v-model="applyObj.brand" @blur="checkBrand" @input="onBrandChange" placeholder="请勿填中文符号">
  13. </div>
  14. <div class="content-line">
  15. <span><i>*</i>截止日期:</span>
  16. <input type="date" v-model="applyObj.deadline" :min="minDay" :max="maxDay" @blur="deadlineChange">
  17. <!--<el-date-picker-->
  18. <!--v-model="applyObj.deadline"-->
  19. <!--type="date"-->
  20. <!--:editable="false"-->
  21. <!--:clearable="true"-->
  22. <!--size="mini">-->
  23. <!--</el-date-picker>-->
  24. </div>
  25. <!--<div class="content-line">
  26. <span>币种:</span>
  27. <a v-text="applyObj.currency" @click="setShowCurrencyList(!showCurrencyList, $event)"></a>
  28. <img v-if="!showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-down.png" alt="">
  29. <img v-if="showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-up.png" alt="">
  30. <ul v-if="showCurrencyList">
  31. <li @click="setCurrency('不限')">不限</li>
  32. <li @click="setCurrency('RMB')">RMB</li>
  33. <li @click="setCurrency('USD')">USD</li>
  34. </ul>
  35. </div>-->
  36. <div class="content-line">
  37. <span>数量:</span>
  38. <input type="text" v-model="applyObj.amount" @blur="checkAmount" @input="onAmountInput">
  39. </div>
  40. <!--<div class="content-line">
  41. <span>生产日期:</span>
  42. <input type="text" v-model="applyObj.produceDate" @input="onProduceDateChange">
  43. </div>-->
  44. <a @click="goPublish">确认发布</a>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. let formatDate = function (date, fmt) {
  51. if (typeof date === 'string') {
  52. date = new Date(Date.parse(date.replace(/-/g, '/')))
  53. }
  54. let o = {
  55. 'M+': date.getMonth() + 1, // 月份
  56. 'd+': date.getDate(), // 日
  57. 'h+': 23, // 小时
  58. 'm+': 59, // 分
  59. 's+': 59, // 秒
  60. 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
  61. 'S': date.getMilliseconds() // 毫秒
  62. }
  63. if (/(y+)/.test(fmt)) {
  64. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  65. }
  66. for (let k in o) {
  67. if (new RegExp('(' + k + ')').test(fmt)) {
  68. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
  69. }
  70. }
  71. return fmt
  72. }
  73. let getRealLen = function (str) {
  74. let len = 0
  75. for (let i = 0; i < str.length; i++) {
  76. if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
  77. len += 2
  78. } else {
  79. len++
  80. }
  81. }
  82. return len
  83. }
  84. let cutOutString = function (str, length) {
  85. for (let i = 1; i <= str.length; i++) {
  86. if (getRealLen(str.substr(0, i)) > length) {
  87. str = str.substr(0, i - 1)
  88. break
  89. }
  90. }
  91. return str
  92. }
  93. export default {
  94. props: ['showSayPriceBox'],
  95. data () {
  96. return {
  97. applyObj: {
  98. code: '',
  99. brand: '',
  100. unitPrice: '',
  101. currency: '不限',
  102. encapsulation: '',
  103. produceDate: '',
  104. amount: '',
  105. deadline: ''
  106. },
  107. validObj: {
  108. code: true,
  109. brand: true,
  110. unitPrice: true,
  111. amount: true,
  112. deadline: true
  113. },
  114. showCurrencyList: false
  115. }
  116. },
  117. computed: {
  118. user () {
  119. return this.$store.state.option.user
  120. },
  121. minDay: function () {
  122. return formatDate(new Date(), 'yyyy-MM-dd')
  123. },
  124. maxDay: function () {
  125. let deadDate = new Date()
  126. deadDate.setMonth(deadDate.getMonth() + 3)
  127. deadDate.setDate(deadDate.getDate() + 1)
  128. deadDate = formatDate(deadDate, 'yyyy-MM-dd')
  129. return deadDate
  130. }
  131. },
  132. watch: {
  133. showSayPriceBox: function (val, old) {
  134. if (val) {
  135. document.body.style.position = 'fixed'
  136. document.body.style.left = '0'
  137. document.body.style.right = '0'
  138. } else {
  139. document.body.style.position = 'relative'
  140. }
  141. }
  142. },
  143. methods: {
  144. cancel: function () {
  145. this.$emit('cancelAction')
  146. },
  147. emptyForm: function () {
  148. for (let attr in this.applyObj) {
  149. this.applyObj[attr] = attr === 'currency' ? '不限' : ''
  150. }
  151. },
  152. setRemindText: function (str) {
  153. this.$emit('remindAction', str)
  154. },
  155. setShowCurrencyList: function (flag, e) {
  156. if (e) {
  157. e.stopPropagation()
  158. }
  159. this.showCurrencyList = flag
  160. },
  161. getMaterialKind: function (code, brand) {
  162. return this.$http.get('/productuser/match/getKind', {params: {cmpCode: code, brand: brand}})
  163. },
  164. goPublish: function () {
  165. if (this.checkAll()) {
  166. this.getMaterialKind(this.applyObj.code, this.applyObj.brand).then(response => {
  167. let inquiry = {}
  168. let inquiryItem = {}
  169. if (this.user.data.enterprise) {
  170. inquiry.enUU = this.user.data.enterprise.uu
  171. }
  172. let date = new Date()
  173. let endDate = formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  174. // let currency = this.applyObj.currency === '不限' ? null : this.applyObj.currency
  175. let currency = null
  176. inquiry.recorderUU = this.user.data.userUU
  177. inquiry.code = 'MALL' + date.getTime()
  178. inquiry.date = date
  179. inquiry.recorder = this.user.data.userName
  180. inquiry.endDate = endDate
  181. inquiry.sourceapp = 'MALL'
  182. inquiry.amount = 1
  183. inquiryItem.prodTitle = response.data && response.data.length ? response.data : '其他'
  184. inquiryItem.userUU = this.user.data.userUU
  185. inquiryItem.source = 'MALL'
  186. inquiryItem.userName = this.user.data.userName
  187. inquiryItem.userTel = this.user.data.userTel
  188. inquiryItem.needquantity = this.applyObj.amount
  189. inquiryItem.inbrand = this.applyObj.brand
  190. inquiryItem.custCurrency = currency
  191. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  192. inquiryItem.unitPrice = this.applyObj.unitPrice
  193. inquiryItem.produceDate = null
  194. inquiryItem.date = date
  195. inquiryItem.endDate = endDate
  196. inquiryItem.encapsulation = this.applyObj.encapsulation
  197. let inquiryItems = []
  198. inquiryItems.push(inquiryItem)
  199. inquiry.inquiryItems = inquiryItems
  200. inquiry.currency = currency
  201. this.$http.post('/inquiry/buyer/save', inquiry)
  202. .then(response => {
  203. // this.$message.success('发布成功')
  204. this.setRemindText('发布成功')
  205. // this.showRemindBox = true
  206. this.emptyForm()
  207. // this.validObj.deadline = true
  208. this.$emit('reloadAction')
  209. this.cancel()
  210. }, error => {
  211. console.log(error)
  212. // this.$message.error('发布失败')
  213. this.setRemindText('发布失败')
  214. })
  215. })
  216. } else {
  217. if (!this.validObj.code) {
  218. this.setRemindText('型号不能为空')
  219. } else if (!this.validObj.brand) {
  220. this.setRemindText('品牌不能为空')
  221. } else if (!this.validObj.deadline) {
  222. this.setRemindText('截止日期不能为空')
  223. } else if (!this.validObj.amount) {
  224. this.setRemindText('请输入正确的数值')
  225. }
  226. }
  227. },
  228. setCurrency: function (type) {
  229. this.applyObj.currency = type
  230. },
  231. isValidDate: function (date) {
  232. let now = new Date(formatDate(new Date(), 'yyyy-MM-dd')).getTime()
  233. let time = new Date(date).getTime()
  234. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 91)
  235. },
  236. deadlineChange: function () {
  237. if (!this.isValidDate(this.applyObj.deadline)) {
  238. this.setRemindText('日期需不小于今天且在90天以内')
  239. this.applyObj.deadline = ''
  240. this.validObj.deadline = false
  241. } else {
  242. this.validObj.deadline = true
  243. }
  244. },
  245. checkAll: function () {
  246. return this.checkCode() && this.checkBrand() && this.checkDeadline() && this.checkAmount()
  247. },
  248. checkCode: function () {
  249. this.validObj.code = this.applyObj.code && this.applyObj.code !== ''
  250. if (!this.validObj.code) {
  251. this.setRemindText('型号不能为空')
  252. }
  253. return this.validObj.code
  254. },
  255. checkBrand: function () {
  256. this.validObj.brand = this.applyObj.brand && this.applyObj.brand !== ''
  257. if (!this.validObj.brand) {
  258. this.setRemindText('品牌不能为空')
  259. }
  260. return this.validObj.brand
  261. },
  262. checkAmount: function () {
  263. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  264. return this.validObj.amount
  265. },
  266. checkDeadline: function () {
  267. this.validObj.deadline = Boolean(this.applyObj.deadline)
  268. return this.validObj.deadline
  269. },
  270. onProduceDateChange: function () {
  271. if (this.applyObj.produceDate && getRealLen(this.applyObj.produceDate) > 12) {
  272. this.applyObj.produceDate = cutOutString(this.applyObj.produceDate, 12)
  273. }
  274. },
  275. onCodeChange: function () {
  276. this.applyObj.code = this.applyObj.code.trim()
  277. if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
  278. let chineseIndex = -1
  279. for (let i = 0; i < this.applyObj.code.length; i++) {
  280. if ((/[^\x00-\xff]/g).test(this.applyObj.code.charAt(i))) {
  281. chineseIndex = i
  282. break
  283. }
  284. }
  285. this.applyObj.code = cutOutString(this.applyObj.code, chineseIndex)
  286. } else if (this.applyObj.code && getRealLen(this.applyObj.code) > 100) {
  287. this.applyObj.code = cutOutString(this.applyObj.code, 100)
  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. }
  306. },
  307. onAmountInput: function () {
  308. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  309. let chineseIndex = -1
  310. for (let i = 0; i < this.applyObj.amount.length; i++) {
  311. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  312. chineseIndex = i
  313. break
  314. }
  315. }
  316. this.applyObj.amount = cutOutString(this.applyObj.amount, chineseIndex)
  317. } else if (this.applyObj.amount.length > 9) {
  318. this.applyObj.amount = cutOutString(this.applyObj.amount, 9)
  319. }
  320. }
  321. }
  322. }
  323. </script>
  324. <style lang="scss" scoped>
  325. .mobile-modal {
  326. .mobile-modal-box {
  327. position: fixed;
  328. width: 5.92rem;
  329. font-size: .28rem;
  330. top: 50%;
  331. left: 50%;
  332. right: 11%;
  333. z-index: 1000;
  334. margin-top: -3.7rem;
  335. margin-left: -2.96rem;
  336. .mobile-modal-header {
  337. font-size: .38rem;
  338. }
  339. .publish-seek {
  340. background: #fff;
  341. padding-top: .1rem;
  342. padding-bottom: .4rem;
  343. .content-line {
  344. position: relative;
  345. height: .8rem;
  346. line-height: .8rem;
  347. font-size: .26rem;
  348. text-align: left;
  349. input {
  350. width: 3.49rem;
  351. height: .52rem;
  352. line-height: normal;
  353. padding: .1rem .19rem;
  354. border: 1px solid #7e7e7e;
  355. font-size: .26rem;
  356. vertical-align: middle;
  357. background: #fff;
  358. border-radius: 0;
  359. }
  360. > span {
  361. display: inline-block;
  362. width: 1.76rem;
  363. text-align: right;
  364. i {
  365. color: #ff0000;
  366. margin-right: .05rem;
  367. font-style: normal;
  368. }
  369. }
  370. > a {
  371. font-size: .26rem;
  372. color: #666;
  373. }
  374. > img {
  375. width: .12rem;
  376. height: .06rem;
  377. margin-left: .04rem;
  378. }
  379. > ul {
  380. position: absolute;
  381. top: .6rem;
  382. left: 1.16rem;
  383. z-index: 1;
  384. width: 1.75rem;
  385. background: #fff;
  386. text-align: center;
  387. border-radius: .1rem;
  388. border: .02rem solid #dfdfdf;
  389. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  390. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  391. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  392. li {
  393. height: .52rem;
  394. line-height: .52rem;
  395. border-bottom: .02rem solid #dfdfdf;
  396. &:hover, &:active {
  397. background: #dedede;
  398. }
  399. }
  400. }
  401. }
  402. > a {
  403. display: block;
  404. width: 5.19rem;
  405. height: .84rem;
  406. text-align: center;
  407. line-height: .84rem;
  408. font-size: .38rem;
  409. margin: .3rem auto 0;
  410. background: #3f84f6;
  411. color: #fff;
  412. border-radius: .08rem;
  413. }
  414. }
  415. }
  416. }
  417. .datepicker-overlay {
  418. z-index: 9999;
  419. .cov-date-body {
  420. width: 4rem;
  421. font-size: .16rem;
  422. .cov-date-monthly {
  423. height: 1.5rem;
  424. div {
  425. height: 1.5rem;
  426. }
  427. .cov-date-caption {
  428. font-size: .24rem;
  429. padding: .5rem 0 !important;
  430. }
  431. .cov-date-next {
  432. text-indent: -3rem;
  433. }
  434. }
  435. .cov-date-box {
  436. .cov-picker-box {
  437. padding: .25rem;
  438. width: 4rem;
  439. height: 2.8rem;
  440. .week {
  441. ul {
  442. margin: 0 0 .08rem;
  443. }
  444. }
  445. .day {
  446. height: .34rem;
  447. line-height: .34rem;
  448. }
  449. }
  450. }
  451. }
  452. .button-box {
  453. height: .5rem;
  454. line-height: .5rem;
  455. padding-right: .2rem;
  456. span {
  457. padding: .1rem .2rem;
  458. }
  459. }
  460. }
  461. </style>