otherStorage.vue 11 KB

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