otherStorage.vue 14 KB

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