PublishSeek.vue 14 KB

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