otherStorage.vue 13 KB

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