SayPrice.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <div class="mobile-modal" v-show="showSayPriceBox" @touchmove="preventTouchMove($event)" @click="clearSimilar">
  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 clearfix">
  9. <div class="pull-left">品牌:</div><span class="pull-left">{{purchaseDetail.inbrand || '-'}}</span>
  10. </div>
  11. <div class="content-line clearfix">
  12. <div class="pull-left">物料名称:</div><span class="pull-left" style="width:5rem;">{{purchaseDetail.prodTitle || '-'}}</span>
  13. </div>
  14. <div class="content-line clearfix">
  15. <div class="pull-left"> 型号:</div><span class="pull-left">{{purchaseDetail.cmpCode || '-'}}</span>
  16. </div>
  17. <div class="content-line clearfix">
  18. <div class="pull-left"> 规格:</div><span class="pull-left">{{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. <ul class="mobile-switch-say">
  35. <li class="inline-block" :class="{'active': sayType == 'current'}" @click="setSayType('current')">当前型号报价</li>
  36. <li class="inline-block" :class="{'active': sayType == 'replace'}" @click="setSayType('replace')">替代型号报价</li>
  37. </ul>
  38. <div class="form-title">
  39. <span class="fl">价格梯度<span>(PCS)</span></span>
  40. <span class="fr">
  41. <!--<span v-text="sayPriceObj.currency" @click="setShowCurrencyList($event)"></span>-->
  42. <span v-text="sayPriceObj.currency" @click="setShowCurrencyList($event)"></span>
  43. <!--<span v-if="purchaseDetail.custCurrency" v-text="purchaseDetail.custCurrency"></span>-->
  44. <img v-if="!showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-down.png" alt="">
  45. <img v-if="showCurrencyList" src="/images/mobile/@2x/applyPurchase/currency-arrow-up.png" alt="">
  46. <ul v-if="showCurrencyList">
  47. <li @click="setCurrency('RMB')">RMB</li>
  48. <li @click="setCurrency('USD')">USD</li>
  49. </ul>
  50. </span>
  51. </div>
  52. <template v-if="sayType == 'replace'">
  53. <div class="replace">
  54. <span>品牌</span>
  55. <input type="text" v-model="sayPriceObj.replaceBrand" class="fr" @blur="checkBrand" @input="onBrandChange" placeholder="请勿填中文符号">
  56. <ul class="similar" v-show="showSimilarBrandList && sayPriceObj.replaceBrand">
  57. <li v-for="sBrand in similarBrand" @click="setBrand(sBrand.nameEn)">{{sBrand.nameEn}}</li>
  58. </ul>
  59. </div>
  60. <div class="replace">
  61. <span>型号</span>
  62. <input type="text" v-model="sayPriceObj.replaceCmpCode" class="fr" @blur="checkCode" @input="onCodeChange" placeholder="请勿填中文符号">
  63. <ul class="similar" v-show="showSimilarCodeList && sayPriceObj.replaceCmpCode">
  64. <li v-for="sCode in similarCode" @click="setCode(sCode.code)">{{sCode.code}}</li>
  65. </ul>
  66. </div>
  67. <div class="replace">
  68. <span>规格</span>
  69. <input type="text" v-model="sayPriceObj.replaceSpec" class="fr" placeholder="(选填)">
  70. </div>
  71. </template>
  72. <div class="form-item" v-for="(reply, index) in sayPriceObj.replies">
  73. <input type="text" placeholder="分段数量" class="fl" @blur="onReplyLapQtyBlur(index)" @input="onReplyLapQtyInput(index)" v-model="reply.lapQty">
  74. <input type="text" placeholder="分段单价" class="fr" @input="onReplyPriceInput(index)" @blur="onReplyPriceBlur(index)" v-model="reply.price">
  75. <i class="iconfont icon-minus" v-if="index > 0" @click="setReplies('sub', index)"></i>
  76. <i class="iconfont icon-add" v-if="index == 0 && sayPriceObj.replies.length < 5" @click="setReplies('add', index)"></i>
  77. </div>
  78. <div class="date">
  79. <span>交期(天)</span>
  80. <input type="text" placeholder="最大值" @input="onLeadtimeInput" @blur="onLeadtimeBlur" v-model="sayPriceObj.leadtime" class="fr">
  81. </div>
  82. <div style="position: relative;height: 1rem;"></div>
  83. </div>
  84. </div>
  85. <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
  86. </div>
  87. <a class="say-price-btn" @click="commitSayPrice">确定</a>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import { sayPriceReplace } from '~utils/mixin'
  93. import {RemindBox} from '~components/mobile/common'
  94. export default {
  95. data () {
  96. return {
  97. showCurrencyList: false,
  98. sayPriceObj: {
  99. currency: 'RMB',
  100. leadtime: '',
  101. replies: [
  102. {
  103. lapQty: '',
  104. price: ''
  105. }
  106. ],
  107. replaceBrand: '',
  108. replaceCmpCode: '',
  109. replaceSpec: ''
  110. },
  111. validSayPrice: {
  112. leadtime: false,
  113. repliesPrice: false,
  114. repliesLapQty: false,
  115. replaceBrand: false,
  116. replaceCmpCode: false,
  117. replaceSpec: true
  118. },
  119. sayType: 'current',
  120. remindText: '',
  121. timeoutCount: 0
  122. }
  123. },
  124. mixins: [sayPriceReplace],
  125. props: ['showSayPriceBox'],
  126. components: {
  127. RemindBox
  128. },
  129. watch: {
  130. 'showSayPriceBox': {
  131. handler: function(val, old) {
  132. if (val) {
  133. this.$nextTick(() => {
  134. this._initscroll()
  135. })
  136. }
  137. this.sayType = 'current'
  138. this.resetSayPrice()
  139. },
  140. deep: true
  141. }
  142. },
  143. mounted () {
  144. this.$nextTick(() => {
  145. document.addEventListener('click', this.checkCurrencySelect)
  146. this._initscroll()
  147. this.initScroll.scrollTo(0, 0, 0)
  148. })
  149. },
  150. filters: {
  151. date: function (date) {
  152. if (date) {
  153. const d = new Date(Number(date))
  154. const year = d.getFullYear()
  155. const monthTemp = d.getMonth() + 1
  156. const month = monthTemp < 10 ? '0' + monthTemp : '' + monthTemp
  157. const day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate() + ' '
  158. return year + '-' + month + '-' + day
  159. } else {
  160. return '-'
  161. }
  162. }
  163. },
  164. computed: {
  165. purchaseDetail () {
  166. return JSON.parse(JSON.stringify(this.$store.state.applyPurchase.purchaseManList.purchaseManDetail.data))
  167. },
  168. user () {
  169. return this.$store.state.option.user
  170. }
  171. },
  172. methods: {
  173. cancel: function () {
  174. this.$emit('cancelSayPriceAction', false)
  175. },
  176. checkCurrencySelect: function () {
  177. this.showCurrencyList = false
  178. },
  179. setShowCurrencyList: function (event) {
  180. event.stopPropagation()
  181. this.showCurrencyList = !this.showCurrencyList
  182. },
  183. setCurrency: function (type) {
  184. this.sayPriceObj.currency = type
  185. this.showCurrencyList = false
  186. },
  187. resetSayPrice: function () {
  188. this.sayPriceObj = {
  189. currency: 'RMB',
  190. leadtime: '',
  191. replies: [
  192. {
  193. lapQty: '',
  194. price: ''
  195. }
  196. ],
  197. replaceBrand: '',
  198. replaceCmpCode: '',
  199. replaceSpec: ''
  200. }
  201. },
  202. setReplies: function (type, index) {
  203. if (type === 'add' && this.sayPriceObj.replies.length < 5) {
  204. this.sayPriceObj.replies.splice(this.sayPriceObj.replies.length, 0, {
  205. lapQty: '',
  206. price: ''
  207. })
  208. } else if (type === 'sub' && this.sayPriceObj.replies.length > 1) {
  209. this.sayPriceObj.replies.splice(index, 1)
  210. }
  211. this._initscroll()
  212. },
  213. commitSayPrice: function () {
  214. if (this.checkValid()) {
  215. let purchaseMan = JSON.parse(JSON.stringify(this.purchaseDetail))
  216. // this.showLoading = true
  217. purchaseMan.leadtime = this.sayPriceObj.leadtime
  218. purchaseMan.replies = this.sayPriceObj.replies
  219. purchaseMan.vendUU = this.user.data.enterprise.uu
  220. purchaseMan.vendUserUU = this.user.data.userUU
  221. purchaseMan.qutoApp = 'MALL'
  222. purchaseMan.currency = this.sayPriceObj.currency
  223. if (this.sayType === 'replace') {
  224. purchaseMan.replaceBrand = this.sayPriceObj.replaceBrand
  225. purchaseMan.replaceCmpCode = this.sayPriceObj.replaceCmpCode
  226. purchaseMan.replaceSpec = this.sayPriceObj.replaceSpec
  227. purchaseMan.isReplace = 1
  228. }
  229. this.$http.post('/inquiry/sale/item/saveQuote', purchaseMan).then(response => {
  230. this.showLoading = false
  231. if (response.data.success === false) {
  232. this.onRemind('response.data.message')
  233. } else {
  234. // this.onRemind('报价成功')
  235. this.resetSayPrice()
  236. this.$emit('cancelSayPriceAction', true, JSON.parse(response.data).quteId)
  237. }
  238. }, error => {
  239. console.log(error)
  240. this.onRemind('请勿重复报价或报价自己的求购')
  241. // this.showLoading = false
  242. })
  243. } else {
  244. this.onRemind('请输入正确的报价信息')
  245. }
  246. },
  247. onLeadtimeInput: function () {
  248. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.replace(/[^\-?\d.]/g, '')
  249. if (this.sayPriceObj.leadtime.length > 3) {
  250. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.substring(0, 3)
  251. }
  252. },
  253. onLeadtimeBlur: function () {
  254. if (!this.sayPriceObj.leadtime || this.sayPriceObj.leadtime < 1 || this.sayPriceObj.leadtime >= 1000 || this.sayPriceObj.leadtime.toString().indexOf('.') !== -1) {
  255. this.validSayPrice.leadtime = false
  256. this.onRemind('交期请填写1-999之间的正整数')
  257. } else {
  258. this.validSayPrice.leadtime = true
  259. }
  260. },
  261. onReplyPriceInput: function (index) {
  262. this.sayPriceObj.replies[index].price = this.sayPriceObj.replies[index].price.replace(/[^\-?\d.]/g, '')
  263. let price = this.sayPriceObj.replies[index].price
  264. if (price >= 10000) {
  265. this.sayPriceObj.replies[index].price = price.substring(0, 4)
  266. } else if (price.indexOf('.') > -1) {
  267. let arr = price.split('.')
  268. if (arr[0].length > 4) {
  269. this.sayPriceObj.replies[index].price = Number(arr[0].substring(0, 4) + '.' + arr[1])
  270. } else if (arr[1].length > 6) {
  271. this.sayPriceObj.replies[index].price = Number(arr[0] + '.' + arr[1].substring(0, 6))
  272. }
  273. }
  274. },
  275. onReplyPriceBlur: function (index) {
  276. let price = this.sayPriceObj.replies[index].price
  277. if (!price) {
  278. this.sayPriceObj.replies[index].price = ''
  279. this.onRemind('价格不能为空')
  280. this.validSayPrice.repliesPrice = false
  281. } else if (price <= 0) {
  282. this.sayPriceObj.replies[index].price = ''
  283. this.onRemind('输入值必须为正整数')
  284. this.validSayPrice.repliesPrice = false
  285. } else {
  286. this.validSayPrice.repliesPrice = true
  287. }
  288. },
  289. onReplyLapQtyBlur: function (index) {
  290. let lapQty = Number(this.sayPriceObj.replies[index].lapQty)
  291. let limitDownObj = this.getLimitDownQty()
  292. if (!lapQty || lapQty < 1) {
  293. this.sayPriceObj.replies[index].lapQty = ''
  294. this.onRemind('输入值必须为正整数')
  295. this.validSayPrice.repliesLapQty = false
  296. } else if (limitDownObj.index !== index && limitDownObj.lapQty > lapQty) {
  297. this.onRemind('输入值必须大于#该梯度的下限#')
  298. this.sayPriceObj.replies[index].lapQty = ''
  299. this.validSayPrice.repliesLapQty = false
  300. } 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)) {
  301. this.onRemind('输入值会导致梯度重叠,请重新修改')
  302. this.sayPriceObj.replies[index].lapQty = ''
  303. this.validSayPrice.repliesLapQty = false
  304. } else {
  305. this.validSayPrice.repliesLapQty = true
  306. }
  307. },
  308. onReplyLapQtyInput: function (index) {
  309. this.sayPriceObj.replies[index].lapQty = this.sayPriceObj.replies[index].lapQty.replace(/[^\-?\d.]/g, '')
  310. let lapQty = this.sayPriceObj.replies[index].lapQty
  311. if (lapQty.length > 9) {
  312. this.sayPriceObj.replies[index].lapQty = lapQty.substring(0, 9)
  313. }
  314. },
  315. getLimitDownQty: function () {
  316. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  317. if (this.sayPriceObj.replies[i].lapQty) {
  318. return {
  319. lapQty: this.sayPriceObj.replies[i].lapQty,
  320. index: i
  321. }
  322. }
  323. }
  324. return {index: -1}
  325. },
  326. checkValid: function () {
  327. this.validSayPrice.repliesLapQty = true
  328. this.validSayPrice.repliesPrice = true
  329. this.validSayPrice.leadtime = true
  330. let validReplace = this.sayType === 'replace' ? this.validSayPrice.replaceBrand && this.validSayPrice.replaceCmpCode && this.validSayPrice.replaceSpec : true
  331. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  332. if (!this.sayPriceObj.replies[i].lapQty || !/^[0-9]+([.]{1}[0-9]+)?$/.test(this.sayPriceObj.replies[i].lapQty) || this.sayPriceObj.replies[i].lapQty === '') {
  333. this.validSayPrice.repliesLapQty = false
  334. break
  335. } else if (!this.sayPriceObj.replies[i].price || !/^[0-9]+([.]{1}[0-9]+)?$/.test(this.sayPriceObj.replies[i].price) || this.sayPriceObj.replies[i].price === '') {
  336. this.validSayPrice.repliesPrice = false
  337. break
  338. }
  339. }
  340. if (!this.sayPriceObj.leadtime || !/^\d+$/.test(this.sayPriceObj.leadtime) || this.sayPriceObj.leadtime === '') {
  341. this.validSayPrice.leadtime = false
  342. }
  343. return this.validSayPrice.leadtime && this.validSayPrice.repliesLapQty && this.validSayPrice.repliesPrice && validReplace
  344. },
  345. onRemind: function (str) {
  346. this.remindText = str
  347. this.timeoutCount ++
  348. },
  349. setSayType: function (type) {
  350. this.sayType = type
  351. this.resetSayPrice()
  352. this.$nextTick(() => {
  353. this._initscroll()
  354. })
  355. }
  356. }
  357. }
  358. </script>
  359. <style lang="scss" scoped>
  360. .mobile-modal {
  361. z-index: 1;
  362. .base-info .content-line{
  363. height: auto;
  364. white-space: inherit;
  365. }
  366. .base-info .content-line span {
  367. width: 5.5rem;
  368. word-wrap:break-word;
  369. word-break:break-all;
  370. }
  371. .mobile-modal-box {
  372. top: 1.66rem;
  373. left: 3%;
  374. right: 3%;
  375. width: 7rem;
  376. bottom: 1.66rem;
  377. margin: 0 auto;
  378. .say-price {
  379. background: #f3f3f3;
  380. padding: .18rem 0 1rem;
  381. width: 100%;
  382. overflow: hidden;
  383. height: 90%;
  384. .base-info {
  385. margin-bottom: .12rem;
  386. }
  387. .form-list {
  388. /*height: 7.53rem;*/
  389. /*background: #fff;*/
  390. /*padding-top: .2rem;*/
  391. /*padding-bottom: 0.4rem;*/
  392. > div {
  393. height: .7rem;
  394. line-height: .7rem;
  395. width: 5.82rem;
  396. font-size: .28rem;
  397. margin: 0 0 .18rem .3rem;
  398. input {
  399. height: .7rem;
  400. text-align: center;
  401. border: 1px solid #666;
  402. border-radius: .05rem;
  403. line-height: normal;
  404. padding: .1rem .2rem;
  405. }
  406. &.form-title {
  407. border: 1px solid #666;
  408. border-radius: .05rem;
  409. padding: 0 .07rem 0 .17rem;
  410. background: #fff;
  411. .fl {
  412. span {
  413. color: #666;
  414. }
  415. }
  416. .fr {
  417. position: relative;
  418. img {
  419. width: .12rem;
  420. height: .06rem;
  421. margin-left: .04rem;
  422. }
  423. > ul {
  424. position: absolute;
  425. top: .6rem;
  426. right: -.4rem;
  427. z-index: 1;
  428. width: 1.75rem;
  429. background: #fff;
  430. text-align: center;
  431. border-radius: .1rem;
  432. border: .02rem solid #dfdfdf;
  433. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  434. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  435. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  436. li {
  437. height: .52rem;
  438. line-height: .52rem;
  439. border-bottom: .02rem solid #dfdfdf;
  440. &:hover, &:active {
  441. background: #dedede;
  442. }
  443. }
  444. }
  445. }
  446. }
  447. &.form-item {
  448. position: relative;
  449. input {
  450. width: 2.84rem;
  451. }
  452. i {
  453. position: absolute;
  454. right: -.5rem;
  455. top: 0;
  456. font-size: .36rem;
  457. &.icon-add {
  458. color: #4768f3;
  459. }
  460. &.icon-minus {
  461. color: #8d8d8d;
  462. }
  463. }
  464. }
  465. &.date {
  466. input {
  467. width: 4.6rem;
  468. }
  469. }
  470. &.replace {
  471. position: relative;
  472. span {
  473. display: inline-block;
  474. width: .66rem;
  475. text-align: left;
  476. }
  477. input {
  478. width: 5.1rem;
  479. text-align: left;
  480. }
  481. .similar {
  482. position: absolute;
  483. width: 5.1rem;
  484. max-height: 2.5rem;
  485. overflow-y: auto;
  486. z-index: 12;
  487. border: 1px solid #7e7e7e;
  488. border-radius: .05rem;
  489. left: .72rem;
  490. top: .68rem;
  491. background: #fff;
  492. li {
  493. height: .5rem;
  494. line-height: .5rem;
  495. font-size: .26rem;
  496. color: #999;
  497. padding-left: .19rem;
  498. &:focus, &:active, &:hover {
  499. background: #999;
  500. color: #fff;
  501. }
  502. }
  503. }
  504. }
  505. }
  506. }
  507. }
  508. .say-price-btn {
  509. width: 6.44rem;
  510. position: absolute;
  511. bottom: 0.1rem;
  512. left: 0;
  513. right: 0;
  514. }
  515. }
  516. }
  517. </style>