PublishSeek.vue 15 KB

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