SayPrice.vue 20 KB

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