PublishSeek.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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" @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" @blur="checkAmount" @input="onAmountInput">
  32. </div>
  33. <div class="content-line">
  34. <span>生产日期:</span>
  35. <input type="text" v-model="applyObj.produceDate" @input="onProduceDateChange">
  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. let cutOutString = function (str, length) {
  78. for (let i = 1; i <= str.length; i++) {
  79. if (getRealLen(str.substr(0, i)) > length) {
  80. str = str.substr(0, i - 1)
  81. break
  82. }
  83. }
  84. return str
  85. }
  86. export default {
  87. props: ['showSayPriceBox'],
  88. data () {
  89. return {
  90. applyObj: {
  91. code: '',
  92. brand: '',
  93. unitPrice: '',
  94. currency: '不限',
  95. encapsulation: '',
  96. produceDate: '',
  97. amount: '',
  98. deadline: ''
  99. },
  100. validObj: {
  101. code: true,
  102. brand: true,
  103. unitPrice: true,
  104. amount: true,
  105. deadline: true
  106. },
  107. showCurrencyList: false
  108. }
  109. },
  110. computed: {
  111. user () {
  112. return this.$store.state.option.user
  113. }
  114. },
  115. methods: {
  116. cancel: function () {
  117. this.$emit('cancelAction')
  118. },
  119. emptyForm: function () {
  120. for (let attr in this.applyObj) {
  121. this.applyObj[attr] = attr === 'currency' ? 'RMB' : ''
  122. }
  123. },
  124. setRemindText: function (str) {
  125. this.$emit('remindAction', str)
  126. },
  127. goPublish: function () {
  128. if (this.checkAll()) {
  129. let inquiry = {}
  130. let inquiryItem = {}
  131. if (this.user.data.enterprise) {
  132. inquiry.enUU = this.user.data.enterprise.uu
  133. }
  134. let date = new Date()
  135. let endDate = formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  136. inquiry.recorderUU = this.user.data.userUU
  137. inquiry.code = 'MALL' + date.getTime()
  138. inquiry.date = date
  139. inquiry.recorder = this.user.data.userName
  140. inquiry.endDate = endDate
  141. inquiry.sourceapp = 'MALL'
  142. inquiry.amount = 1
  143. inquiryItem.prodTitle = this.applyObj.code
  144. inquiryItem.userUU = this.user.data.userUU
  145. inquiryItem.source = 'MALL'
  146. inquiryItem.userName = this.user.data.userName
  147. inquiryItem.userTel = this.user.data.userTel
  148. inquiryItem.needquantity = this.applyObj.amount
  149. inquiryItem.inbrand = this.applyObj.brand
  150. inquiryItem.currency = this.applyObj.currency === '不限' ? null : this.applyObj.currency
  151. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  152. inquiryItem.unitPrice = this.applyObj.unitPrice
  153. inquiryItem.produceDate = this.applyObj.produceDate
  154. inquiryItem.date = date
  155. inquiryItem.endDate = endDate
  156. inquiryItem.encapsulation = this.applyObj.encapsulation
  157. let inquiryItems = []
  158. inquiryItems.push(inquiryItem)
  159. inquiry.inquiryItems = inquiryItems
  160. this.$http.post('/inquiry/buyer/save', inquiry)
  161. .then(response => {
  162. // this.$message.success('发布成功')
  163. this.setRemindText('发布成功')
  164. // this.showRemindBox = true
  165. this.emptyForm()
  166. // this.validObj.deadline = true
  167. this.$emit('reloadAction')
  168. this.cancel()
  169. }, error => {
  170. console.log(error)
  171. // this.$message.error('发布失败')
  172. this.setRemindText('发布失败')
  173. })
  174. } else {
  175. if (!this.validObj.code) {
  176. this.setRemindText('型号不能为空')
  177. } else if (!this.validObj.brand) {
  178. this.setRemindText('品牌不能为空')
  179. } else if (!this.validObj.deadline) {
  180. this.setRemindText('截止日期不能为空')
  181. } else if (!this.validObj.amount) {
  182. this.setRemindText('请输入正确的数值')
  183. }
  184. }
  185. },
  186. setCurrency: function (type) {
  187. this.applyObj.currency = type
  188. this.showCurrencyList = false
  189. },
  190. isValidDate: function (date) {
  191. let now = new Date().getTime()
  192. let time = new Date(formatDate(date, 'yyyy-MM-dd hh:mm:ss')).getTime()
  193. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 91)
  194. },
  195. deadlineChange: function () {
  196. if (!this.isValidDate(this.applyObj.deadline)) {
  197. this.setRemindText('日期需不小于今天且在90天以内')
  198. this.applyObj.deadline = ''
  199. this.validObj.deadline = false
  200. } else {
  201. this.validObj.deadline = true
  202. }
  203. },
  204. checkAll: function () {
  205. return this.checkCode() && this.checkBrand() && this.checkDeadline() && this.checkAmount()
  206. },
  207. checkCode: function () {
  208. this.validObj.code = this.applyObj.code && this.applyObj.code !== ''
  209. if (!this.validObj.code) {
  210. this.setRemindText('型号不能为空')
  211. }
  212. return this.validObj.code
  213. },
  214. checkBrand: function () {
  215. this.validObj.brand = this.applyObj.brand && this.applyObj.brand !== ''
  216. if (!this.validObj.brand) {
  217. this.setRemindText('品牌不能为空')
  218. }
  219. return this.validObj.brand
  220. },
  221. checkAmount: function () {
  222. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  223. return this.validObj.amount
  224. },
  225. checkDeadline: function () {
  226. this.validObj.deadline = Boolean(this.applyObj.deadline)
  227. return this.validObj.deadline
  228. },
  229. onProduceDateChange: function () {
  230. if (this.applyObj.produceDate && getRealLen(this.applyObj.produceDate) > 12) {
  231. this.applyObj.produceDate = cutOutString(this.applyObj.produceDate, 12)
  232. }
  233. },
  234. onCodeChange: function () {
  235. this.applyObj.code = this.applyObj.code.trim()
  236. if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
  237. let chineseIndex = -1
  238. for (let i = 0; i < this.applyObj.code.length; i++) {
  239. if ((/[^\x00-\xff]/g).test(this.applyObj.code.charAt(i))) {
  240. chineseIndex = i
  241. break
  242. }
  243. }
  244. this.applyObj.code = cutOutString(this.applyObj.code, chineseIndex)
  245. } else if (this.applyObj.code && getRealLen(this.applyObj.code) > 100) {
  246. this.applyObj.code = cutOutString(this.applyObj.code, 100)
  247. }
  248. },
  249. onBrandChange: function () {
  250. this.applyObj.brand = this.applyObj.brand.trim()
  251. if ((/[^\x00-\xff]/g).test(this.applyObj.brand)) {
  252. let chineseIndex = -1
  253. for (let i = 0; i < this.applyObj.brand.length; i++) {
  254. if ((/[^\x00-\xff]/g).test(this.applyObj.brand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.applyObj.brand.charAt(i))) {
  255. chineseIndex = i
  256. break
  257. }
  258. }
  259. if (chineseIndex > -1) {
  260. this.applyObj.brand = this.applyObj.brand.substring(0, chineseIndex)
  261. }
  262. } else if (this.applyObj.brand && getRealLen(this.applyObj.brand) > 50) {
  263. this.applyObj.brand = cutOutString(this.applyObj.brand, 50)
  264. }
  265. },
  266. onAmountInput: function () {
  267. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  268. let chineseIndex = -1
  269. for (let i = 0; i < this.applyObj.amount.length; i++) {
  270. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  271. chineseIndex = i
  272. break
  273. }
  274. }
  275. this.applyObj.amount = cutOutString(this.applyObj.amount, chineseIndex)
  276. } else if (this.applyObj.amount.length > 9) {
  277. this.applyObj.amount = cutOutString(this.applyObj.amount, 9)
  278. }
  279. }
  280. }
  281. }
  282. </script>
  283. <style lang="scss" scoped>
  284. .mobile-modal {
  285. .mobile-modal-box {
  286. .publish-seek {
  287. background: #fff;
  288. padding-top: .1rem;
  289. padding-bottom: .4rem;
  290. .content-line {
  291. height: .8rem;
  292. line-height: .8rem;
  293. font-size: .26rem;
  294. text-align: left;
  295. border-bottom: .02rem solid #b7d5fe;
  296. position: relative;
  297. input {
  298. width: 3.49rem;
  299. height: .52rem;
  300. line-height: .52rem;
  301. padding-left: .19rem;
  302. border: .02rem solid #7e7e7e;
  303. font-size: .26rem;
  304. vertical-align: middle;
  305. background: #fff;
  306. }
  307. > span {
  308. display: inline-block;
  309. width: 1.76rem;
  310. text-align: right;
  311. i {
  312. color: #ff0000;
  313. margin-right: .05rem;
  314. font-style: normal;
  315. }
  316. }
  317. > a {
  318. font-size: .26rem;
  319. color: #666;
  320. }
  321. > img {
  322. width: .12rem;
  323. height: .06rem;
  324. margin-left: .04rem;
  325. }
  326. > ul {
  327. position: absolute;
  328. top: .6rem;
  329. left: 1.16rem;
  330. z-index: 1;
  331. width: 1.75rem;
  332. background: #fff;
  333. text-align: center;
  334. border-radius: .1rem;
  335. border: .02rem solid #dfdfdf;
  336. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  337. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  338. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  339. li {
  340. height: .52rem;
  341. line-height: .52rem;
  342. border-bottom: .02rem solid #dfdfdf;
  343. &:hover, &:active {
  344. background: #dedede;
  345. }
  346. }
  347. }
  348. }
  349. > a {
  350. display: block;
  351. width: 5.19rem;
  352. height: .84rem;
  353. text-align: center;
  354. line-height: .84rem;
  355. font-size: .38rem;
  356. margin: .3rem auto 0;
  357. background: #3f84f6;
  358. color: #fff;
  359. border-radius: .08rem;
  360. }
  361. }
  362. }
  363. }
  364. </style>