otherStorage.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <div class="storage">
  3. <div class="btn-click">
  4. <span class="base-color" @click="saveClick()">保存</span>
  5. <span class="clear" @click="saveClick('clear')">取消</span>
  6. </div>
  7. <div class="storage-info">
  8. <div class="linetext">{{switchType === 'INBOUND' ? '入库单' : '出库单'}}:<span>系统自动生成</span></div>
  9. <div class="linetext">{{switchType === 'INBOUND' ? '卖家名称' : '买家名称'}}:
  10. <span><input type="text" v-model="enName" :placeholder="switchType === 'INBOUND' ? '请输入卖家名称' : '请输入买家名称'"></span>
  11. </div>
  12. <div class="linetext">录入人: <span v-text="user.logged">21324</span></div>
  13. <div class="linetext">录入时间: <span v-text="baseUtils.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')">21324</span></div>
  14. </div>
  15. <ul class="list-unstyled">
  16. <li class="info-list clearfix" v-for="(item, index) in allObj">
  17. <span class="super"><em v-text="index + 1">1</em></span>
  18. <div class="linetext width50 fl">型号:
  19. <span>
  20. <input type="text" style="width:2rem;" v-model="item.cmpCode" @input="onCodeChange(index)">
  21. </span>
  22. </div>
  23. <div class="linetext width50 fl">品牌: <span v-text="item.brand">21324</span></div>
  24. <div class="linetext width50 fl">物料名称: <span v-text="item.pcmpcode">21324</span></div>
  25. <div class="linetext width50 fl">规格: <span v-text="item.spec">21324</span></div>
  26. <div class="linetext width50 fl">库存数: <span v-text="item.erpReserve">21324</span></div>
  27. <div class="linetext width50 fl"><em>*</em>{{switchType === 'INBOUND' ? '入库数' : '出库数'}}(PCS): <span>
  28. <input type="text" style="width:1.1rem;" v-model="item.qty" @input="onAmountInput(item, index)">
  29. </span></div>
  30. <div class="linetext width50 fl">{{switchType === 'INBOUND' ? '采购单价' : '销售单价'}}({{currency === 'RMB' ? '¥': '$'}}):<span>
  31. <input type="text" style="width:1.2rem;" v-model="item.price" @blur="rMBPriceBlur(item, index)">
  32. </span></div>
  33. <div class="content-line" v-show="item.showSimilarCodeList && item.cmpCode">
  34. <ul class="similar">
  35. <li v-for="sCode in similarCode" @click.stop="setCode(sCode, index)">
  36. <span v-text="sCode.cmpCode"></span>
  37. <span v-text="sCode.brand"></span>
  38. </li>
  39. </ul>
  40. </div>
  41. <div class="look-btn">
  42. <span @click="addClick()" v-if="index === allObj.length - 1">新增</span>
  43. <span @click="addClick(index)" v-if="index !== 0">删除</span>
  44. </div>
  45. </li>
  46. </ul>
  47. <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
  48. </div>
  49. </template>
  50. <script>
  51. import { RemindBox, PullUp, EmptyStatus } from '~components/mobile/common'
  52. export default {
  53. props: {
  54. switchType: {
  55. type: String,
  56. default: 'INBOUND'
  57. }
  58. },
  59. data () {
  60. return {
  61. remindText: '',
  62. timeoutCount:0,
  63. enName: '',
  64. allObj:[],
  65. storageObj: {
  66. cmpCode: '',
  67. brand: '',
  68. pcmpcode: '',
  69. spec: '',
  70. qty: '',
  71. price: '',
  72. erpReserve: '',
  73. showSimilarCodeList: false,
  74. },
  75. similarCode:[]
  76. }
  77. },
  78. components: {
  79. RemindBox
  80. },
  81. mounted () {
  82. let _this = this
  83. this.allObj.push(this.storageObj)
  84. document.body.onclick = function() {
  85. _this.allObj.forEach(val => {
  86. if(!val.productId) {
  87. val = {
  88. cmpCode: '',
  89. brand: '',
  90. pcmpcode: '',
  91. spec: '',
  92. qty: '',
  93. price: '',
  94. erpReserve: ''
  95. }
  96. }
  97. val.showSimilarCodeList = false
  98. })
  99. }
  100. },
  101. methods: {
  102. onRemind: function (str) {
  103. this.remindText = str
  104. this.timeoutCount++
  105. },
  106. setFilterType (type) {
  107. let bound = ''
  108. if(type === 'OTHER_INBOUND') {
  109. bound = '其他入库'
  110. } else if(type === 'OTHER_OUTBOUND'){
  111. bound = '其他出库'
  112. } else if (type === 'PURCHASE_INBOUND') {
  113. bound = '采购入库'
  114. } else if(type === 'SELL_OUTBOUND') {
  115. bound = '销售出库'
  116. } else {
  117. bound = '全部类型'
  118. }
  119. return bound
  120. },
  121. initData () {
  122. this.enName = ''
  123. this.allObj = []
  124. this.allObj.push({
  125. cmpCode: '',
  126. brand: '',
  127. pcmpcode: '',
  128. spec: '',
  129. qty: '',
  130. price: '',
  131. erpReserve: '',
  132. showSimilarCodeList: false,
  133. })
  134. },
  135. onCodeChange (type) {
  136. this.allObj[type].showSimilarCodeList = true
  137. this.allObj[type].cmpCode = this.allObj[type].cmpCode.trim()
  138. this.getSimilarCode(type)
  139. },
  140. getSimilarCode: function (type) {
  141. if (this.allObj[type].cmpCode) {
  142. this.$http.get('/trade/products/code/keyword', {params: {keyword: this.allObj[type].cmpCode}})
  143. .then(response => {
  144. if(response.data.length > 0){
  145. this.similarCode = response.data
  146. } else {
  147. this.similarCode = []
  148. this.allObj[type].cmpCode = ''
  149. this.allObj[type].brand = ''
  150. this.allObj[type].pcmpcode = ''
  151. this.allObj[type].spec = ''
  152. this.allObj[type].productId = ''
  153. this.allObj[type].erpReserve = ''
  154. this.onRemind('产品库中没有找到相应产品信息')
  155. }
  156. this.allObj[type].showSimilarCodeList = response.data.length > 0
  157. }).catch((err) => {
  158. this.similarCode = []
  159. this.allObj[type].cmpCode = ''
  160. this.allObj[type].brand = ''
  161. this.allObj[type].pcmpcode = ''
  162. this.allObj[type].spec = ''
  163. this.allObj[type].productId = ''
  164. this.allObj[type].erpReserve = ''
  165. this.onRemind('产品库中没有找到相应产品信息')
  166. })
  167. } else {
  168. this.allObj[type].showSimilarCodeList = false
  169. }
  170. },
  171. setCode (data, type) {
  172. this.allObj[type].cmpCode = data.cmpCode
  173. this.allObj[type].brand = data.pbranden
  174. this.allObj[type].pcmpcode = data.kind
  175. this.allObj[type].spec = data.spec
  176. this.allObj[type].productId = data.id
  177. this.allObj[type].erpReserve = data.erpReserve
  178. this.allObj[type].showSimilarCodeList = false
  179. if(data.erpReserve <= 0 && this.switchType === 'OUTBOUND') {
  180. this.onRemind('当前产品库存为0,不能出库!')
  181. }
  182. },
  183. addClick (type) {
  184. if(type) {
  185. this.allObj.splice(type, 1)
  186. } else {
  187. let _item = {
  188. cmpCode: '',
  189. brand: '',
  190. pcmpcode: '',
  191. spec: '',
  192. qty: '',
  193. price: '',
  194. erpReserve: '',
  195. showSimilarCodeList: false,
  196. }
  197. this.allObj.push(_item)
  198. }
  199. },
  200. onAmountInput: function (item, index) {
  201. if (!(/^[0-9]*$/).test(item.qty)) {
  202. let chineseIndex = -1
  203. for (let i = 0; i < item.qty.length; i++) {
  204. if (!(/^[0-9]*$/).test(item.qty.charAt(i))) {
  205. chineseIndex = i
  206. break
  207. }
  208. }
  209. this.allObj[index].qty = this.baseUtils.cutOutString(item.qty, chineseIndex)
  210. } else if (item.qty.length > 9) {
  211. this.onRemind ('数量不能高于10亿')
  212. this.allObj[index].qty = this.baseUtils.cutOutString(item.qty, 9)
  213. }
  214. },
  215. rMBPriceBlur(item) {
  216. if (item.price === '' || !item.price) { return false }
  217. if (!/^[0-9]+([.]{1}[0-9]{1,6})?$/.test(item.price)) {
  218. this.onRemind('单价只能输入数字带6位小数')
  219. } else if (Math.abs(item.price) === 0) {
  220. return false
  221. } else if (Math.abs(item.price) >= 10000) {
  222. item.price = 9999
  223. this.onRemind ('单价不能高于10000')
  224. return false
  225. }
  226. item.price = item.price.toString()
  227. let splits = item.price.split('.')
  228. if (splits[0].length >= 4) {
  229. splits[0] = splits[0].substr(0, 4)
  230. item.price = splits[0]
  231. }
  232. if (splits[1]) {
  233. item.price = splits[0] + '.' + splits[1]
  234. }
  235. if (splits[1] && splits[1].length > 6) {
  236. splits[1] = splits[1].substr(0, 7)
  237. let str = splits[1].substr(0, 6)
  238. if (splits[1][splits[1].length - 1] >= 5) {
  239. str = splits[1].substr(0, 6)
  240. str = Math.abs(str) + 1
  241. }
  242. item.price = splits[0] + '.' + Math.ceil(str)
  243. }
  244. },
  245. saveClick (type) {
  246. if(type === 'clear') {
  247. this.initData()
  248. }else {
  249. let arr = []
  250. let flag = 0;
  251. this.allObj.forEach(val => {
  252. if(val.productId) {
  253. if((val.erpReserve <= 0) && this.switchType === 'OUTBOUND'){
  254. flag = 1
  255. } else if((val.erpReserve < val.qty) && this.switchType === 'OUTBOUND') {
  256. flag = 2
  257. } else if(val.qty && Number(val.qty) <= 0) {
  258. flag = 3
  259. } else if(val.qty) {
  260. val.price ?
  261. arr.push({price: Number(val.price), productId: val.productId, qty:Number(val.qty)}) :
  262. arr.push({productId: val.productId, qty:Number(val.qty)})
  263. } else {
  264. flag = 4
  265. }
  266. }
  267. })
  268. if(flag === 1) {
  269. this.onRemind('产品库中库存数量为0将不能出库!')
  270. return;
  271. }
  272. if(flag === 2) {
  273. this.onRemind('出库量数量不能大于库存数!')
  274. return;
  275. }
  276. if(flag === 3) {
  277. this.onRemind('填写的数量不能小于0!')
  278. return;
  279. }
  280. if(flag === 4) {
  281. this.onRemind('请填写数量!')
  282. return;
  283. }
  284. if(arr.length <= 0) {
  285. this.onRemind('至少填写一条数据!')
  286. return;
  287. }
  288. this.$http.post(`/CommodityInOutbound/${this.switchType === 'INBOUND'? 'inBound': 'outBound'}/other?enName=${this.enName}`, arr)
  289. .then(response => {
  290. if(response.data.code === 1){
  291. this.onRemind('保存信息成功')
  292. this.initData()
  293. } else {
  294. this.onRemind(response.data)
  295. }
  296. })
  297. .catch(err => {
  298. this.onRemind('保存信息失败')
  299. })
  300. }
  301. }
  302. }
  303. }
  304. </script>
  305. <style lang="scss" scoped>
  306. $base-color: #3f84f6;
  307. $title-color: #ffa200;
  308. $red-color: #ff0000;
  309. .storage{
  310. position: relative;
  311. margin-bottom:.3rem;
  312. .btn-click{
  313. padding: 0.24rem 0.24rem;
  314. position: fixed;
  315. bottom: 1rem;
  316. left: 0;
  317. right: 0;
  318. z-index:100;
  319. text-align: center;
  320. background: #f1f3f6;
  321. span{
  322. display:inline-block;
  323. width:30%;
  324. height: .6rem;
  325. line-height: .6rem;
  326. margin: 0 .1rem;
  327. border-radius:.05rem;
  328. &.clear{
  329. color:#fafbfc;
  330. background: #b5b5b5;
  331. }
  332. &.base-color{
  333. color:#fff;
  334. background: $base-color;
  335. }
  336. }
  337. }
  338. .storage-info{
  339. padding: 0.24rem 0.24rem;
  340. background: #fff;
  341. margin-bottom:.2rem;
  342. }
  343. .content-line{
  344. position: absolute;
  345. border: 1px solid #7e7e7e;
  346. border-radius: .05rem;
  347. left: .3rem;
  348. top: 32%;
  349. background: #fff;
  350. width: 6.5rem;
  351. max-height: 2.5rem;
  352. overflow-y: auto;
  353. z-index: 12;
  354. .similar {
  355. li {
  356. height: .5rem;
  357. line-height: .5rem;
  358. font-size: .26rem;
  359. color: #999;
  360. padding-left: .19rem;
  361. &:focus, &:active, &:hover {
  362. background: #999;
  363. color: #fff;
  364. }
  365. span{
  366. display: inline-block;
  367. width: 50%;
  368. overflow: hidden;
  369. text-overflow: ellipsis;
  370. white-space: nowrap;
  371. }
  372. }
  373. }
  374. }
  375. .look-btn{
  376. position: absolute;
  377. bottom: 0;
  378. left: 0;
  379. width: 100%;
  380. border-top: 1px solid #d3d3d3;
  381. text-align: center;
  382. span{
  383. display:inline-block;
  384. width:50%;
  385. text-align: center;
  386. line-height: .8rem;
  387. }
  388. }
  389. .linetext{
  390. color:#666;
  391. line-height: .6rem;
  392. overflow: hidden;
  393. -o-text-overflow: ellipsis;
  394. text-overflow: ellipsis;
  395. white-space: nowrap;
  396. input{
  397. height: .5rem;
  398. font-size: .24rem;
  399. border-radius: .04rem;
  400. border: 1px solid #d2d2d2;
  401. padding: 0 .1rem;
  402. }
  403. em{
  404. color:$red-color;
  405. }
  406. span{
  407. color:#333;
  408. &.base-color{
  409. color:$base-color;
  410. }
  411. }
  412. }
  413. > ul{
  414. margin-bottom:1rem;
  415. }
  416. .info-list{
  417. position:relative;
  418. padding: 0.3rem 0.24rem 1rem;
  419. background: #fff;
  420. margin-bottom:.2rem;
  421. .width50{
  422. display:inline-block;
  423. width: 48%;
  424. margin-left: .1rem;
  425. }
  426. >span{
  427. display:inline-block;
  428. position:absolute;
  429. left:0;
  430. top:0;
  431. padding: 0 .1rem;
  432. background: $title-color;
  433. border-radius: 0 .5rem .5rem 0;
  434. line-height: .3rem;
  435. height:.3rem;
  436. color:#fff;
  437. font-size: .24rem;
  438. }
  439. }
  440. }
  441. </style>