PublishSeek.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. goPublish: function () {
  162. if (this.checkAll()) {
  163. let inquiry = {}
  164. let inquiryItem = {}
  165. if (this.user.data.enterprise) {
  166. inquiry.enUU = this.user.data.enterprise.uu
  167. }
  168. let date = new Date()
  169. let endDate = formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  170. // let currency = this.applyObj.currency === '不限' ? null : this.applyObj.currency
  171. let currency = null
  172. inquiry.recorderUU = this.user.data.userUU
  173. inquiry.code = 'MALL' + date.getTime()
  174. inquiry.date = date
  175. inquiry.recorder = this.user.data.userName
  176. inquiry.endDate = endDate
  177. inquiry.sourceapp = 'MALL'
  178. inquiry.amount = 1
  179. inquiryItem.prodTitle = this.applyObj.code
  180. inquiryItem.userUU = this.user.data.userUU
  181. inquiryItem.source = 'MALL'
  182. inquiryItem.userName = this.user.data.userName
  183. inquiryItem.userTel = this.user.data.userTel
  184. inquiryItem.needquantity = this.applyObj.amount
  185. inquiryItem.inbrand = this.applyObj.brand
  186. inquiryItem.custCurrency = currency
  187. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  188. inquiryItem.unitPrice = this.applyObj.unitPrice
  189. inquiryItem.produceDate = null
  190. inquiryItem.date = date
  191. inquiryItem.endDate = endDate
  192. inquiryItem.encapsulation = this.applyObj.encapsulation
  193. let inquiryItems = []
  194. inquiryItems.push(inquiryItem)
  195. inquiry.inquiryItems = inquiryItems
  196. inquiry.currency = currency
  197. this.$http.post('/inquiry/buyer/save', inquiry)
  198. .then(response => {
  199. // this.$message.success('发布成功')
  200. this.setRemindText('发布成功')
  201. // this.showRemindBox = true
  202. this.emptyForm()
  203. // this.validObj.deadline = true
  204. this.$emit('reloadAction')
  205. this.cancel()
  206. }, error => {
  207. console.log(error)
  208. // this.$message.error('发布失败')
  209. this.setRemindText('发布失败')
  210. })
  211. } else {
  212. if (!this.validObj.code) {
  213. this.setRemindText('型号不能为空')
  214. } else if (!this.validObj.brand) {
  215. this.setRemindText('品牌不能为空')
  216. } else if (!this.validObj.deadline) {
  217. this.setRemindText('截止日期不能为空')
  218. } else if (!this.validObj.amount) {
  219. this.setRemindText('请输入正确的数值')
  220. }
  221. }
  222. },
  223. setCurrency: function (type) {
  224. this.applyObj.currency = type
  225. },
  226. isValidDate: function (date) {
  227. let now = new Date(formatDate(new Date(), 'yyyy-MM-dd')).getTime()
  228. let time = new Date(date).getTime()
  229. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 91)
  230. },
  231. deadlineChange: function () {
  232. if (!this.isValidDate(this.applyObj.deadline)) {
  233. this.setRemindText('日期需不小于今天且在90天以内')
  234. this.applyObj.deadline = ''
  235. this.validObj.deadline = false
  236. } else {
  237. this.validObj.deadline = true
  238. }
  239. },
  240. checkAll: function () {
  241. return this.checkCode() && this.checkBrand() && this.checkDeadline() && this.checkAmount()
  242. },
  243. checkCode: function () {
  244. this.validObj.code = this.applyObj.code && this.applyObj.code !== ''
  245. if (!this.validObj.code) {
  246. this.setRemindText('型号不能为空')
  247. }
  248. return this.validObj.code
  249. },
  250. checkBrand: function () {
  251. this.validObj.brand = this.applyObj.brand && this.applyObj.brand !== ''
  252. if (!this.validObj.brand) {
  253. this.setRemindText('品牌不能为空')
  254. }
  255. return this.validObj.brand
  256. },
  257. checkAmount: function () {
  258. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  259. return this.validObj.amount
  260. },
  261. checkDeadline: function () {
  262. this.validObj.deadline = Boolean(this.applyObj.deadline)
  263. return this.validObj.deadline
  264. },
  265. onProduceDateChange: function () {
  266. if (this.applyObj.produceDate && getRealLen(this.applyObj.produceDate) > 12) {
  267. this.applyObj.produceDate = cutOutString(this.applyObj.produceDate, 12)
  268. }
  269. },
  270. onCodeChange: function () {
  271. this.applyObj.code = this.applyObj.code.trim()
  272. if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
  273. let chineseIndex = -1
  274. for (let i = 0; i < this.applyObj.code.length; i++) {
  275. if ((/[^\x00-\xff]/g).test(this.applyObj.code.charAt(i))) {
  276. chineseIndex = i
  277. break
  278. }
  279. }
  280. this.applyObj.code = cutOutString(this.applyObj.code, chineseIndex)
  281. } else if (this.applyObj.code && getRealLen(this.applyObj.code) > 100) {
  282. this.applyObj.code = cutOutString(this.applyObj.code, 100)
  283. }
  284. },
  285. onBrandChange: function () {
  286. this.applyObj.brand = this.applyObj.brand.trim()
  287. if ((/[^\x00-\xff]/g).test(this.applyObj.brand)) {
  288. let chineseIndex = -1
  289. for (let i = 0; i < this.applyObj.brand.length; i++) {
  290. if ((/[^\x00-\xff]/g).test(this.applyObj.brand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.applyObj.brand.charAt(i))) {
  291. chineseIndex = i
  292. break
  293. }
  294. }
  295. if (chineseIndex > -1) {
  296. this.applyObj.brand = this.applyObj.brand.substring(0, chineseIndex)
  297. }
  298. } else if (this.applyObj.brand && getRealLen(this.applyObj.brand) > 50) {
  299. this.applyObj.brand = cutOutString(this.applyObj.brand, 50)
  300. }
  301. },
  302. onAmountInput: function () {
  303. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  304. let chineseIndex = -1
  305. for (let i = 0; i < this.applyObj.amount.length; i++) {
  306. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  307. chineseIndex = i
  308. break
  309. }
  310. }
  311. this.applyObj.amount = cutOutString(this.applyObj.amount, chineseIndex)
  312. } else if (this.applyObj.amount.length > 9) {
  313. this.applyObj.amount = cutOutString(this.applyObj.amount, 9)
  314. }
  315. }
  316. }
  317. }
  318. </script>
  319. <style lang="scss" scoped>
  320. .mobile-modal {
  321. .mobile-modal-box {
  322. position: fixed;
  323. width: 5.92rem;
  324. font-size: .28rem;
  325. top: 50%;
  326. left: 50%;
  327. right: 11%;
  328. z-index: 1000;
  329. margin-top: -3.7rem;
  330. margin-left: -2.96rem;
  331. .publish-seek {
  332. background: #fff;
  333. padding-top: .1rem;
  334. padding-bottom: .4rem;
  335. .content-line {
  336. position: relative;
  337. height: .8rem;
  338. line-height: .8rem;
  339. font-size: .26rem;
  340. text-align: left;
  341. border-bottom: 1px solid #d0e3fd;
  342. input {
  343. width: 3.49rem;
  344. height: .52rem;
  345. line-height: normal;
  346. padding: .1rem .19rem;
  347. border: 1px solid #7e7e7e;
  348. font-size: .26rem;
  349. vertical-align: middle;
  350. background: #fff;
  351. border-radius: 0;
  352. }
  353. > span {
  354. display: inline-block;
  355. width: 1.76rem;
  356. text-align: right;
  357. i {
  358. color: #ff0000;
  359. margin-right: .05rem;
  360. font-style: normal;
  361. }
  362. }
  363. > a {
  364. font-size: .26rem;
  365. color: #666;
  366. }
  367. > img {
  368. width: .12rem;
  369. height: .06rem;
  370. margin-left: .04rem;
  371. }
  372. > ul {
  373. position: absolute;
  374. top: .6rem;
  375. left: 1.16rem;
  376. z-index: 1;
  377. width: 1.75rem;
  378. background: #fff;
  379. text-align: center;
  380. border-radius: .1rem;
  381. border: .02rem solid #dfdfdf;
  382. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  383. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  384. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  385. li {
  386. height: .52rem;
  387. line-height: .52rem;
  388. border-bottom: .02rem solid #dfdfdf;
  389. &:hover, &:active {
  390. background: #dedede;
  391. }
  392. }
  393. }
  394. }
  395. > a {
  396. display: block;
  397. width: 5.19rem;
  398. height: .84rem;
  399. text-align: center;
  400. line-height: .84rem;
  401. font-size: .38rem;
  402. margin: .3rem auto 0;
  403. background: #3f84f6;
  404. color: #fff;
  405. border-radius: .08rem;
  406. }
  407. }
  408. }
  409. }
  410. .datepicker-overlay {
  411. z-index: 9999;
  412. .cov-date-body {
  413. width: 4rem;
  414. font-size: .16rem;
  415. .cov-date-monthly {
  416. height: 1.5rem;
  417. div {
  418. height: 1.5rem;
  419. }
  420. .cov-date-caption {
  421. font-size: .24rem;
  422. padding: .5rem 0 !important;
  423. }
  424. .cov-date-next {
  425. text-indent: -3rem;
  426. }
  427. }
  428. .cov-date-box {
  429. .cov-picker-box {
  430. padding: .25rem;
  431. width: 4rem;
  432. height: 2.8rem;
  433. .week {
  434. ul {
  435. margin: 0 0 .08rem;
  436. }
  437. }
  438. .day {
  439. height: .34rem;
  440. line-height: .34rem;
  441. }
  442. }
  443. }
  444. }
  445. .button-box {
  446. height: .5rem;
  447. line-height: .5rem;
  448. padding-right: .2rem;
  449. span {
  450. padding: .1rem .2rem;
  451. }
  452. }
  453. }
  454. </style>