SayPrice.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. console.log(this.sayPriceObj)
  168. if (this.checkValid()) {
  169. let purchaseMan = JSON.parse(JSON.stringify(this.purchaseDetail))
  170. // this.showLoading = true
  171. purchaseMan.leadtime = this.sayPriceObj.leadtime
  172. purchaseMan.replies = this.sayPriceObj.replies
  173. purchaseMan.vendUU = this.user.data.enterprise.uu
  174. purchaseMan.vendUserUU = this.user.data.userUU
  175. purchaseMan.qutoApp = 'MALL'
  176. purchaseMan.currency = this.sayPriceObj.currency
  177. this.$http.post('/inquiry/sale/item/save', purchaseMan).then(response => {
  178. this.showLoading = false
  179. if (response.data.success === false) {
  180. this.onRemind('response.data.message')
  181. } else {
  182. // this.onRemind('报价成功')
  183. this.resetSayPrice()
  184. this.$emit('cancelSayPriceAction', true, JSON.parse(response.data).quteId)
  185. }
  186. }, error => {
  187. console.log(error)
  188. this.onRemind('请勿重复报价或报价自己的求购')
  189. // this.showLoading = false
  190. })
  191. } else {
  192. this.onRemind('请输入正确的报价信息')
  193. }
  194. },
  195. onLeadtimeInput: function () {
  196. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.replace(/[^\-?\d.]/g, '')
  197. if (this.sayPriceObj.leadtime.length > 3) {
  198. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.substring(0, 3)
  199. }
  200. },
  201. onLeadtimeBlur: function () {
  202. if (!this.sayPriceObj.leadtime || this.sayPriceObj.leadtime < 1 || this.sayPriceObj.leadtime >= 1000 || this.sayPriceObj.leadtime.toString().indexOf('.') !== -1) {
  203. this.validSayPrice.leadtime = false
  204. this.onRemind('交期请填写1-999之间的正整数')
  205. } else {
  206. this.validSayPrice.leadtime = true
  207. }
  208. },
  209. onReplyPriceInput: function (index) {
  210. this.sayPriceObj.replies[index].price = this.sayPriceObj.replies[index].price.replace(/[^\-?\d.]/g, '')
  211. let price = this.sayPriceObj.replies[index].price
  212. if (price >= 10000) {
  213. this.sayPriceObj.replies[index].price = price.substring(0, 4)
  214. } else if (price.indexOf('.') > -1) {
  215. let arr = price.split('.')
  216. if (arr[0].length > 4) {
  217. this.sayPriceObj.replies[index].price = Number(arr[0].substring(0, 4) + '.' + arr[1])
  218. } else if (arr[1].length > 6) {
  219. this.sayPriceObj.replies[index].price = Number(arr[0] + '.' + arr[1].substring(0, 6))
  220. }
  221. }
  222. },
  223. onReplyPriceBlur: function (index) {
  224. let price = this.sayPriceObj.replies[index].price
  225. if (!price) {
  226. this.sayPriceObj.replies[index].price = ''
  227. this.onRemind('价格不能为空')
  228. this.validSayPrice.repliesPrice = false
  229. } else if (price <= 0) {
  230. this.sayPriceObj.replies[index].price = ''
  231. this.onRemind('输入值必须为正整数')
  232. this.validSayPrice.repliesPrice = false
  233. } else {
  234. this.validSayPrice.repliesPrice = true
  235. }
  236. },
  237. onReplyLapQtyBlur: function (index) {
  238. let lapQty = Number(this.sayPriceObj.replies[index].lapQty)
  239. let limitDownObj = this.getLimitDownQty()
  240. if (!lapQty || lapQty < 1) {
  241. this.sayPriceObj.replies[index].lapQty = ''
  242. this.onRemind('输入值必须为正整数')
  243. this.validSayPrice.repliesLapQty = false
  244. } else if (limitDownObj.index !== index && limitDownObj.lapQty > lapQty) {
  245. this.onRemind('输入值必须大于#该梯度的下限#')
  246. this.sayPriceObj.replies[index].lapQty = ''
  247. this.validSayPrice.repliesLapQty = false
  248. } 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)) {
  249. this.onRemind('输入值会导致梯度重叠,请重新修改')
  250. this.sayPriceObj.replies[index].lapQty = ''
  251. this.validSayPrice.repliesLapQty = false
  252. } else {
  253. this.validSayPrice.repliesLapQty = true
  254. }
  255. },
  256. onReplyLapQtyInput: function (index) {
  257. this.sayPriceObj.replies[index].lapQty = this.sayPriceObj.replies[index].lapQty.replace(/[^\-?\d.]/g, '')
  258. let lapQty = this.sayPriceObj.replies[index].lapQty
  259. if (lapQty.length > 9) {
  260. this.sayPriceObj.replies[index].lapQty = lapQty.substring(0, 9)
  261. }
  262. },
  263. getLimitDownQty: function () {
  264. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  265. if (this.sayPriceObj.replies[i].lapQty) {
  266. return {
  267. lapQty: this.sayPriceObj.replies[i].lapQty,
  268. index: i
  269. }
  270. }
  271. }
  272. return {index: -1}
  273. },
  274. checkValid: function () {
  275. this.validSayPrice.repliesLapQty = true
  276. this.validSayPrice.repliesPrice = true
  277. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  278. if (!this.sayPriceObj.replies[i].lapQty) {
  279. this.validSayPrice.repliesLapQty = false
  280. break
  281. } else if (!this.sayPriceObj.replies[i].price) {
  282. this.validSayPrice.repliesPrice = false
  283. break
  284. }
  285. }
  286. console.log(this.validSayPrice.leadtime + '-' + this.validSayPrice.repliesLapQty + '-' + this.validSayPrice.repliesPrice)
  287. return this.validSayPrice.leadtime && this.validSayPrice.repliesLapQty && this.validSayPrice.repliesPrice
  288. },
  289. onRemind: function (str) {
  290. this.remindText = str
  291. this.timeoutCount ++
  292. }
  293. }
  294. }
  295. </script>
  296. <style lang="scss" scoped>
  297. .mobile-modal {
  298. .mobile-modal-box {
  299. top: 5%;
  300. left: 3%;
  301. right: 3%;
  302. width: 7rem;
  303. bottom: 3%;
  304. margin: 0 auto;
  305. .say-price {
  306. background: #f3f3f3;
  307. padding: .18rem 0;
  308. width: 100%;
  309. overflow-y: auto;
  310. height: 90%;
  311. .form-list {
  312. height: 7.53rem;
  313. background: #fff;
  314. padding-top: .2rem;
  315. > div {
  316. height: .7rem;
  317. line-height: .7rem;
  318. width: 5.82rem;
  319. font-size: .28rem;
  320. margin: 0 0 .18rem .3rem;
  321. input {
  322. height: .7rem;
  323. text-align: center;
  324. border: 1px solid #666;
  325. border-radius: .05rem;
  326. line-height: normal;
  327. padding: .1rem .2rem;
  328. }
  329. &.form-title {
  330. border: 1px solid #666;
  331. border-radius: .05rem;
  332. padding: 0 .07rem 0 .17rem;
  333. .fl {
  334. span {
  335. color: #666;
  336. }
  337. }
  338. .fr {
  339. position: relative;
  340. img {
  341. width: .12rem;
  342. height: .06rem;
  343. margin-left: .04rem;
  344. }
  345. > ul {
  346. position: absolute;
  347. top: .6rem;
  348. right: -.4rem;
  349. z-index: 1;
  350. width: 1.75rem;
  351. background: #fff;
  352. text-align: center;
  353. border-radius: .1rem;
  354. border: .02rem solid #dfdfdf;
  355. -webkit-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  356. -moz-box-shadow: 0 0 .12rem .02rem #e2d9d975;
  357. box-shadow: 0 0 .12rem .02rem #e2d9d975;
  358. li {
  359. height: .52rem;
  360. line-height: .52rem;
  361. border-bottom: .02rem solid #dfdfdf;
  362. &:hover, &:active {
  363. background: #dedede;
  364. }
  365. }
  366. }
  367. }
  368. }
  369. &.form-item {
  370. position: relative;
  371. input {
  372. width: 2.84rem;
  373. }
  374. i {
  375. position: absolute;
  376. right: -.5rem;
  377. top: 0;
  378. font-size: .36rem;
  379. &.icon-add {
  380. color: #4768f3;
  381. }
  382. &.icon-minus {
  383. color: #8d8d8d;
  384. }
  385. }
  386. }
  387. &.date {
  388. input {
  389. width: 4.6rem;
  390. }
  391. }
  392. }
  393. .say-price-btn {
  394. width: 6.44rem;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. </style>