SayPrice.vue 13 KB

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