SayPrice.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <div class="mobile-modal" v-show="showSayPriceBox" @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="say-price" ref="mobileModalBox">
  6. <div>
  7. <div class="base-info">
  8. <div class="content-line">
  9. 品牌:<span>{{purchaseDetail.inbrand || '-'}}</span>
  10. </div>
  11. <div class="content-line">
  12. 类目(产品名称):<span>{{purchaseDetail.prodTitle || '-'}}</span>
  13. </div>
  14. <div class="content-line">
  15. 型号:<span>{{purchaseDetail.cmpCode || '-'}}</span>
  16. </div>
  17. <div class="content-line">
  18. 规格:<span>{{purchaseDetail.spec || '-'}}</span>
  19. </div>
  20. <div class="content-line">
  21. 采购数量(PCS):<span>{{purchaseDetail.needquantity || '-'}}</span>
  22. </div>
  23. <!--<div class="content-line">
  24. 币种:<span>{{purchaseDetail.custCurrency || '不限'}}</span>
  25. </div>
  26. <div class="content-line">
  27. 生产日期:<span>{{purchaseDetail.produceDate || '-'}}</span>
  28. </div>-->
  29. <div class="content-line">
  30. 截止日期:<span>{{purchaseDetail.endDate | date}}</span>
  31. </div>
  32. </div>
  33. <div class="form-list">
  34. <div class="form-title">
  35. <span class="fl">价格梯度<span>(PCS)</span></span>
  36. <span class="fr">
  37. <!--<span v-text="sayPriceObj.currency" @click="setShowCurrencyList($event)"></span>-->
  38. <span v-text="sayPriceObj.currency" @click="setShowCurrencyList($event)"></span>
  39. <!--<span v-if="purchaseDetail.custCurrency" v-text="purchaseDetail.custCurrency"></span>-->
  40. <img v-if="!showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-down.png" alt="">
  41. <img v-if="showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-up.png" alt="">
  42. <ul v-if="showCurrencyList">
  43. <li @click="setCurrency('RMB')">RMB</li>
  44. <li @click="setCurrency('USD')">USD</li>
  45. </ul>
  46. </span>
  47. </div>
  48. <div class="form-item" v-for="(reply, index) in sayPriceObj.replies">
  49. <input type="text" placeholder="分段数量" class="fl" @blur="onReplyLapQtyBlur(index)" @input="onReplyLapQtyInput(index)" v-model="reply.lapQty">
  50. <input type="text" placeholder="分段单价" class="fr" @input="onReplyPriceInput(index)" @blur="onReplyPriceBlur(index)" v-model="reply.price">
  51. <i class="iconfont icon-minus" v-if="index > 0" @click="setReplies('sub', index)"></i>
  52. <i class="iconfont icon-add" v-if="index == 0 && sayPriceObj.replies.length < 5" @click="setReplies('add', index)"></i>
  53. </div>
  54. <div class="date">
  55. <span>交期(天)</span>
  56. <input type="text" placeholder="最大值" @input="onLeadtimeInput" @blur="onLeadtimeBlur" v-model="sayPriceObj.leadtime" class="fr">
  57. </div>
  58. <a class="say-price-btn" @click="commitSayPrice">确定</a>
  59. </div>
  60. </div>
  61. <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import {RemindBox} from '~components/mobile/common'
  68. export default {
  69. data () {
  70. return {
  71. showCurrencyList: false,
  72. sayPriceObj: {
  73. currency: 'RMB',
  74. leadtime: '',
  75. replies: [
  76. {
  77. lapQty: '',
  78. price: ''
  79. }
  80. ]
  81. },
  82. validSayPrice: {
  83. leadtime: false,
  84. repliesPrice: false,
  85. repliesLapQty: false
  86. },
  87. remindText: '',
  88. timeoutCount: 0
  89. }
  90. },
  91. props: ['showSayPriceBox'],
  92. components: {
  93. RemindBox
  94. },
  95. watch: {
  96. showSayPriceBox: function (val, old) {
  97. if (val) {
  98. // document.body.style.position = 'fixed'
  99. // document.body.style.left = '0'
  100. // document.body.style.right = '0'
  101. // document.documentElement.style['overflow'] = 'hidden'
  102. // document.body.style.overflow = 'hidden'
  103. // document.documentElement.addEventListener('touchmove', function(event) {
  104. // event.preventDefault()
  105. // }, false)
  106. } else {
  107. // document.body.style.position = 'static'
  108. // document.documentElement.style['overflow'] = 'auto'
  109. // document.body.style.overflow = 'auto'
  110. }
  111. this.resetSayPrice()
  112. }
  113. },
  114. mounted () {
  115. this.$nextTick(() => {
  116. document.addEventListener('click', this.checkCurrencySelect)
  117. this._initscroll()
  118. })
  119. },
  120. filters: {
  121. date: function (date) {
  122. if (date) {
  123. const d = new Date(Number(date))
  124. const year = d.getFullYear()
  125. const monthTemp = d.getMonth() + 1
  126. const month = monthTemp < 10 ? '0' + monthTemp : '' + monthTemp
  127. const day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate() + ' '
  128. return year + '-' + month + '-' + day
  129. } else {
  130. return '-'
  131. }
  132. }
  133. },
  134. computed: {
  135. purchaseDetail () {
  136. return JSON.parse(JSON.stringify(this.$store.state.applyPurchase.purchaseManList.purchaseManDetail.data))
  137. },
  138. user () {
  139. return this.$store.state.option.user
  140. }
  141. },
  142. methods: {
  143. cancel: function () {
  144. this.$emit('cancelSayPriceAction', false)
  145. },
  146. checkCurrencySelect: function () {
  147. this.showCurrencyList = false
  148. },
  149. setShowCurrencyList: function (event) {
  150. event.stopPropagation()
  151. this.showCurrencyList = !this.showCurrencyList
  152. },
  153. setCurrency: function (type) {
  154. this.sayPriceObj.currency = type
  155. this.showCurrencyList = false
  156. },
  157. resetSayPrice: function () {
  158. this.sayPriceObj = {
  159. currency: 'RMB',
  160. leadtime: '',
  161. replies: [
  162. {
  163. lapQty: '',
  164. price: ''
  165. }
  166. ]
  167. }
  168. },
  169. setReplies: function (type, index) {
  170. if (type === 'add' && this.sayPriceObj.replies.length < 5) {
  171. this.sayPriceObj.replies.splice(this.sayPriceObj.replies.length, 0, {
  172. lapQty: '',
  173. price: ''
  174. })
  175. } else if (type === 'sub' && this.sayPriceObj.replies.length > 1) {
  176. this.sayPriceObj.replies.splice(index, 1)
  177. }
  178. this._initscroll()
  179. },
  180. commitSayPrice: function () {
  181. if (this.checkValid()) {
  182. let purchaseMan = JSON.parse(JSON.stringify(this.purchaseDetail))
  183. // this.showLoading = true
  184. purchaseMan.leadtime = this.sayPriceObj.leadtime
  185. purchaseMan.replies = this.sayPriceObj.replies
  186. purchaseMan.vendUU = this.user.data.enterprise.uu
  187. purchaseMan.vendUserUU = this.user.data.userUU
  188. purchaseMan.qutoApp = 'MALL'
  189. purchaseMan.currency = this.sayPriceObj.currency
  190. this.$http.post('/inquiry/sale/item/save', purchaseMan).then(response => {
  191. this.showLoading = false
  192. if (response.data.success === false) {
  193. this.onRemind('response.data.message')
  194. } else {
  195. // this.onRemind('报价成功')
  196. this.resetSayPrice()
  197. this.$emit('cancelSayPriceAction', true, JSON.parse(response.data).quteId)
  198. }
  199. }, error => {
  200. console.log(error)
  201. this.onRemind('请勿重复报价或报价自己的求购')
  202. // this.showLoading = false
  203. })
  204. } else {
  205. this.onRemind('请输入正确的报价信息')
  206. }
  207. },
  208. onLeadtimeInput: function () {
  209. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.replace(/[^\-?\d.]/g, '')
  210. if (this.sayPriceObj.leadtime.length > 3) {
  211. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.substring(0, 3)
  212. }
  213. },
  214. onLeadtimeBlur: function () {
  215. if (!this.sayPriceObj.leadtime || this.sayPriceObj.leadtime < 1 || this.sayPriceObj.leadtime >= 1000 || this.sayPriceObj.leadtime.toString().indexOf('.') !== -1) {
  216. this.validSayPrice.leadtime = false
  217. this.onRemind('交期请填写1-999之间的正整数')
  218. } else {
  219. this.validSayPrice.leadtime = true
  220. }
  221. },
  222. onReplyPriceInput: function (index) {
  223. this.sayPriceObj.replies[index].price = this.sayPriceObj.replies[index].price.replace(/[^\-?\d.]/g, '')
  224. let price = this.sayPriceObj.replies[index].price
  225. if (price >= 10000) {
  226. this.sayPriceObj.replies[index].price = price.substring(0, 4)
  227. } else if (price.indexOf('.') > -1) {
  228. let arr = price.split('.')
  229. if (arr[0].length > 4) {
  230. this.sayPriceObj.replies[index].price = Number(arr[0].substring(0, 4) + '.' + arr[1])
  231. } else if (arr[1].length > 6) {
  232. this.sayPriceObj.replies[index].price = Number(arr[0] + '.' + arr[1].substring(0, 6))
  233. }
  234. }
  235. },
  236. onReplyPriceBlur: function (index) {
  237. let price = this.sayPriceObj.replies[index].price
  238. if (!price) {
  239. this.sayPriceObj.replies[index].price = ''
  240. this.onRemind('价格不能为空')
  241. this.validSayPrice.repliesPrice = false
  242. } else if (price <= 0) {
  243. this.sayPriceObj.replies[index].price = ''
  244. this.onRemind('输入值必须为正整数')
  245. this.validSayPrice.repliesPrice = false
  246. } else {
  247. this.validSayPrice.repliesPrice = true
  248. }
  249. },
  250. onReplyLapQtyBlur: function (index) {
  251. let lapQty = Number(this.sayPriceObj.replies[index].lapQty)
  252. let limitDownObj = this.getLimitDownQty()
  253. if (!lapQty || lapQty < 1) {
  254. this.sayPriceObj.replies[index].lapQty = ''
  255. this.onRemind('输入值必须为正整数')
  256. this.validSayPrice.repliesLapQty = false
  257. } else if (limitDownObj.index !== index && limitDownObj.lapQty > lapQty) {
  258. this.onRemind('输入值必须大于#该梯度的下限#')
  259. this.sayPriceObj.replies[index].lapQty = ''
  260. this.validSayPrice.repliesLapQty = false
  261. } else if ((index - 1 >= 0 && this.sayPriceObj.replies[index - 1].lapQty && this.sayPriceObj.replies[index - 1].lapQty >= lapQty) || (index + 1 < this.sayPriceObj.replies.length && this.sayPriceObj.replies[index + 1].lapQty && this.sayPriceObj.replies[index + 1].lapQty <= lapQty)) {
  262. this.onRemind('输入值会导致梯度重叠,请重新修改')
  263. this.sayPriceObj.replies[index].lapQty = ''
  264. this.validSayPrice.repliesLapQty = false
  265. } else {
  266. this.validSayPrice.repliesLapQty = true
  267. }
  268. },
  269. onReplyLapQtyInput: function (index) {
  270. this.sayPriceObj.replies[index].lapQty = this.sayPriceObj.replies[index].lapQty.replace(/[^\-?\d.]/g, '')
  271. let lapQty = this.sayPriceObj.replies[index].lapQty
  272. if (lapQty.length > 9) {
  273. this.sayPriceObj.replies[index].lapQty = lapQty.substring(0, 9)
  274. }
  275. },
  276. getLimitDownQty: function () {
  277. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  278. if (this.sayPriceObj.replies[i].lapQty) {
  279. return {
  280. lapQty: this.sayPriceObj.replies[i].lapQty,
  281. index: i
  282. }
  283. }
  284. }
  285. return {index: -1}
  286. },
  287. checkValid: function () {
  288. this.validSayPrice.repliesLapQty = true
  289. this.validSayPrice.repliesPrice = true
  290. this.validSayPrice.repliesleadtime = true
  291. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  292. console.log(this.sayPriceObj.replies)
  293. if (!/^[0-9]+([.]{1}[0-9]+)?$/.test(this.sayPriceObj.replies[i].lapQty) || this.sayPriceObj.replies[i].lapQty === '') {
  294. this.validSayPrice.repliesLapQty = false
  295. break
  296. } else if (!/^[0-9]+([.]{1}[0-9]+)?$/.test(this.sayPriceObj.replies[i].price) || this.sayPriceObj.replies[i].price === '') {
  297. this.validSayPrice.repliesPrice = false
  298. break
  299. }
  300. }
  301. if (/^\d+$/.test(this.validSayPrice.leadtime) || this.validSayPrice.leadtime === '') {
  302. this.validSayPrice.repliesleadtime = false
  303. }
  304. console.log(this.validSayPrice.repliesleadtime)
  305. console.log(this.validSayPrice.repliesLapQty)
  306. console.log(this.validSayPrice.repliesPrice)
  307. return this.validSayPrice.repliesleadtime && this.validSayPrice.repliesLapQty && this.validSayPrice.repliesPrice
  308. },
  309. onRemind: function (str) {
  310. this.remindText = str
  311. this.timeoutCount ++
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .mobile-modal {
  318. .mobile-modal-box {
  319. top: 1.66rem;
  320. left: 3%;
  321. right: 3%;
  322. width: 7rem;
  323. bottom: 1.66rem;
  324. margin: 0 auto;
  325. .say-price {
  326. background: #f3f3f3;
  327. padding: .18rem 0;
  328. width: 100%;
  329. overflow: hidden;
  330. height: 90%;
  331. .form-list {
  332. height: 7.53rem;
  333. background: #fff;
  334. padding-top: .2rem;
  335. > div {
  336. height: .7rem;
  337. line-height: .7rem;
  338. width: 5.82rem;
  339. font-size: .28rem;
  340. margin: 0 0 .18rem .3rem;
  341. input {
  342. height: .7rem;
  343. text-align: center;
  344. border: 1px solid #666;
  345. border-radius: .05rem;
  346. line-height: normal;
  347. padding: .1rem .2rem;
  348. }
  349. &.form-title {
  350. border: 1px solid #666;
  351. border-radius: .05rem;
  352. padding: 0 .07rem 0 .17rem;
  353. .fl {
  354. span {
  355. color: #666;
  356. }
  357. }
  358. .fr {
  359. position: relative;
  360. img {
  361. width: .12rem;
  362. height: .06rem;
  363. margin-left: .04rem;
  364. }
  365. > ul {
  366. position: absolute;
  367. top: .6rem;
  368. right: -.4rem;
  369. z-index: 1;
  370. width: 1.75rem;
  371. background: #fff;
  372. text-align: center;
  373. border-radius: .1rem;
  374. border: .02rem solid #dfdfdf;
  375. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  376. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  377. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  378. li {
  379. height: .52rem;
  380. line-height: .52rem;
  381. border-bottom: .02rem solid #dfdfdf;
  382. &:hover, &:active {
  383. background: #dedede;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. &.form-item {
  390. position: relative;
  391. input {
  392. width: 2.84rem;
  393. }
  394. i {
  395. position: absolute;
  396. right: -.5rem;
  397. top: 0;
  398. font-size: .36rem;
  399. &.icon-add {
  400. color: #4768f3;
  401. }
  402. &.icon-minus {
  403. color: #8d8d8d;
  404. }
  405. }
  406. }
  407. &.date {
  408. input {
  409. width: 4.6rem;
  410. }
  411. }
  412. }
  413. .say-price-btn {
  414. width: 6.44rem;
  415. }
  416. }
  417. }
  418. }
  419. }
  420. </style>