SayPrice.vue 15 KB

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