otherStorage.vue 11 KB

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