PublishSeek.vue 15 KB

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