PublishSupplierSeek.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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>数量(PCS):</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. getMaterialKind: function (code, brand) {
  91. return this.$http.get('/productuser/match/getKind', {params: {cmpCode: code, brand: brand}})
  92. },
  93. startPublish: function (prodTitle) {
  94. let inquiry = {}
  95. let inquiryItem = {}
  96. if (this.user.data.enterprise) {
  97. inquiry.enUU = this.user.data.enterprise.uu
  98. }
  99. let date = new Date()
  100. let endDate = formatDate(this.applyObj.deadline, 'yyyy-MM-dd hh:mm:ss')
  101. inquiry.recorderUU = this.user.data.userUU
  102. inquiry.code = 'MALL' + date.getTime()
  103. inquiry.date = date
  104. inquiry.recorder = this.user.data.userName
  105. inquiry.endDate = endDate
  106. inquiry.sourceapp = 'MALL'
  107. inquiryItem.userUU = this.user.data.userUU
  108. inquiryItem.source = 'MALL'
  109. inquiryItem.userName = this.user.data.userName
  110. inquiryItem.userTel = this.user.data.userTel
  111. inquiryItem.needquantity = this.applyObj.amount
  112. inquiryItem.inbrand = this.applyObj.brand
  113. inquiryItem.cmpCode = (this.applyObj.code).toUpperCase()
  114. inquiryItem.prodTitle = prodTitle || this.applyObj.prodTitle || '其他'
  115. inquiryItem.date = date
  116. inquiryItem.endDate = endDate
  117. let inquiryItems = []
  118. inquiryItems.push(inquiryItem)
  119. inquiry.inquiryItems = inquiryItems
  120. this.$http.post('/inquiry/buyer/save', inquiry)
  121. .then(response => {
  122. // this.$message.success('发布成功')
  123. this.setRemindText('发布成功')
  124. // this.showRemindBox = true
  125. this.emptyForm()
  126. // this.validObj.deadline = true
  127. // this.$emit('reloadAction')
  128. this.cancel()
  129. }, error => {
  130. console.log(error)
  131. // this.$message.error('发布失败')
  132. this.setRemindText('发布失败')
  133. })
  134. },
  135. goPublish: function () {
  136. if (this.checkAll()) {
  137. if (!this.applyObj.prodTitle || this.applyObj.prodTitle.length === 0) {
  138. this.getMaterialKind(this.applyObj.code, this.applyObj.brand).then(response => {
  139. this.startPublish(response.data && response.data.length ? response.data : '其他')
  140. })
  141. } else {
  142. this.startPublish()
  143. }
  144. } else {
  145. if (!this.validObj.deadline) {
  146. this.setRemindText('截止日期不能为空')
  147. } else if (!this.validObj.amount) {
  148. this.setRemindText('请输入正确的数值')
  149. }
  150. }
  151. },
  152. isValidDate: function (date) {
  153. let now = new Date(formatDate(new Date(), 'yyyy-MM-dd')).getTime()
  154. let time = new Date(date).getTime()
  155. return !time || (time >= now && time <= now + 1000 * 60 * 60 * 24 * 90)
  156. },
  157. deadlineChange: function () {
  158. if (!this.isValidDate(this.applyObj.deadline)) {
  159. this.setRemindText('日期需不小于今天且在90天以内')
  160. this.applyObj.deadline = ''
  161. this.validObj.deadline = false
  162. } else {
  163. this.validObj.deadline = true
  164. }
  165. },
  166. checkAll: function () {
  167. return this.checkDeadline() && this.checkAmount()
  168. },
  169. checkAmount: function () {
  170. this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000
  171. return this.validObj.amount
  172. },
  173. checkDeadline: function () {
  174. this.validObj.deadline = Boolean(this.applyObj.deadline)
  175. return this.validObj.deadline
  176. },
  177. onAmountInput: function () {
  178. if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
  179. let chineseIndex = -1
  180. for (let i = 0; i < this.applyObj.amount.length; i++) {
  181. if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
  182. chineseIndex = i
  183. break
  184. }
  185. }
  186. this.applyObj.amount = cutOutString(this.applyObj.amount, chineseIndex)
  187. } else if (this.applyObj.amount.length > 9) {
  188. this.applyObj.amount = cutOutString(this.applyObj.amount, 9)
  189. }
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. .mobile-modal {
  196. .mobile-modal-box {
  197. position: fixed;
  198. width: 5.92rem;
  199. font-size: .28rem;
  200. top: 50%;
  201. left: 50%;
  202. right: 11%;
  203. z-index: 1000;
  204. margin-top: -3.7rem;
  205. margin-left: -2.96rem;
  206. background: #f3f3f3;
  207. .mobile-modal-header {
  208. border-radius: 0;
  209. }
  210. .publish-seek {
  211. background: #fff;
  212. padding-top: .1rem;
  213. padding-bottom: .4rem;
  214. .content-line {
  215. position: relative;
  216. height: .8rem;
  217. line-height: .8rem;
  218. font-size: .26rem;
  219. text-align: left;
  220. input {
  221. width: 3.49rem;
  222. height: .52rem;
  223. line-height: normal;
  224. padding: .1rem .19rem;
  225. border: 1px solid #7e7e7e;
  226. font-size: .26rem;
  227. vertical-align: middle;
  228. background: #fff;
  229. border-radius: 0;
  230. }
  231. > span {
  232. display: inline-block;
  233. width: 1.76rem;
  234. text-align: right;
  235. i {
  236. color: #ff0000;
  237. margin-right: .05rem;
  238. font-style: normal;
  239. }
  240. }
  241. > a {
  242. font-size: .26rem;
  243. color: #666;
  244. }
  245. > img {
  246. width: .12rem;
  247. height: .06rem;
  248. margin-left: .04rem;
  249. }
  250. }
  251. > a {
  252. display: block;
  253. width: 5.19rem;
  254. height: .84rem;
  255. text-align: center;
  256. line-height: .84rem;
  257. font-size: .38rem;
  258. margin: .3rem auto 0;
  259. background: #3f84f6;
  260. color: #fff;
  261. border-radius: .08rem;
  262. }
  263. }
  264. .props {
  265. font-size: .28rem;
  266. background: #fff;
  267. margin: .2rem 0;
  268. padding-left: .29rem;
  269. .prop {
  270. padding-top: .2rem;
  271. &:last-child {
  272. padding-bottom: .2rem;
  273. }
  274. span {
  275. color: #666;
  276. }
  277. }
  278. }
  279. }
  280. }
  281. </style>