SayPrice.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. <ul class="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="onReplaceBrandBlur()">
  56. </div>
  57. <div class="replace">
  58. <span>型号</span>
  59. <input type="text" v-model="sayPriceObj.replaceCmpCode" class="fr" @blur="onReplaceCmpCodeBlur()">
  60. </div>
  61. <div class="replace">
  62. <span>规格</span>
  63. <input type="text" v-model="sayPriceObj.replaceSpec" class="fr" @blur="onReplaceSpecBlur()">
  64. </div>
  65. </template>
  66. <div class="form-item" v-for="(reply, index) in sayPriceObj.replies">
  67. <input type="text" placeholder="分段数量" class="fl" @blur="onReplyLapQtyBlur(index)" @input="onReplyLapQtyInput(index)" v-model="reply.lapQty">
  68. <input type="text" placeholder="分段单价" class="fr" @input="onReplyPriceInput(index)" @blur="onReplyPriceBlur(index)" v-model="reply.price">
  69. <i class="iconfont icon-minus" v-if="index > 0" @click="setReplies('sub', index)"></i>
  70. <i class="iconfont icon-add" v-if="index == 0 && sayPriceObj.replies.length < 5" @click="setReplies('add', index)"></i>
  71. </div>
  72. <div class="date">
  73. <span>交期(天)</span>
  74. <input type="text" placeholder="最大值" @input="onLeadtimeInput" @blur="onLeadtimeBlur" v-model="sayPriceObj.leadtime" class="fr">
  75. </div>
  76. <a class="say-price-btn" @click="commitSayPrice">确定</a>
  77. </div>
  78. </div>
  79. <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
  80. </div>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. import {RemindBox} from '~components/mobile/common'
  86. export default {
  87. data () {
  88. return {
  89. showCurrencyList: false,
  90. sayPriceObj: {
  91. currency: 'RMB',
  92. leadtime: '',
  93. replies: [
  94. {
  95. lapQty: '',
  96. price: ''
  97. }
  98. ],
  99. replaceBrand: '',
  100. replaceCmpCode: '',
  101. replaceSpec: ''
  102. },
  103. validSayPrice: {
  104. leadtime: false,
  105. repliesPrice: false,
  106. repliesLapQty: false,
  107. replaceBrand: false,
  108. replaceCmpCode: false,
  109. replaceSpec: false
  110. },
  111. sayType: 'current',
  112. remindText: '',
  113. timeoutCount: 0
  114. }
  115. },
  116. props: ['showSayPriceBox'],
  117. components: {
  118. RemindBox
  119. },
  120. watch: {
  121. showSayPriceBox: function (val, old) {
  122. if (val) {
  123. this.$nextTick(() => {
  124. this._initscroll()
  125. this.initScroll.scrollTo(0, 0, 0)
  126. })
  127. }
  128. this.sayType = 'current'
  129. this.resetSayPrice()
  130. }
  131. },
  132. mounted () {
  133. this.$nextTick(() => {
  134. document.addEventListener('click', this.checkCurrencySelect)
  135. this._initscroll()
  136. })
  137. },
  138. filters: {
  139. date: function (date) {
  140. if (date) {
  141. const d = new Date(Number(date))
  142. const year = d.getFullYear()
  143. const monthTemp = d.getMonth() + 1
  144. const month = monthTemp < 10 ? '0' + monthTemp : '' + monthTemp
  145. const day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate() + ' '
  146. return year + '-' + month + '-' + day
  147. } else {
  148. return '-'
  149. }
  150. }
  151. },
  152. computed: {
  153. purchaseDetail () {
  154. return JSON.parse(JSON.stringify(this.$store.state.applyPurchase.purchaseManList.purchaseManDetail.data))
  155. },
  156. user () {
  157. return this.$store.state.option.user
  158. }
  159. },
  160. methods: {
  161. cancel: function () {
  162. this.$emit('cancelSayPriceAction', false)
  163. },
  164. checkCurrencySelect: function () {
  165. this.showCurrencyList = false
  166. },
  167. setShowCurrencyList: function (event) {
  168. event.stopPropagation()
  169. this.showCurrencyList = !this.showCurrencyList
  170. },
  171. setCurrency: function (type) {
  172. this.sayPriceObj.currency = type
  173. this.showCurrencyList = false
  174. },
  175. resetSayPrice: function () {
  176. this.sayPriceObj = {
  177. currency: 'RMB',
  178. leadtime: '',
  179. replies: [
  180. {
  181. lapQty: '',
  182. price: ''
  183. }
  184. ],
  185. replaceBrand: '',
  186. replaceCmpCode: '',
  187. replaceSpec: ''
  188. }
  189. },
  190. setReplies: function (type, index) {
  191. if (type === 'add' && this.sayPriceObj.replies.length < 5) {
  192. this.sayPriceObj.replies.splice(this.sayPriceObj.replies.length, 0, {
  193. lapQty: '',
  194. price: ''
  195. })
  196. } else if (type === 'sub' && this.sayPriceObj.replies.length > 1) {
  197. this.sayPriceObj.replies.splice(index, 1)
  198. }
  199. this._initscroll()
  200. },
  201. commitSayPrice: function () {
  202. if (this.checkValid()) {
  203. let purchaseMan = JSON.parse(JSON.stringify(this.purchaseDetail))
  204. // this.showLoading = true
  205. purchaseMan.leadtime = this.sayPriceObj.leadtime
  206. purchaseMan.replies = this.sayPriceObj.replies
  207. purchaseMan.vendUU = this.user.data.enterprise.uu
  208. purchaseMan.vendUserUU = this.user.data.userUU
  209. purchaseMan.qutoApp = 'MALL'
  210. purchaseMan.currency = this.sayPriceObj.currency
  211. if (this.sayType === 'replace') {
  212. purchaseMan.replaceBrand = this.sayPriceObj.replaceBrand
  213. purchaseMan.replaceCmpCode = this.sayPriceObj.replaceCmpCode
  214. purchaseMan.replaceSpec = this.sayPriceObj.replaceSpec
  215. purchaseMan.isReplace = 1
  216. }
  217. this.$http.post('/inquiry/sale/item/save', purchaseMan).then(response => {
  218. this.showLoading = false
  219. if (response.data.success === false) {
  220. this.onRemind('response.data.message')
  221. } else {
  222. // this.onRemind('报价成功')
  223. this.resetSayPrice()
  224. this.$emit('cancelSayPriceAction', true, JSON.parse(response.data).quteId)
  225. }
  226. }, error => {
  227. console.log(error)
  228. this.onRemind('请勿重复报价或报价自己的求购')
  229. // this.showLoading = false
  230. })
  231. } else {
  232. this.onRemind('请输入正确的报价信息')
  233. }
  234. },
  235. onLeadtimeInput: function () {
  236. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.replace(/[^\-?\d.]/g, '')
  237. if (this.sayPriceObj.leadtime.length > 3) {
  238. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.substring(0, 3)
  239. }
  240. },
  241. onLeadtimeBlur: function () {
  242. if (!this.sayPriceObj.leadtime || this.sayPriceObj.leadtime < 1 || this.sayPriceObj.leadtime >= 1000 || this.sayPriceObj.leadtime.toString().indexOf('.') !== -1) {
  243. this.validSayPrice.leadtime = false
  244. this.onRemind('交期请填写1-999之间的正整数')
  245. } else {
  246. this.validSayPrice.leadtime = true
  247. }
  248. },
  249. onReplaceBrandBlur: function () {
  250. if (!this.sayPriceObj.replaceBrand || !this.sayPriceObj.replaceBrand.length) {
  251. this.validSayPrice.replaceBrand = false
  252. this.onRemind('请填写替代物料品牌')
  253. } else {
  254. this.validSayPrice.replaceBrand = true
  255. }
  256. },
  257. onReplaceCmpCodeBlur: function () {
  258. if (!this.sayPriceObj.replaceCmpCode || !this.sayPriceObj.replaceCmpCode.length) {
  259. this.validSayPrice.replaceCmpCode = false
  260. this.onRemind('请填写替代物料型号')
  261. } else {
  262. this.validSayPrice.replaceCmpCode = true
  263. }
  264. },
  265. onReplaceSpecBlur: function () {
  266. if (!this.sayPriceObj.replaceSpec || !this.sayPriceObj.replaceSpec.length) {
  267. this.validSayPrice.replaceSpec = false
  268. this.onRemind('请填写替代物料规格')
  269. } else {
  270. this.validSayPrice.replaceSpec = true
  271. }
  272. },
  273. onReplyPriceInput: function (index) {
  274. this.sayPriceObj.replies[index].price = this.sayPriceObj.replies[index].price.replace(/[^\-?\d.]/g, '')
  275. let price = this.sayPriceObj.replies[index].price
  276. if (price >= 10000) {
  277. this.sayPriceObj.replies[index].price = price.substring(0, 4)
  278. } else if (price.indexOf('.') > -1) {
  279. let arr = price.split('.')
  280. if (arr[0].length > 4) {
  281. this.sayPriceObj.replies[index].price = Number(arr[0].substring(0, 4) + '.' + arr[1])
  282. } else if (arr[1].length > 6) {
  283. this.sayPriceObj.replies[index].price = Number(arr[0] + '.' + arr[1].substring(0, 6))
  284. }
  285. }
  286. },
  287. onReplyPriceBlur: function (index) {
  288. let price = this.sayPriceObj.replies[index].price
  289. if (!price) {
  290. this.sayPriceObj.replies[index].price = ''
  291. this.onRemind('价格不能为空')
  292. this.validSayPrice.repliesPrice = false
  293. } else if (price <= 0) {
  294. this.sayPriceObj.replies[index].price = ''
  295. this.onRemind('输入值必须为正整数')
  296. this.validSayPrice.repliesPrice = false
  297. } else {
  298. this.validSayPrice.repliesPrice = true
  299. }
  300. },
  301. onReplyLapQtyBlur: function (index) {
  302. let lapQty = Number(this.sayPriceObj.replies[index].lapQty)
  303. let limitDownObj = this.getLimitDownQty()
  304. if (!lapQty || lapQty < 1) {
  305. this.sayPriceObj.replies[index].lapQty = ''
  306. this.onRemind('输入值必须为正整数')
  307. this.validSayPrice.repliesLapQty = false
  308. } else if (limitDownObj.index !== index && limitDownObj.lapQty > lapQty) {
  309. this.onRemind('输入值必须大于#该梯度的下限#')
  310. this.sayPriceObj.replies[index].lapQty = ''
  311. this.validSayPrice.repliesLapQty = false
  312. } 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)) {
  313. this.onRemind('输入值会导致梯度重叠,请重新修改')
  314. this.sayPriceObj.replies[index].lapQty = ''
  315. this.validSayPrice.repliesLapQty = false
  316. } else {
  317. this.validSayPrice.repliesLapQty = true
  318. }
  319. },
  320. onReplyLapQtyInput: function (index) {
  321. this.sayPriceObj.replies[index].lapQty = this.sayPriceObj.replies[index].lapQty.replace(/[^\-?\d.]/g, '')
  322. let lapQty = this.sayPriceObj.replies[index].lapQty
  323. if (lapQty.length > 9) {
  324. this.sayPriceObj.replies[index].lapQty = lapQty.substring(0, 9)
  325. }
  326. },
  327. getLimitDownQty: function () {
  328. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  329. if (this.sayPriceObj.replies[i].lapQty) {
  330. return {
  331. lapQty: this.sayPriceObj.replies[i].lapQty,
  332. index: i
  333. }
  334. }
  335. }
  336. return {index: -1}
  337. },
  338. checkValid: function () {
  339. this.validSayPrice.repliesLapQty = true
  340. this.validSayPrice.repliesPrice = true
  341. this.validSayPrice.leadtime = true
  342. let validReplace = this.sayType === 'replace' ? this.validSayPrice.replaceBrand && this.validSayPrice.replaceCmpCode && this.validSayPrice.replaceSpec : true
  343. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  344. if (!this.sayPriceObj.replies[i].lapQty || !/^[0-9]+([.]{1}[0-9]+)?$/.test(this.sayPriceObj.replies[i].lapQty) || this.sayPriceObj.replies[i].lapQty === '') {
  345. this.validSayPrice.repliesLapQty = false
  346. break
  347. } else if (!this.sayPriceObj.replies[i].price || !/^[0-9]+([.]{1}[0-9]+)?$/.test(this.sayPriceObj.replies[i].price) || this.sayPriceObj.replies[i].price === '') {
  348. this.validSayPrice.repliesPrice = false
  349. break
  350. }
  351. }
  352. if (!this.sayPriceObj.leadtime || !/^\d+$/.test(this.sayPriceObj.leadtime) || this.sayPriceObj.leadtime === '') {
  353. this.validSayPrice.leadtime = false
  354. }
  355. return this.validSayPrice.leadtime && this.validSayPrice.repliesLapQty && this.validSayPrice.repliesPrice && validReplace
  356. },
  357. onRemind: function (str) {
  358. this.remindText = str
  359. this.timeoutCount ++
  360. },
  361. setSayType: function (type) {
  362. this.sayType = type
  363. this.resetSayPrice()
  364. }
  365. }
  366. }
  367. </script>
  368. <style lang="scss" scoped>
  369. .mobile-modal {
  370. z-index: 1;
  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;
  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. span {
  472. display: inline-block;
  473. width: .66rem;
  474. text-align: left;
  475. }
  476. input {
  477. width: 5.1rem;
  478. }
  479. }
  480. }
  481. .say-price-btn {
  482. width: 6.44rem;
  483. }
  484. }
  485. }
  486. }
  487. }
  488. </style>