PublishSupplierSeek.vue 9.0 KB

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