SayPrice.vue 19 KB

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