SayPrice.vue 15 KB

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