PublishSupplierSeek.vue 8.5 KB

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