SayPrice.vue 16 KB

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