SayPrice.vue 14 KB

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