PublishSeek.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. import { formatDate, getRealLen, cutOutString } from '~utils/baseUtils'
  51. export default {
  52. props: ['showSayPriceBox'],
  53. data () {
  54. return {
  55. applyObj: {
  56. code: '',
  57. brand: '',
  58. unitPrice: '',
  59. currency: '不限',
  60. encapsulation: '',
  61. produceDate: '',
  62. amount: '',
  63. deadline: ''
  64. },
  65. validObj: {
  66. code: true,
  67. brand: true,
  68. unitPrice: true,
  69. amount: true,
  70. deadline: true
  71. },
  72. showCurrencyList: false
  73. }
  74. },
  75. computed: {
  76. user () {
  77. return this.$store.state.option.user
  78. },
  79. minDay: function () {
  80. return formatDate(new Date(), 'yyyy-MM-dd')
  81. },
  82. maxDay: function () {
  83. let deadDate = new Date().getTime() + 1000 * 60 * 60 * 24 * 90
  84. deadDate = formatDate(new Date(deadDate), 'yyyy-MM-dd')
  85. return deadDate
  86. }
  87. },
  88. watch: {
  89. showSayPriceBox: function (val, old) {
  90. if (val) {
  91. document.body.style.position = 'fixed'
  92. document.body.style.left = '0'
  93. document.body.style.right = '0'
  94. } else {
  95. document.body.style.position = 'relative'
  96. }
  97. }
  98. },
  99. methods: {
  100. cancel: function () {
  101. this.$emit('cancelAction')
  102. },
  103. emptyForm: function () {
  104. for (let attr in this.applyObj) {
  105. this.applyObj[attr] = attr === 'currency' ? '不限' : ''
  106. }
  107. },
  108. setRemindText: function (str) {
  109. this.$emit('remindAction', str)
  110. },
  111. setShowCurrencyList: function (flag, e) {
  112. if (e) {
  113. e.stopPropagation()
  114. }
  115. this.showCurrencyList = flag
  116. },
  117. getMaterialKind: function (code, brand) {
  118. return this.$http.get('/productuser/match/getKind', {params: {cmpCode: code, brand: brand}})
  119. },
  120. goPublish: function () {
  121. if (this.checkAll()) {
  122. this.getMaterialKind(this.applyObj.code, this.applyObj.brand).then(response => {
  123. let inquiry = {}
  124. let inquiryItem = {}
  125. if (this.user.data.enterprise) {
  126. inquiry.enUU = this.user.data.enterprise.uu
  127. }
  128. let date = new Date()
  129. let endDate = formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  130. // let currency = this.applyObj.currency === '不限' ? null : this.applyObj.currency
  131. let currency = null
  132. inquiry.recorderUU = this.user.data.userUU
  133. inquiry.code = 'MALL' + date.getTime()
  134. inquiry.date = date
  135. inquiry.recorder = this.user.data.userName
  136. inquiry.endDate = endDate
  137. inquiry.sourceapp = 'MALL'
  138. inquiry.amount = 1
  139. inquiryItem.prodTitle = response.data && response.data.length ? response.data : '其他'
  140. inquiryItem.userUU = this.user.data.userUU
  141. inquiryItem.source = 'MALL'
  142. inquiryItem.userName = this.user.data.userName
  143. inquiryItem.userTel = this.user.data.userTel
  144. inquiryItem.needquantity = this.applyObj.amount
  145. inquiryItem.inbrand = this.applyObj.brand
  146. inquiryItem.custCurrency = currency
  147. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  148. inquiryItem.unitPrice = this.applyObj.unitPrice
  149. inquiryItem.produceDate = null
  150. inquiryItem.date = date
  151. inquiryItem.endDate = endDate
  152. inquiryItem.encapsulation = this.applyObj.encapsulation
  153. let inquiryItems = []
  154. inquiryItems.push(inquiryItem)
  155. inquiry.inquiryItems = inquiryItems
  156. inquiry.currency = currency
  157. this.$http.post('/inquiry/buyer/save', inquiry)
  158. .then(response => {
  159. // this.$message.success('发布成功')
  160. this.setRemindText('发布成功')
  161. // this.showRemindBox = true
  162. this.emptyForm()
  163. // this.validObj.deadline = true
  164. this.$emit('reloadAction')
  165. this.cancel()
  166. }, error => {
  167. console.log(error)
  168. // this.$message.error('发布失败')
  169. this.setRemindText('发布失败')
  170. })
  171. })
  172. } else {
  173. if (!this.validObj.code) {
  174. this.setRemindText('型号不能为空')
  175. } else if (!this.validObj.brand) {
  176. this.setRemindText('品牌不能为空')
  177. } else if (!this.validObj.deadline) {
  178. this.setRemindText('截止日期不能为空')
  179. } else if (!this.validObj.amount) {
  180. this.setRemindText('请输入正确的数值')
  181. }
  182. }
  183. },
  184. setCurrency: function (type) {
  185. this.applyObj.currency = type
  186. },
  187. isValidDate: function (date) {
  188. let now = new Date(formatDate(new Date(), 'yyyy-MM-dd')).getTime()
  189. let time = new Date(date).getTime()
  190. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 91)
  191. },
  192. deadlineChange: function () {
  193. if (!this.isValidDate(this.applyObj.deadline)) {
  194. this.setRemindText('日期需不小于今天且在90天以内')
  195. this.applyObj.deadline = ''
  196. this.validObj.deadline = false
  197. } else {
  198. this.validObj.deadline = true
  199. }
  200. },
  201. checkAll: function () {
  202. return this.checkCode() && this.checkBrand() && this.checkDeadline() && this.checkAmount()
  203. },
  204. checkCode: function () {
  205. this.validObj.code = this.applyObj.code && this.applyObj.code !== ''
  206. if (!this.validObj.code) {
  207. this.setRemindText('型号不能为空')
  208. }
  209. return this.validObj.code
  210. },
  211. checkBrand: function () {
  212. this.validObj.brand = this.applyObj.brand && this.applyObj.brand !== ''
  213. if (!this.validObj.brand) {
  214. this.setRemindText('品牌不能为空')
  215. }
  216. return this.validObj.brand
  217. },
  218. checkAmount: function () {
  219. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  220. return this.validObj.amount
  221. },
  222. checkDeadline: function () {
  223. this.validObj.deadline = Boolean(this.applyObj.deadline)
  224. return this.validObj.deadline
  225. },
  226. onProduceDateChange: function () {
  227. if (this.applyObj.produceDate && getRealLen(this.applyObj.produceDate) > 12) {
  228. this.applyObj.produceDate = cutOutString(this.applyObj.produceDate, 12)
  229. }
  230. },
  231. onCodeChange: function () {
  232. this.applyObj.code = this.applyObj.code.trim()
  233. if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
  234. let chineseIndex = -1
  235. for (let i = 0; i < this.applyObj.code.length; i++) {
  236. if ((/[^\x00-\xff]/g).test(this.applyObj.code.charAt(i))) {
  237. chineseIndex = i
  238. break
  239. }
  240. }
  241. this.applyObj.code = cutOutString(this.applyObj.code, chineseIndex)
  242. } else if (this.applyObj.code && getRealLen(this.applyObj.code) > 100) {
  243. this.applyObj.code = cutOutString(this.applyObj.code, 100)
  244. }
  245. },
  246. onBrandChange: function () {
  247. this.applyObj.brand = this.applyObj.brand.trim()
  248. if ((/[^\x00-\xff]/g).test(this.applyObj.brand)) {
  249. let chineseIndex = -1
  250. for (let i = 0; i < this.applyObj.brand.length; i++) {
  251. if ((/[^\x00-\xff]/g).test(this.applyObj.brand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.applyObj.brand.charAt(i))) {
  252. chineseIndex = i
  253. break
  254. }
  255. }
  256. if (chineseIndex > -1) {
  257. this.applyObj.brand = this.applyObj.brand.substring(0, chineseIndex)
  258. }
  259. } else if (this.applyObj.brand && getRealLen(this.applyObj.brand) > 50) {
  260. this.applyObj.brand = cutOutString(this.applyObj.brand, 50)
  261. }
  262. },
  263. onAmountInput: function () {
  264. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  265. let chineseIndex = -1
  266. for (let i = 0; i < this.applyObj.amount.length; i++) {
  267. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  268. chineseIndex = i
  269. break
  270. }
  271. }
  272. this.applyObj.amount = cutOutString(this.applyObj.amount, chineseIndex)
  273. } else if (this.applyObj.amount.length > 9) {
  274. this.applyObj.amount = cutOutString(this.applyObj.amount, 9)
  275. }
  276. }
  277. }
  278. }
  279. </script>
  280. <style lang="scss" scoped>
  281. .mobile-modal {
  282. .mobile-modal-box {
  283. position: fixed;
  284. width: 5.92rem;
  285. font-size: .28rem;
  286. top: 50%;
  287. left: 50%;
  288. right: 11%;
  289. z-index: 1000;
  290. margin-top: -3.7rem;
  291. margin-left: -2.96rem;
  292. .mobile-modal-header {
  293. font-size: .38rem;
  294. }
  295. .publish-seek {
  296. background: #fff;
  297. padding-top: .1rem;
  298. padding-bottom: .4rem;
  299. .content-line {
  300. position: relative;
  301. height: .8rem;
  302. line-height: .8rem;
  303. font-size: .26rem;
  304. text-align: left;
  305. input {
  306. width: 3.49rem;
  307. height: .52rem;
  308. line-height: normal;
  309. padding: .1rem .19rem;
  310. border: 1px solid #7e7e7e;
  311. font-size: .26rem;
  312. vertical-align: middle;
  313. background: #fff;
  314. border-radius: 0;
  315. }
  316. > span {
  317. display: inline-block;
  318. width: 1.76rem;
  319. text-align: right;
  320. i {
  321. color: #ff0000;
  322. margin-right: .05rem;
  323. font-style: normal;
  324. }
  325. }
  326. > a {
  327. font-size: .26rem;
  328. color: #666;
  329. }
  330. > img {
  331. width: .12rem;
  332. height: .06rem;
  333. margin-left: .04rem;
  334. }
  335. > ul {
  336. position: absolute;
  337. top: .6rem;
  338. left: 1.16rem;
  339. z-index: 1;
  340. width: 1.75rem;
  341. background: #fff;
  342. text-align: center;
  343. border-radius: .1rem;
  344. border: .02rem solid #dfdfdf;
  345. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  346. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  347. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  348. li {
  349. height: .52rem;
  350. line-height: .52rem;
  351. border-bottom: .02rem solid #dfdfdf;
  352. &:hover, &:active {
  353. background: #dedede;
  354. }
  355. }
  356. }
  357. }
  358. > a {
  359. display: block;
  360. width: 5.19rem;
  361. height: .84rem;
  362. text-align: center;
  363. line-height: .84rem;
  364. font-size: .38rem;
  365. margin: .3rem auto 0;
  366. background: #3f84f6;
  367. color: #fff;
  368. border-radius: .08rem;
  369. }
  370. }
  371. }
  372. }
  373. .datepicker-overlay {
  374. z-index: 9999;
  375. .cov-date-body {
  376. width: 4rem;
  377. font-size: .16rem;
  378. .cov-date-monthly {
  379. height: 1.5rem;
  380. div {
  381. height: 1.5rem;
  382. }
  383. .cov-date-caption {
  384. font-size: .24rem;
  385. padding: .5rem 0 !important;
  386. }
  387. .cov-date-next {
  388. text-indent: -3rem;
  389. }
  390. }
  391. .cov-date-box {
  392. .cov-picker-box {
  393. padding: .25rem;
  394. width: 4rem;
  395. height: 2.8rem;
  396. .week {
  397. ul {
  398. margin: 0 0 .08rem;
  399. }
  400. }
  401. .day {
  402. height: .34rem;
  403. line-height: .34rem;
  404. }
  405. }
  406. }
  407. }
  408. .button-box {
  409. height: .5rem;
  410. line-height: .5rem;
  411. padding-right: .2rem;
  412. span {
  413. padding: .1rem .2rem;
  414. }
  415. }
  416. }
  417. </style>