PublishSupplierSeek.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class="mobile-modal" v-if="showPublishBox">
  3. <div class="mobile-modal-box">
  4. <div class="mobile-modal-header">我要询价<i class="icon-guanbi iconfont" @click="cancel"></i></div>
  5. <div class="props">
  6. <div class="prop">型号:{{applyObj.code || '-'}}</div>
  7. <div class="prop">品牌:{{applyObj.brand || '-'}}</div>
  8. <div class="prop">类目:{{applyObj.prodTitle || '-'}}</div>
  9. <div class="prop">规格:{{applyObj.spec || '-'}}</div>
  10. </div>
  11. <div class="publish-seek">
  12. <div class="content-line">
  13. <span><i>*</i>截止日期:</span>
  14. <input type="date" v-model="applyObj.deadline" :min="minDay" :max="maxDay" @blur="deadlineChange">
  15. </div>
  16. <div class="content-line">
  17. <span>数量:</span>
  18. <input type="text" v-model="applyObj.amount" @blur="checkAmount" @input="onAmountInput">
  19. </div>
  20. <a @click="goPublish">确认</a>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import { formatDate, cutOutString } from '~utils/baseUtils'
  27. export default {
  28. props: ['showPublishBox', 'product'],
  29. data () {
  30. return {
  31. applyObj: {
  32. code: '',
  33. brand: '',
  34. amount: '',
  35. deadline: '',
  36. prodTitle: ''
  37. },
  38. validObj: {
  39. amount: true,
  40. deadline: true
  41. }
  42. }
  43. },
  44. computed: {
  45. minDay: function () {
  46. return formatDate(new Date(), 'yyyy-MM-dd')
  47. },
  48. maxDay: function () {
  49. let deadDate = new Date().getTime() + 1000 * 60 * 60 * 24 * 90
  50. deadDate = formatDate(new Date(deadDate), 'yyyy-MM-dd')
  51. return deadDate
  52. }
  53. },
  54. watch: {
  55. // showPublishBox: function (val, old) {
  56. // if (val) {
  57. // document.body.style.position = 'fixed'
  58. // document.body.style.left = '0'
  59. // document.body.style.right = '0'
  60. // } else {
  61. // document.body.style.position = 'relative'
  62. // }
  63. // },
  64. product: {
  65. handler (val, oldVal) {
  66. if (val) {
  67. let isStandard = val.standard === 1
  68. this.applyObj.code = val.cmpCode
  69. this.applyObj.brand = isStandard ? val.pbranden : val.brand
  70. this.applyObj.spec = val.spec
  71. // this.applyObj.unit = val.unit || 'PCS'
  72. this.applyObj.prodTitle = isStandard ? val.kind : val.prodName
  73. }
  74. },
  75. immediate: true
  76. }
  77. },
  78. methods: {
  79. cancel: function () {
  80. this.$emit('cancelAction')
  81. },
  82. emptyForm: function () {
  83. for (let attr in this.applyObj) {
  84. this.applyObj[attr] = ''
  85. }
  86. },
  87. setRemindText: function (str) {
  88. this.$emit('remindAction', str)
  89. },
  90. goPublish: function () {
  91. if (this.checkAll()) {
  92. let inquiry = {}
  93. let inquiryItem = {}
  94. if (this.user.data.enterprise) {
  95. inquiry.enUU = this.user.data.enterprise.uu
  96. }
  97. let date = new Date()
  98. let endDate = formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  99. inquiry.recorderUU = this.user.data.userUU
  100. inquiry.code = 'MALL' + date.getTime()
  101. inquiry.date = date
  102. inquiry.recorder = this.user.data.userName
  103. inquiry.endDate = endDate
  104. inquiry.sourceapp = 'MALL'
  105. inquiryItem.userUU = this.user.data.userUU
  106. inquiryItem.source = 'MALL'
  107. inquiryItem.userName = this.user.data.userName
  108. inquiryItem.userTel = this.user.data.userTel
  109. inquiryItem.needquantity = this.applyObj.amount
  110. inquiryItem.inbrand = this.applyObj.brand
  111. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  112. inquiryItem.prodTitle = this.applyObj.prodTitle
  113. inquiryItem.date = date
  114. inquiryItem.endDate = endDate
  115. let inquiryItems = []
  116. inquiryItems.push(inquiryItem)
  117. inquiry.inquiryItems = inquiryItems
  118. this.$http.post('/inquiry/buyer/save', inquiry)
  119. .then(response => {
  120. // this.$message.success('发布成功')
  121. this.setRemindText('发布成功')
  122. // this.showRemindBox = true
  123. this.emptyForm()
  124. // this.validObj.deadline = true
  125. // this.$emit('reloadAction')
  126. this.cancel()
  127. }, error => {
  128. console.log(error)
  129. // this.$message.error('发布失败')
  130. this.setRemindText('发布失败')
  131. })
  132. } else {
  133. if (!this.validObj.deadline) {
  134. this.setRemindText('截止日期不能为空')
  135. } else if (!this.validObj.amount) {
  136. this.setRemindText('请输入正确的数值')
  137. }
  138. }
  139. },
  140. isValidDate: function (date) {
  141. let now = new Date(formatDate(new Date(), 'yyyy-MM-dd')).getTime()
  142. let time = new Date(date).getTime()
  143. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 91)
  144. },
  145. deadlineChange: function () {
  146. if (!this.isValidDate(this.applyObj.deadline)) {
  147. this.setRemindText('日期需不小于今天且在90天以内')
  148. this.applyObj.deadline = ''
  149. this.validObj.deadline = false
  150. } else {
  151. this.validObj.deadline = true
  152. }
  153. },
  154. checkAll: function () {
  155. return this.checkDeadline() && this.checkAmount()
  156. },
  157. checkAmount: function () {
  158. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  159. return this.validObj.amount
  160. },
  161. checkDeadline: function () {
  162. this.validObj.deadline = Boolean(this.applyObj.deadline)
  163. return this.validObj.deadline
  164. },
  165. onAmountInput: function () {
  166. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  167. let chineseIndex = -1
  168. for (let i = 0; i < this.applyObj.amount.length; i++) {
  169. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  170. chineseIndex = i
  171. break
  172. }
  173. }
  174. this.applyObj.amount = cutOutString(this.applyObj.amount, chineseIndex)
  175. } else if (this.applyObj.amount.length > 9) {
  176. this.applyObj.amount = cutOutString(this.applyObj.amount, 9)
  177. }
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. .mobile-modal {
  184. .mobile-modal-box {
  185. position: fixed;
  186. width: 5.92rem;
  187. font-size: .28rem;
  188. top: 50%;
  189. left: 50%;
  190. right: 11%;
  191. z-index: 1000;
  192. margin-top: -3.7rem;
  193. margin-left: -2.96rem;
  194. background: #f3f3f3;
  195. .mobile-modal-header {
  196. border-radius: 0;
  197. }
  198. .publish-seek {
  199. background: #fff;
  200. padding-top: .1rem;
  201. padding-bottom: .4rem;
  202. .content-line {
  203. position: relative;
  204. height: .8rem;
  205. line-height: .8rem;
  206. font-size: .26rem;
  207. text-align: left;
  208. input {
  209. width: 3.49rem;
  210. height: .52rem;
  211. line-height: normal;
  212. padding: .1rem .19rem;
  213. border: 1px solid #7e7e7e;
  214. font-size: .26rem;
  215. vertical-align: middle;
  216. background: #fff;
  217. border-radius: 0;
  218. }
  219. > span {
  220. display: inline-block;
  221. width: 1.76rem;
  222. text-align: right;
  223. i {
  224. color: #ff0000;
  225. margin-right: .05rem;
  226. font-style: normal;
  227. }
  228. }
  229. > a {
  230. font-size: .26rem;
  231. color: #666;
  232. }
  233. > img {
  234. width: .12rem;
  235. height: .06rem;
  236. margin-left: .04rem;
  237. }
  238. }
  239. > a {
  240. display: block;
  241. width: 5.19rem;
  242. height: .84rem;
  243. text-align: center;
  244. line-height: .84rem;
  245. font-size: .38rem;
  246. margin: .3rem auto 0;
  247. background: #3f84f6;
  248. color: #fff;
  249. border-radius: .08rem;
  250. }
  251. }
  252. .props {
  253. font-size: .28rem;
  254. background: #fff;
  255. margin: .2rem 0;
  256. padding-left: .29rem;
  257. .prop {
  258. padding-top: .2rem;
  259. &:last-child {
  260. padding-bottom: .2rem;
  261. }
  262. span {
  263. color: #666;
  264. }
  265. }
  266. }
  267. }
  268. }
  269. </style>