SayPrice.vue 14 KB

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