SayPrice.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  291. if (!this.sayPriceObj.replies[i].lapQty) {
  292. this.validSayPrice.repliesLapQty = false
  293. break
  294. } else if (!this.sayPriceObj.replies[i].price) {
  295. this.validSayPrice.repliesPrice = false
  296. break
  297. }
  298. }
  299. // console.log(this.validSayPrice.leadtime + '-' + this.validSayPrice.repliesLapQty + '-' + this.validSayPrice.repliesPrice)
  300. return this.validSayPrice.leadtime && this.validSayPrice.repliesLapQty && this.validSayPrice.repliesPrice
  301. },
  302. onRemind: function (str) {
  303. this.remindText = str
  304. this.timeoutCount ++
  305. }
  306. }
  307. }
  308. </script>
  309. <style lang="scss" scoped>
  310. .mobile-modal {
  311. .mobile-modal-box {
  312. top: 10%;
  313. left: 3%;
  314. right: 3%;
  315. width: 7rem;
  316. bottom: 10%;
  317. margin: 0 auto;
  318. .say-price {
  319. background: #f3f3f3;
  320. padding: .18rem 0;
  321. width: 100%;
  322. overflow: hidden;
  323. height: 90%;
  324. .form-list {
  325. height: 7.53rem;
  326. background: #fff;
  327. padding-top: .2rem;
  328. > div {
  329. height: .7rem;
  330. line-height: .7rem;
  331. width: 5.82rem;
  332. font-size: .28rem;
  333. margin: 0 0 .18rem .3rem;
  334. input {
  335. height: .7rem;
  336. text-align: center;
  337. border: 1px solid #666;
  338. border-radius: .05rem;
  339. line-height: normal;
  340. padding: .1rem .2rem;
  341. }
  342. &.form-title {
  343. border: 1px solid #666;
  344. border-radius: .05rem;
  345. padding: 0 .07rem 0 .17rem;
  346. .fl {
  347. span {
  348. color: #666;
  349. }
  350. }
  351. .fr {
  352. position: relative;
  353. img {
  354. width: .12rem;
  355. height: .06rem;
  356. margin-left: .04rem;
  357. }
  358. > ul {
  359. position: absolute;
  360. top: .6rem;
  361. right: -.4rem;
  362. z-index: 1;
  363. width: 1.75rem;
  364. background: #fff;
  365. text-align: center;
  366. border-radius: .1rem;
  367. border: .02rem solid #dfdfdf;
  368. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  369. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  370. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  371. li {
  372. height: .52rem;
  373. line-height: .52rem;
  374. border-bottom: .02rem solid #dfdfdf;
  375. &:hover, &:active {
  376. background: #dedede;
  377. }
  378. }
  379. }
  380. }
  381. }
  382. &.form-item {
  383. position: relative;
  384. input {
  385. width: 2.84rem;
  386. }
  387. i {
  388. position: absolute;
  389. right: -.5rem;
  390. top: 0;
  391. font-size: .36rem;
  392. &.icon-add {
  393. color: #4768f3;
  394. }
  395. &.icon-minus {
  396. color: #8d8d8d;
  397. }
  398. }
  399. }
  400. &.date {
  401. input {
  402. width: 4.6rem;
  403. }
  404. }
  405. }
  406. .say-price-btn {
  407. width: 6.44rem;
  408. }
  409. }
  410. }
  411. }
  412. }
  413. </style>