SayPrice.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div class="mobile-modal" v-show="showSayPriceBox" @touchmove.self="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.prodTitle || '-'}}</span>
  10. </div>
  11. <div class="content-line">
  12. 型号:<span>{{purchaseDetail.cmpCode || '-'}}</span>
  13. </div>
  14. <div class="content-line">
  15. 品牌:<span>{{purchaseDetail.inbrand || '-'}}</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. touchmove(e) {
  144. e.preventDefault()
  145. },
  146. cancel: function () {
  147. this.$emit('cancelSayPriceAction', false)
  148. },
  149. checkCurrencySelect: function () {
  150. this.showCurrencyList = false
  151. },
  152. setShowCurrencyList: function (event) {
  153. event.stopPropagation()
  154. this.showCurrencyList = !this.showCurrencyList
  155. },
  156. setCurrency: function (type) {
  157. this.sayPriceObj.currency = type
  158. this.showCurrencyList = false
  159. },
  160. resetSayPrice: function () {
  161. this.sayPriceObj = {
  162. currency: 'RMB',
  163. leadtime: '',
  164. replies: [
  165. {
  166. lapQty: '',
  167. price: ''
  168. }
  169. ]
  170. }
  171. },
  172. setReplies: function (type, index) {
  173. if (type === 'add' && this.sayPriceObj.replies.length < 5) {
  174. this.sayPriceObj.replies.splice(this.sayPriceObj.replies.length, 0, {
  175. lapQty: '',
  176. price: ''
  177. })
  178. } else if (type === 'sub' && this.sayPriceObj.replies.length > 1) {
  179. this.sayPriceObj.replies.splice(index, 1)
  180. }
  181. this._initscroll()
  182. },
  183. commitSayPrice: function () {
  184. if (this.checkValid()) {
  185. let purchaseMan = JSON.parse(JSON.stringify(this.purchaseDetail))
  186. // this.showLoading = true
  187. purchaseMan.leadtime = this.sayPriceObj.leadtime
  188. purchaseMan.replies = this.sayPriceObj.replies
  189. purchaseMan.vendUU = this.user.data.enterprise.uu
  190. purchaseMan.vendUserUU = this.user.data.userUU
  191. purchaseMan.qutoApp = 'MALL'
  192. purchaseMan.currency = this.sayPriceObj.currency
  193. this.$http.post('/inquiry/sale/item/save', purchaseMan).then(response => {
  194. this.showLoading = false
  195. if (response.data.success === false) {
  196. this.onRemind('response.data.message')
  197. } else {
  198. // this.onRemind('报价成功')
  199. this.resetSayPrice()
  200. this.$emit('cancelSayPriceAction', true, JSON.parse(response.data).quteId)
  201. }
  202. }, error => {
  203. console.log(error)
  204. this.onRemind('请勿重复报价或报价自己的求购')
  205. // this.showLoading = false
  206. })
  207. } else {
  208. this.onRemind('请输入正确的报价信息')
  209. }
  210. },
  211. onLeadtimeInput: function () {
  212. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.replace(/[^\-?\d.]/g, '')
  213. if (this.sayPriceObj.leadtime.length > 3) {
  214. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.substring(0, 3)
  215. }
  216. },
  217. onLeadtimeBlur: function () {
  218. if (!this.sayPriceObj.leadtime || this.sayPriceObj.leadtime < 1 || this.sayPriceObj.leadtime >= 1000 || this.sayPriceObj.leadtime.toString().indexOf('.') !== -1) {
  219. this.validSayPrice.leadtime = false
  220. this.onRemind('交期请填写1-999之间的正整数')
  221. } else {
  222. this.validSayPrice.leadtime = true
  223. }
  224. },
  225. onReplyPriceInput: function (index) {
  226. this.sayPriceObj.replies[index].price = this.sayPriceObj.replies[index].price.replace(/[^\-?\d.]/g, '')
  227. let price = this.sayPriceObj.replies[index].price
  228. if (price >= 10000) {
  229. this.sayPriceObj.replies[index].price = price.substring(0, 4)
  230. } else if (price.indexOf('.') > -1) {
  231. let arr = price.split('.')
  232. if (arr[0].length > 4) {
  233. this.sayPriceObj.replies[index].price = Number(arr[0].substring(0, 4) + '.' + arr[1])
  234. } else if (arr[1].length > 6) {
  235. this.sayPriceObj.replies[index].price = Number(arr[0] + '.' + arr[1].substring(0, 6))
  236. }
  237. }
  238. },
  239. onReplyPriceBlur: function (index) {
  240. let price = this.sayPriceObj.replies[index].price
  241. if (!price) {
  242. this.sayPriceObj.replies[index].price = ''
  243. this.onRemind('价格不能为空')
  244. this.validSayPrice.repliesPrice = false
  245. } else if (price <= 0) {
  246. this.sayPriceObj.replies[index].price = ''
  247. this.onRemind('输入值必须为正整数')
  248. this.validSayPrice.repliesPrice = false
  249. } else {
  250. this.validSayPrice.repliesPrice = true
  251. }
  252. },
  253. onReplyLapQtyBlur: function (index) {
  254. let lapQty = Number(this.sayPriceObj.replies[index].lapQty)
  255. let limitDownObj = this.getLimitDownQty()
  256. if (!lapQty || lapQty < 1) {
  257. this.sayPriceObj.replies[index].lapQty = ''
  258. this.onRemind('输入值必须为正整数')
  259. this.validSayPrice.repliesLapQty = false
  260. } else if (limitDownObj.index !== index && limitDownObj.lapQty > lapQty) {
  261. this.onRemind('输入值必须大于#该梯度的下限#')
  262. this.sayPriceObj.replies[index].lapQty = ''
  263. this.validSayPrice.repliesLapQty = false
  264. } 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)) {
  265. this.onRemind('输入值会导致梯度重叠,请重新修改')
  266. this.sayPriceObj.replies[index].lapQty = ''
  267. this.validSayPrice.repliesLapQty = false
  268. } else {
  269. this.validSayPrice.repliesLapQty = true
  270. }
  271. },
  272. onReplyLapQtyInput: function (index) {
  273. this.sayPriceObj.replies[index].lapQty = this.sayPriceObj.replies[index].lapQty.replace(/[^\-?\d.]/g, '')
  274. let lapQty = this.sayPriceObj.replies[index].lapQty
  275. if (lapQty.length > 9) {
  276. this.sayPriceObj.replies[index].lapQty = lapQty.substring(0, 9)
  277. }
  278. },
  279. getLimitDownQty: function () {
  280. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  281. if (this.sayPriceObj.replies[i].lapQty) {
  282. return {
  283. lapQty: this.sayPriceObj.replies[i].lapQty,
  284. index: i
  285. }
  286. }
  287. }
  288. return {index: -1}
  289. },
  290. checkValid: function () {
  291. this.validSayPrice.repliesLapQty = true
  292. this.validSayPrice.repliesPrice = true
  293. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  294. if (!this.sayPriceObj.replies[i].lapQty) {
  295. this.validSayPrice.repliesLapQty = false
  296. break
  297. } else if (!this.sayPriceObj.replies[i].price) {
  298. this.validSayPrice.repliesPrice = false
  299. break
  300. }
  301. }
  302. // console.log(this.validSayPrice.leadtime + '-' + this.validSayPrice.repliesLapQty + '-' + this.validSayPrice.repliesPrice)
  303. return this.validSayPrice.leadtime && this.validSayPrice.repliesLapQty && this.validSayPrice.repliesPrice
  304. },
  305. onRemind: function (str) {
  306. this.remindText = str
  307. this.timeoutCount ++
  308. }
  309. }
  310. }
  311. </script>
  312. <style lang="scss" scoped>
  313. .mobile-modal {
  314. .mobile-modal-box {
  315. top: 10%;
  316. left: 3%;
  317. right: 3%;
  318. width: 7rem;
  319. bottom: 10%;
  320. margin: 0 auto;
  321. .say-price {
  322. background: #f3f3f3;
  323. padding: .18rem 0;
  324. width: 100%;
  325. overflow: hidden;
  326. height: 90%;
  327. .form-list {
  328. height: 7.53rem;
  329. background: #fff;
  330. padding-top: .2rem;
  331. > div {
  332. height: .7rem;
  333. line-height: .7rem;
  334. width: 5.82rem;
  335. font-size: .28rem;
  336. margin: 0 0 .18rem .3rem;
  337. input {
  338. height: .7rem;
  339. text-align: center;
  340. border: 1px solid #666;
  341. border-radius: .05rem;
  342. line-height: normal;
  343. padding: .1rem .2rem;
  344. }
  345. &.form-title {
  346. border: 1px solid #666;
  347. border-radius: .05rem;
  348. padding: 0 .07rem 0 .17rem;
  349. .fl {
  350. span {
  351. color: #666;
  352. }
  353. }
  354. .fr {
  355. position: relative;
  356. img {
  357. width: .12rem;
  358. height: .06rem;
  359. margin-left: .04rem;
  360. }
  361. > ul {
  362. position: absolute;
  363. top: .6rem;
  364. right: -.4rem;
  365. z-index: 1;
  366. width: 1.75rem;
  367. background: #fff;
  368. text-align: center;
  369. border-radius: .1rem;
  370. border: .02rem solid #dfdfdf;
  371. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  372. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  373. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  374. li {
  375. height: .52rem;
  376. line-height: .52rem;
  377. border-bottom: .02rem solid #dfdfdf;
  378. &:hover, &:active {
  379. background: #dedede;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. &.form-item {
  386. position: relative;
  387. input {
  388. width: 2.84rem;
  389. }
  390. i {
  391. position: absolute;
  392. right: -.5rem;
  393. top: 0;
  394. font-size: .36rem;
  395. &.icon-add {
  396. color: #4768f3;
  397. }
  398. &.icon-minus {
  399. color: #8d8d8d;
  400. }
  401. }
  402. }
  403. &.date {
  404. input {
  405. width: 4.6rem;
  406. }
  407. }
  408. }
  409. .say-price-btn {
  410. width: 6.44rem;
  411. }
  412. }
  413. }
  414. }
  415. }
  416. </style>