PublishSeek.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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" placeholder="请勿填中文符号">
  9. </div>
  10. <div class="content-line">
  11. <span><i>*</i>品牌:</span>
  12. <input type="text" v-model="applyObj.brand" placeholder="请勿填中文符号">
  13. </div>
  14. <div class="content-line">
  15. <span><i>*</i>截止日期:</span>
  16. <input type="date" v-model="applyObj.deadline" @change="deadlineChange">
  17. </div>
  18. <div class="content-line">
  19. <span>币种:</span>
  20. <a v-text="applyObj.currency" @click="showCurrencyList = !showCurrencyList"></a>
  21. <img v-if="!showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-down.png" alt="">
  22. <img v-if="showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-up.png" alt="">
  23. <ul v-if="showCurrencyList">
  24. <li @click="setCurrency('RMB')">RMB</li>
  25. <li @click="setCurrency('USD')">USD</li>
  26. </ul>
  27. </div>
  28. <div class="content-line">
  29. <span>数量:</span>
  30. <input type="number" v-model="applyObj.amount">
  31. </div>
  32. <div class="content-line">
  33. <span>生产日期:</span>
  34. <input type="text" v-model="applyObj.produceDate">
  35. </div>
  36. <a @click="goPublish">确认发布</a>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. let formatDate = function (date, fmt) {
  43. if (typeof date === 'string') {
  44. date = new Date(Date.parse(date.replace(/-/g, '/')))
  45. }
  46. let o = {
  47. 'M+': date.getMonth() + 1, // 月份
  48. 'd+': date.getDate(), // 日
  49. 'h+': 23, // 小时
  50. 'm+': 59, // 分
  51. 's+': 59, // 秒
  52. 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
  53. 'S': date.getMilliseconds() // 毫秒
  54. }
  55. if (/(y+)/.test(fmt)) {
  56. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  57. }
  58. for (let k in o) {
  59. if (new RegExp('(' + k + ')').test(fmt)) {
  60. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
  61. }
  62. }
  63. return fmt
  64. }
  65. let getRealLen = function (str) {
  66. let len = 0
  67. for (let i = 0; i < str.length; i++) {
  68. if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
  69. len += 2
  70. } else {
  71. len++
  72. }
  73. }
  74. return len
  75. }
  76. export default {
  77. props: ['showSayPriceBox'],
  78. data () {
  79. return {
  80. applyObj: {
  81. code: '',
  82. brand: '',
  83. unitPrice: '',
  84. currency: 'RMB',
  85. encapsulation: '',
  86. produceDate: '',
  87. amount: '',
  88. deadline: ''
  89. },
  90. showCurrencyList: false
  91. }
  92. },
  93. computed: {
  94. user () {
  95. return this.$store.state.option.user
  96. }
  97. },
  98. methods: {
  99. cancel: function () {
  100. this.$emit('cancelAction')
  101. },
  102. emptyForm: function () {
  103. for (let attr in this.applyObj) {
  104. this.applyObj[attr] = attr === 'currency' ? 'RMB' : ''
  105. }
  106. },
  107. goPublish: function () {
  108. if (this.checkAll()) {
  109. let inquiry = {}
  110. let inquiryItem = {}
  111. if (this.user.data.enterprise) {
  112. inquiry.enUU = this.user.data.enterprise.uu
  113. }
  114. let date = new Date()
  115. inquiry.recorderUU = this.user.data.userUU
  116. inquiry.code = 'MALL' + date.getTime()
  117. inquiry.date = date
  118. inquiry.recorder = this.user.data.userName
  119. inquiry.endDate = formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  120. inquiry.sourceapp = 'MALL'
  121. inquiry.amount = 1
  122. inquiryItem.prodTitle = this.applyObj.code
  123. inquiryItem.userUU = this.user.data.userUU
  124. inquiryItem.source = 'MALL'
  125. inquiryItem.userName = this.user.data.userName
  126. inquiryItem.userTel = this.user.data.userTel
  127. inquiryItem.needquantity = this.applyObj.amount
  128. inquiryItem.inbrand = this.applyObj.brand
  129. inquiryItem.currency = this.applyObj.unitPrice ? this.applyObj.currency : null
  130. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  131. inquiryItem.unitPrice = this.applyObj.unitPrice
  132. inquiryItem.produceDate = this.applyObj.produceDate
  133. inquiryItem.date = date
  134. inquiryItem.endDate = this.applyObj.deadline
  135. inquiryItem.encapsulation = this.applyObj.encapsulation
  136. let inquiryItems = []
  137. inquiryItems.push(inquiryItem)
  138. inquiry.inquiryItems = inquiryItems
  139. this.$http.post('/inquiry/buyer/save', inquiry)
  140. .then(response => {
  141. this.$message.success('发布成功')
  142. // this.showRemindBox = true
  143. this.emptyForm()
  144. // this.validObj.deadline = true
  145. this.$emit('reloadAction')
  146. this.cancel()
  147. }, error => {
  148. console.log(error)
  149. this.$message.error('发布失败')
  150. })
  151. }
  152. },
  153. setCurrency: function (type) {
  154. this.applyObj.currency = type
  155. this.showCurrencyList = false
  156. },
  157. isValidDate: function (date) {
  158. let now = new Date().getTime()
  159. let time = new Date(formatDate(date, 'yyyy-MM-dd hh:mm:ss')).getTime()
  160. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 91)
  161. },
  162. deadlineChange: function () {
  163. if (!this.isValidDate(this.applyObj.deadline)) {
  164. this.$message.error('日期需不小于今天且在90天以内')
  165. this.applyObj.deadline = ''
  166. }
  167. },
  168. checkAll: function () {
  169. return this.checkCode() && this.checkBrand() && this.checkDeadLine() && this.checkAmount() && this.checkProduceDate()
  170. },
  171. checkCode: function () {
  172. if (!this.applyObj.code) {
  173. this.$message.error('型号不能为空')
  174. return false
  175. } else if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
  176. this.$message.error('型号不能包含中文及中文字符')
  177. return false
  178. } else if (getRealLen(this.applyObj.code) > 100) {
  179. this.$message.error('型号不能超过100个字符')
  180. return false
  181. } else {
  182. return true
  183. }
  184. },
  185. checkBrand: function () {
  186. let chineseIndex = -1
  187. if ((/[^\x00-\xff]/g).test(this.applyObj.brand)) {
  188. for (let i = 0; i < this.applyObj.brand.length; i++) {
  189. if ((/[^\x00-\xff]/g).test(this.applyObj.brand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.applyObj.brand.charAt(i))) {
  190. chineseIndex = i
  191. break
  192. }
  193. }
  194. }
  195. if (!this.applyObj.brand) {
  196. this.$message.error('品牌不能为空')
  197. return false
  198. } else if (chineseIndex !== -1) {
  199. this.$message.error('品牌不能包含中文字符')
  200. return false
  201. } else if (getRealLen(this.applyObj.brand) > 50) {
  202. this.$message.error('品牌不能超过50个字符')
  203. return false
  204. } else {
  205. return true
  206. }
  207. },
  208. checkDeadLine: function () {
  209. if (!this.applyObj.deadline) {
  210. this.$message.error('截止日期不能为空')
  211. }
  212. return this.applyObj.deadline
  213. },
  214. checkAmount: function () {
  215. if (typeof this.applyObj.amount === 'undefined' || this.applyObj.amount === '') {
  216. return true
  217. } else {
  218. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  219. this.$message.error('请输入正确的数量')
  220. return false
  221. } else if (this.applyObj.amount.length > 9) {
  222. this.$message.error('数量不能大于999999999')
  223. return false
  224. } else {
  225. return true
  226. }
  227. }
  228. },
  229. checkProduceDate: function () {
  230. if (typeof this.applyObj.produceDate === 'undefined' || this.applyObj.produceDate === '') {
  231. return true
  232. } else {
  233. if (getRealLen(this.applyObj.produceDate) > 12) {
  234. this.$message.error('生产日期不能大于12个字符')
  235. return false
  236. } else {
  237. return true
  238. }
  239. }
  240. }
  241. }
  242. }
  243. </script>
  244. <style lang="scss" scoped>
  245. .mobile-modal {
  246. .mobile-modal-box {
  247. .publish-seek {
  248. background: #fff;
  249. padding-top: .1rem;
  250. padding-bottom: .4rem;
  251. .content-line {
  252. height: .8rem;
  253. line-height: .8rem;
  254. font-size: .26rem;
  255. text-align: left;
  256. border-bottom: .04rem solid #b7d5fe;
  257. position: relative;
  258. input {
  259. width: 3.49rem;
  260. height: .52rem;
  261. padding-left: .19rem;
  262. border: .04rem solid #7e7e7e;
  263. }
  264. > span {
  265. display: inline-block;
  266. width: 1.76rem;
  267. text-align: right;
  268. i {
  269. color: #ff0000;
  270. margin-right: .05rem;
  271. font-style: normal;
  272. }
  273. }
  274. > a {
  275. font-size: .26rem;
  276. color: #666;
  277. }
  278. > img {
  279. width: .12rem;
  280. height: .06rem;
  281. margin-left: .04rem;
  282. }
  283. > ul {
  284. position: absolute;
  285. top: .6rem;
  286. left: 1.16rem;
  287. z-index: 1;
  288. width: 1.75rem;
  289. background: #fff;
  290. text-align: center;
  291. border-radius: .1rem;
  292. border: .02rem solid #dfdfdf;
  293. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  294. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  295. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  296. li {
  297. height: .52rem;
  298. line-height: .52rem;
  299. border-bottom: .04rem solid #dfdfdf;
  300. &:hover, &:active {
  301. background: #dedede;
  302. }
  303. }
  304. }
  305. }
  306. > a {
  307. display: block;
  308. width: 5.19rem;
  309. height: .84rem;
  310. text-align: center;
  311. line-height: .84rem;
  312. font-size: .38rem;
  313. margin: .3rem auto 0;
  314. background: #3f84f6;
  315. color: #fff;
  316. border-radius: .08rem;
  317. }
  318. }
  319. }
  320. }
  321. </style>