SayPrice.vue 17 KB

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