PublishSeek.vue 11 KB

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