SayPrice.vue 13 KB

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