SayPrice.vue 14 KB

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