SayPrice.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div>
  3. <div class="modal-wrap" v-if="currentSayPriceIndex > -1">
  4. <div class="say-price-box" >
  5. <div class="title">
  6. <div>型号:<span :title="purchaseManList.content[currentSayPriceIndex].cmpCode">{{purchaseManList.content[currentSayPriceIndex].cmpCode}}</span></div>
  7. <div>品牌:<span :title="purchaseManList.content[currentSayPriceIndex].inbrand">{{purchaseManList.content[currentSayPriceIndex].inbrand}}</span></div>
  8. <i class="fa fa-close" @click="cancelSayPrice"></i>
  9. </div>
  10. <div class="content">
  11. <div class="content-line">
  12. <div class="form-item form-left date">
  13. <span><i>*</i>交期:</span>
  14. <input type="number" class="form-control" placeholder="天数" @input="onLeadtimeInput" @blur="onLeadtimeBlur" v-model="sayPriceObj.leadtime">
  15. <!-- -
  16. <input type="text" class="form-control" placeholder="天数">-->
  17. </div>
  18. <!--<div class="form-item form-upload">
  19. <label>
  20. <span><i>+</i>添加附件</span>
  21. <input type="file">
  22. </label>
  23. &lt;!&ndash;<div>
  24. <span>我是Excel的名字111</span>
  25. <i class="fa fa-times-circle"></i>
  26. <a href="">更换</a>
  27. </div>&ndash;&gt;
  28. </div>-->
  29. </div>
  30. <div class="content-line" v-for="(reply, index) in sayPriceObj.replies">
  31. <div class="form-item form-left">
  32. <span><i>*</i>价格梯度:</span>
  33. <input type="number" class="form-control" @blur="onReplyLapQtyBlur(index)" @input="onReplyLapQtyInput(index)" v-model="reply.lapQty" placeholder="数量">
  34. <!-- -
  35. <input type="text" class="form-control" placeholder="数量">-->
  36. </div>
  37. <div class="form-item form-right">
  38. <span><i>*</i>单价<span v-if="purchaseManList.content[currentSayPriceIndex].currency" v-text="purchaseManList.content[currentSayPriceIndex].currency == 'USD' ? '($)' : '(¥)'"></span>:</span>
  39. <!--{{purchaseManList.content[currentSayPriceIndex].currency == 'USD' ? '$' : '¥'}})-->
  40. <select v-if="!purchaseManList.content[currentSayPriceIndex].currency" v-model="sayPriceObj.currency">
  41. <option value="RMB">¥</option>
  42. <option value="USD">$</option>
  43. </select>
  44. <input type="number" class="form-control" @input="onReplyPriceInput(index)" @blur="onReplyPriceBlur(index)" placeholder="单价" v-model="reply.price">
  45. <i class="fa fa-minus-circle" v-if="sayPriceObj.replies.length > 1" @click="setReplies('sub', index)"></i>
  46. <i class="fa fa-plus-circle" v-if="sayPriceObj.replies.length < 5" @click="setReplies('add', index)"></i>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="operate">
  51. <span @click="commitSayPrice">确定</span>
  52. <span @click="cancelSayPrice">取消</span>
  53. </div>
  54. </div>
  55. </div>
  56. <loading v-show="showLoading"></loading>
  57. </div>
  58. </template>
  59. <script>
  60. import Loading from '~components/common/loading/PageLoading.vue'
  61. export default {
  62. props: {
  63. purchase: Object,
  64. current: Number
  65. },
  66. data () {
  67. return {
  68. sayPriceObj: {
  69. currency: 'RMB',
  70. leadtime: '',
  71. replies: [
  72. {
  73. lapQty: '',
  74. price: ''
  75. }
  76. ]
  77. },
  78. validSayPrice: {
  79. leadtime: false,
  80. repliesPrice: false,
  81. repliesLapQty: false
  82. },
  83. showLoading: false
  84. }
  85. },
  86. components: {
  87. Loading
  88. },
  89. computed: {
  90. purchaseManList () {
  91. return this.purchase || []
  92. },
  93. currentSayPriceIndex () {
  94. this.resetSayPrice()
  95. return this.current
  96. },
  97. user () {
  98. return this.$store.state.option.user
  99. }
  100. },
  101. methods: {
  102. setIndex: function (index) {
  103. this.$emit('sayPriceIndexAction', index)
  104. },
  105. sayPrice: function (purchaseMan, index) {
  106. if (this.user.logged) {
  107. if (this.user.data.enterprise.uu) {
  108. if (this.user.data.enterprise.isVendor && this.user.data.enterprise.isVendor !== '1690') {
  109. this.resetSayPrice()
  110. purchaseMan.active = true
  111. this.setIndex(index)
  112. } else {
  113. this.$message.error('抱歉,您需开通卖家功能才可报价')
  114. }
  115. } else {
  116. this.$message.error('个人账户不可报价')
  117. }
  118. } else {
  119. this.$router.push('/auth/login?returnUrl=' + window.location.href)
  120. }
  121. },
  122. cancelSayPrice: function () {
  123. this.$emit('cancelSayPriceAction')
  124. },
  125. commitSayPrice: function () {
  126. if (this.checkValid()) {
  127. let purchaseMan = this.purchaseManList.content[this.currentSayPriceIndex]
  128. this.showLoading = true
  129. purchaseMan.leadtime = this.sayPriceObj.leadtime
  130. purchaseMan.replies = this.sayPriceObj.replies
  131. purchaseMan.vendUU = this.user.data.enterprise.uu
  132. purchaseMan.vendorUserUU = this.user.data.userUU
  133. purchaseMan.qutoApp = 'MALL'
  134. if (!purchaseMan.currency) {
  135. purchaseMan.currency = this.sayPriceObj.currency
  136. }
  137. this.$http.post('/inquiry/sale/item/save', purchaseMan).then(response => {
  138. this.showLoading = false
  139. if (response.data.success === false) {
  140. this.$message.error(response.data.message)
  141. } else {
  142. this.$message.success('报价成功')
  143. this.resetSayPrice()
  144. this.resetList()
  145. }
  146. }, error => {
  147. console.log(error)
  148. this.$message.error('请勿重复报价或报价自己的求购')
  149. this.showLoading = false
  150. })
  151. } else {
  152. this.$message.error('请输入正确的报价信息')
  153. }
  154. },
  155. resetList: function () {
  156. this.$emit('resetListAction')
  157. },
  158. resetSayPrice: function () {
  159. this.sayPriceObj = {
  160. currency: 'RMB',
  161. leadtime: '',
  162. replies: [
  163. {
  164. lapQty: '',
  165. price: ''
  166. }
  167. ]
  168. }
  169. },
  170. onLeadtimeInput: function () {
  171. if (this.sayPriceObj.leadtime.length > 2) {
  172. this.sayPriceObj.leadtime = this.sayPriceObj.leadtime.substring(0, 2)
  173. }
  174. },
  175. onLeadtimeBlur: function () {
  176. if (!this.sayPriceObj.leadtime || this.sayPriceObj.leadtime < 1 || this.sayPriceObj.leadtime > 31 || this.sayPriceObj.leadtime.toString().indexOf('.') !== -1) {
  177. this.validSayPrice.leadtime = false
  178. this.$message.error('交期只能填写1-31之间的整数值')
  179. } else {
  180. this.validSayPrice.leadtime = true
  181. }
  182. },
  183. onReplyPriceInput: function (index) {
  184. let price = this.sayPriceObj.replies[index].price
  185. if (price >= 10000) {
  186. this.sayPriceObj.replies[index].price = price.substring(0, 4)
  187. } else if (price.indexOf('.') > -1) {
  188. let arr = price.split('.')
  189. if (arr[0].length > 4) {
  190. this.sayPriceObj.replies[index].price = Number(arr[0].substring(0, 4) + '.' + arr[1])
  191. } else if (arr[1].length > 6) {
  192. this.sayPriceObj.replies[index].price = Number(arr[0] + '.' + arr[1].substring(0, 6))
  193. }
  194. }
  195. },
  196. onReplyPriceBlur: function (index) {
  197. let price = this.sayPriceObj.replies[index].price
  198. if (!price) {
  199. this.sayPriceObj.replies[index].price = ''
  200. this.$message.error('价格不能为空')
  201. this.validSayPrice.repliesPrice = false
  202. } else if (price <= 0) {
  203. this.sayPriceObj.replies[index].price = ''
  204. this.$message.error('输入值必须为正整数')
  205. this.validSayPrice.repliesPrice = false
  206. } else {
  207. this.validSayPrice.repliesPrice = true
  208. }
  209. },
  210. onReplyLapQtyBlur: function (index) {
  211. let lapQty = this.sayPriceObj.replies[index].lapQty
  212. let limitDownObj = this.getLimitDownQty()
  213. if (!lapQty || lapQty < 1) {
  214. this.sayPriceObj.replies[index].lapQty = ''
  215. this.$message.error('输入值必须为正整数')
  216. this.validSayPrice.repliesLapQty = false
  217. } else if (limitDownObj.index !== index && limitDownObj.lapQty > lapQty) {
  218. this.$message.error('输入值必须大于#该梯度的下限#')
  219. this.sayPriceObj.replies[index].lapQty = ''
  220. this.validSayPrice.repliesLapQty = false
  221. } 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)) {
  222. this.$message.error('输入值会导致梯度重叠,请重新修改')
  223. this.sayPriceObj.replies[index].lapQty = ''
  224. this.validSayPrice.repliesLapQty = false
  225. } else {
  226. this.validSayPrice.repliesLapQty = true
  227. }
  228. },
  229. onReplyLapQtyInput: function (index) {
  230. let lapQty = this.sayPriceObj.replies[index].lapQty
  231. if (lapQty.length > 9) {
  232. this.sayPriceObj.replies[index].lapQty = lapQty.substring(0, 9)
  233. }
  234. },
  235. getLimitDownQty: function () {
  236. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  237. if (this.sayPriceObj.replies[i].lapQty) {
  238. return {
  239. lapQty: this.sayPriceObj.replies[i].lapQty,
  240. index: i
  241. }
  242. }
  243. }
  244. return {index: -1}
  245. },
  246. checkValid: function () {
  247. for (let i = 0; i < this.sayPriceObj.replies.length; i++) {
  248. if (!this.sayPriceObj.replies[i].lapQty || !this.sayPriceObj.replies[i].price) {
  249. return false
  250. }
  251. }
  252. return this.validSayPrice.leadtime && this.validSayPrice.repliesLapQty && this.validSayPrice.repliesPrice
  253. },
  254. setReplies: function (type, index) {
  255. if (type === 'add' && this.sayPriceObj.replies.length < 5) {
  256. if (this.sayPriceObj.replies[index].lapQty && this.sayPriceObj.replies[index].price) {
  257. this.sayPriceObj.replies.splice(index + 1, 0, {
  258. lapQty: '',
  259. price: ''
  260. })
  261. } else {
  262. this.$message.error('请填完整信息')
  263. }
  264. } else if (type === 'sub' && this.sayPriceObj.replies.length > 1) {
  265. this.sayPriceObj.replies.splice(index, 1)
  266. }
  267. }
  268. }
  269. }
  270. </script>
  271. <style scoped lang="scss">
  272. .say-price-box {
  273. position: fixed;
  274. width: 456px;
  275. top: 30%;
  276. left: 33%;
  277. /*-webkit-box-shadow: 0 5px 15px rgba(0,0,0,.5);*/
  278. /*-moz-box-shadow: 0 5px 15px rgba(0,0,0,.5);*/
  279. /*box-shadow: 0 5px 15px rgba(0,0,0,.5);*/
  280. z-index: 1;
  281. .title {
  282. position: relative;
  283. height: 44px;
  284. background: #4290f7;
  285. line-height: 44px;
  286. color: #fff;
  287. border: {
  288. top-right-radius: 5px;
  289. top-left-radius: 5px;
  290. }
  291. > div {
  292. display: inline-block;
  293. padding-left: 57px;
  294. width: 47%;
  295. overflow: hidden;
  296. text-overflow: ellipsis;
  297. white-space: nowrap;
  298. }
  299. i {
  300. position: absolute;
  301. right: 10px;
  302. top: 8px;
  303. cursor: pointer;
  304. }
  305. }
  306. .content {
  307. padding: 9px 0;
  308. background: #fff;
  309. .content-line {
  310. margin: 0 0 14px 0;
  311. .form-item {
  312. display: inline-block;
  313. width: 49%;
  314. > span {
  315. i {
  316. color: #fd2637;
  317. margin-right: 4px;
  318. }
  319. }
  320. input {
  321. border: 1px solid #bfbfbf;
  322. border-radius: 2px;
  323. height: 28px;
  324. padding: 0 8px;
  325. }
  326. &.form-left {
  327. span {
  328. display: inline-block;
  329. width: 104px;
  330. text-align: right;
  331. }
  332. input {
  333. width: 102px;
  334. padding: 0 8px;
  335. }
  336. &.date {
  337. input {
  338. width: 64px;
  339. }
  340. }
  341. }
  342. &.form-upload {
  343. text-align: center;
  344. label {
  345. margin-bottom: 0;
  346. cursor: pointer;
  347. input {
  348. display: none;
  349. }
  350. span {
  351. display: block;
  352. width: 94px;
  353. height: 23px;
  354. line-height: 18px;
  355. font-weight: normal;
  356. color: #4290f7;
  357. text-align: center;
  358. border: 1px dashed #4290f7;
  359. border-radius: 11px;
  360. i {
  361. font-weight: bold;
  362. font-style: normal;
  363. font-size: 18px;
  364. margin-right: 5px;
  365. }
  366. }
  367. }
  368. div {
  369. i {
  370. cursor: pointer;
  371. color: #eb222c;
  372. font-size: 16px;
  373. margin-right: 10px;
  374. }
  375. span {
  376. display: inline-block;
  377. max-width: 128px;
  378. overflow: hidden;
  379. text-overflow: ellipsis;
  380. white-space: nowrap;
  381. }
  382. }
  383. }
  384. &.form-right {
  385. position: relative;
  386. padding-left: 13px;
  387. input {
  388. width: 104px;
  389. padding: 0 8px;
  390. }
  391. select {
  392. position: absolute;
  393. top: 0;
  394. width: 32px;
  395. height: 28px;
  396. background: url(/images/applyPurchase/arrow-down.png) no-repeat right center;
  397. border: {
  398. left: none;
  399. top: none;
  400. bottom: none;
  401. right: 1px solid #bfbfbf;
  402. bottom-left-radius: 4px;
  403. top-left-radius: 4px;
  404. }
  405. color: #5392f9;
  406. font: small-caption;
  407. padding-left: 8px;
  408. outline: none;
  409. & + input {
  410. padding-left: 36px;
  411. }
  412. }
  413. > i {
  414. margin-left: 4px;
  415. }
  416. }
  417. }
  418. }
  419. }
  420. .operate {
  421. background: #fff;
  422. height: 62px;
  423. text-align: center;
  424. padding-top: 15px;
  425. border: {
  426. top: 1px solid #e4e5e6;
  427. bottom-left-radius: 5px;
  428. bottom-right-radius: 5px;
  429. }
  430. span {
  431. display: inline-block;
  432. width: 64px;
  433. height: 28px;
  434. line-height: 28px;
  435. text-align: center;
  436. background: #4290f7;
  437. color: #fff;
  438. cursor: pointer;
  439. &:last-child {
  440. margin-left: 15px;
  441. background: #acabab;
  442. }
  443. }
  444. }
  445. }
  446. </style>