index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <view>
  3. <view class="p-content">
  4. <view class="p-head">
  5. <view v-if="baseData">
  6. <view>
  7. <text>散件单号:</text>
  8. <text style="color: crimson;">{{baseData.sparePartsPurchaseNo}}</text>
  9. </view>
  10. <view>
  11. <button size="mini" :disabled="loading" type="warn" @click="submitInStock"> 入库 <text class="iconfont icon-icon-test43"></text></button>
  12. </view>
  13. </view>
  14. <view>
  15. <view>
  16. <text>产品条码:</text>
  17. <view style="flex-grow: 1;display: flex;align-items: center;">
  18. <input
  19. style="width: 150px;text-align: left;font-size: 32rpx;padding: 6rpx 0 6rpx 7rpx;"
  20. class="uni-input"
  21. placeholder="扫描或输入条码"
  22. border="surround"
  23. v-model="code">
  24. </view>
  25. </view>
  26. <view style="display: flex;align-items: center;">
  27. <button size="mini" @click="queryProduct" :style="{padding:'2px 3px',color:'#00aaff'}">查询</button>
  28. <button size="mini" @click="resetForm" :style="{padding:'2px 3px',color:'#aa0000',margin:'0 0 0 5px'}">重置</button>
  29. </view>
  30. </view>
  31. <view v-if="curProduct">
  32. <view>
  33. <text style="width:180rpx">产品名称:</text>
  34. <view>
  35. {{curProduct.productName}}
  36. </view>
  37. </view>
  38. </view>
  39. <view v-if="curProduct">
  40. <view>数量:<input class="uni-input" v-model="curProduct.putQty" :min="0" @blur="updateCurr" type="digit"/></view>
  41. <view>成本:<input class="uni-input" v-model="curProduct.putCost" :min="0" @blur="updateCurr" type="digit"/></view>
  42. </view>
  43. <view v-if="countData" style="justify-content: flex-start;flex-wrap: wrap;">
  44. <view>总款数:{{countData.productTotalCategory||0}}</view>
  45. <view>总数量:{{countData.productTotalQty||0}}</view>
  46. <view>
  47. 总成本:<u-text type="error" mode="price" :text="countData.productTotalCost" />
  48. </view>
  49. </view>
  50. </view>
  51. <view class="p-body" :style="{height: curProduct ? 'calc(100vh - 250px)':'calc(100vh - 180px)'}">
  52. <scroll-view :scroll-top="scrollTop" :scroll-y="true" class="scrollView">
  53. <uni-table border emptyText="暂无数据" :loading="loading" >
  54. <!-- 表头行 -->
  55. <uni-tr>
  56. <uni-td align="center">产品编码</uni-td>
  57. <uni-td align="center">数量</uni-td>
  58. <uni-td align="center">总成本</uni-td>
  59. </uni-tr>
  60. <!-- 表格数据行 -->
  61. <uni-tr v-for="item in detailList" :key="item.id" :checkedRow="curProduct&&curProduct.qrCode == item.qrCode" @click="selRow(item)">
  62. <uni-td width="40%" align="center">{{item.productCode}}</uni-td>
  63. <uni-td width="30%" align="center">{{item.putQty}}</uni-td>
  64. <uni-td width="30%" align="center">
  65. <view @click="toDetail(item)"><span :style="{ color: 'red' }">¥{{Number(item.putCost*item.putQty).toFixed(2)}}</span></view>
  66. </uni-td>
  67. </uni-tr>
  68. </uni-table>
  69. </scroll-view>
  70. </view>
  71. <view class="p-footer">
  72. <button size="mini" type="warn" @click="addQty(false)"> <text class="iconfont icon-reduce-btn"> 减 </text></button>
  73. <button size="mini" type="primary" @click="addQty(true)"> <text class="iconfont icon-add-btn"> 加 </text></button>
  74. </view>
  75. </view>
  76. <scanCode></scanCode>
  77. <uni-popup ref="popup" :mask-click="false" type="dialog">
  78. <view style="background-color: #fff;padding: 30rpx 50rpx;border-radius: 30rpx;width: 75%;margin: 0 auto;">
  79. <view v-if="tempProduct">
  80. <view>
  81. 产品编码:{{tempProduct.code}}
  82. </view>
  83. <view>
  84. 产品名称:{{tempProduct.name}}
  85. </view>
  86. <view style="display: flex;align-items: center;">
  87. 成本价:
  88. <u--input
  89. placeholder="请输入成本价"
  90. border="surround"
  91. v-model="tempProduct.putCost"
  92. :min="0"
  93. type="digit"
  94. ></u--input>
  95. </view>
  96. </view>
  97. <view style="display: flex;padding: 30rpx 15rpx;justify-content: space-between;">
  98. <button @click="closePop">取消</button>
  99. <button type="primary" @click="okPop">确定</button>
  100. </view>
  101. </view>
  102. </uni-popup>
  103. </view>
  104. </template>
  105. <script>
  106. import {
  107. sparePartsPurDetail,
  108. dealerProductQueryForSparePartsPur,
  109. sparePartsPurDetailList,
  110. sparePartsQueryCount,
  111. sparePartsPurDetailSave,
  112. sparePartsPurDetailDel,
  113. sparePartsPurDetailDelAll,
  114. sparePartsPurSubmitPut,
  115. } from '@/config/api.js'
  116. import scanCode from '@/libs/scan-code.vue';
  117. import { playAudio } from '@/libs/tools.js'
  118. export default {
  119. components: { scanCode },
  120. data() {
  121. return {
  122. loading: false,
  123. baseData: null,
  124. detailList:[],
  125. countData:null,
  126. code:'',
  127. sparePartsPurchaseSn: '',
  128. sparePartsPurchaseId: '',
  129. curProduct: null,
  130. defaultWarehouseCascade: [] ,// 默认仓库仓位
  131. tempProduct: null,
  132. scrollTop: 0
  133. };
  134. },
  135. onLoad(opts) {
  136. var _this = this
  137. this.sparePartsPurchaseSn = opts.sn
  138. this.sparePartsPurchaseId = opts.id
  139. this.getWarehouseCascade()
  140. this.getDetail()
  141. this.pageInit()
  142. uni.$on('scancodedate', function(content) {
  143. console.log("扫描到的内容为:", content)
  144. _this.code = content||''
  145. _this.queryProduct()
  146. })
  147. },
  148. onShow() {
  149. this.pageInit()
  150. this.hideKeyborder()
  151. },
  152. onUnload() {
  153. uni.$off('scancodedate')
  154. },
  155. onNavigationBarButtonTap(e){
  156. if(e.index == 0){
  157. uni.navigateTo({
  158. url: "/pages/stockIn/list"
  159. })
  160. }
  161. },
  162. methods: {
  163. closePop(){
  164. this.$refs.popup.close()
  165. },
  166. okPop(){
  167. if(this.tempProduct.putCost || this.tempProduct.putCost === 0){
  168. this.closePop()
  169. this.addDetailProduct(this.tempProduct, false)
  170. }else{
  171. uni.$u.toast("请输入成本价!")
  172. }
  173. },
  174. pageInit(){
  175. this.getTotal()
  176. this.getDetailList()
  177. },
  178. // 仓库仓位 级联 列表
  179. getWarehouseCascade () {
  180. const _this = this
  181. const warehouseList = this.$store.state.vuex_warehouseList
  182. warehouseList.filter(item => {
  183. // 过滤默认仓库
  184. if (item.defaultFlag == 1 && item.wasteFlag == 0) { // defaultFlag为1,且不是废品仓
  185. _this.defaultWarehouseCascade[0] = item.warehouseSn
  186. // 过滤默认仓位
  187. item.warehouseLocationList.filter(subItem => {
  188. if (subItem.defaultFlag == 1 && subItem.wasteFlag == 0) {
  189. _this.defaultWarehouseCascade[1] = subItem.warehouseLocationSn
  190. }
  191. })
  192. }
  193. })
  194. },
  195. hideKeyborder(){
  196. uni.hideKeyboard()
  197. },
  198. // 修改数量和成本
  199. updateCurr(){
  200. if(this.curProduct.putQty>0){
  201. if(this.curProduct.putCost>0){
  202. this.addDetailProduct(this.curProduct, true)
  203. }else{
  204. uni.$u.toast("成本必须大于0!")
  205. this.curProduct.putCost = this.curProduct.putCostBackups
  206. }
  207. }else{
  208. // 删除
  209. this.delDetailProduct(this.curProduct)
  210. }
  211. },
  212. // 加减数量
  213. addQty(type){
  214. playAudio('info')
  215. const hasProduct = this.detailList.find(item => item.qrCode == this.code)
  216. if(hasProduct){
  217. hasProduct.putQty = hasProduct.putQty + (type ? 1 : -1)
  218. if(hasProduct.putQty>0){
  219. this.addDetailProduct(hasProduct, true)
  220. }else{
  221. // 删除
  222. this.delDetailProduct(hasProduct)
  223. }
  224. }
  225. },
  226. // 删除
  227. delDetailProduct(item) {
  228. sparePartsPurDetailDel({ sn: item.id }).then(res => {
  229. if (res.status == 200) {
  230. uni.$u.toast(res.message)
  231. this.pageInit()
  232. }
  233. })
  234. },
  235. // 查询产品
  236. queryProduct(){
  237. if(!this.code){
  238. uni.$u.toast("请扫码或输入条形码!")
  239. return
  240. }
  241. // 如果已添加产品,则累加数量
  242. const hasProduct = this.detailList.find(item => item.qrCode == this.code)
  243. console.log(hasProduct)
  244. if(!!hasProduct){
  245. this.addQty(true)
  246. return
  247. }
  248. if(this.code==''){
  249. uni.$u.toast("未识别到条形码!")
  250. playAudio('error')
  251. return
  252. }
  253. const params = {
  254. supplierSn: this.baseData.supplierSn,
  255. qrCode: this.code,
  256. pageNo:1,
  257. pageSize:1 ,
  258. }
  259. console.log(params)
  260. dealerProductQueryForSparePartsPur(params).then(res => {
  261. console.log(res)
  262. if(res.status == 200){
  263. const curProduct = res.data && res.data.list[0] || null
  264. console.log(curProduct)
  265. if(curProduct){
  266. curProduct.putCost = curProduct.purchasePrice
  267. curProduct.putQty = curProduct.putQty || 1
  268. if (this.defaultWarehouseCascade.length > 0) {
  269. curProduct.warehouseSn = this.defaultWarehouseCascade[0]
  270. curProduct.warehouseLocationSn = this.defaultWarehouseCascade[1]
  271. } else {
  272. curProduct.warehouseSn = undefined
  273. curProduct.warehouseLocationSn = undefined
  274. }
  275. // 添加产品
  276. this.addDetailProduct(curProduct, false)
  277. }else{
  278. uni.$u.toast("此商品不存在!")
  279. playAudio('error')
  280. }
  281. }
  282. })
  283. },
  284. // 添加明细
  285. addDetailProduct(row, isEdit){
  286. const params = {
  287. id: isEdit ? row.id : undefined,
  288. sparePartsPurchaseSn: this.sparePartsPurchaseSn,
  289. putCost: row.putCost,
  290. putQty: row.putQty,
  291. productCode: isEdit ? row.productCode : row.code,
  292. productOrigCode: (isEdit ? row.productOrigCode : row.origCode) || undefined,
  293. productSn: row.productSn,
  294. productTypeSn1: row.productTypeSn1,
  295. productTypeSn2: row.productTypeSn2,
  296. productTypeSn3: row.productTypeSn3,
  297. brandSn: isEdit ? row.brandSn : row.productBrandSn,
  298. warehouseLocationSn: row.warehouseLocationSn,
  299. warehouseSn: row.warehouseSn
  300. }
  301. if (isEdit) { // 编辑
  302. // 清空成本价或数量时,值应保持未清空前的值,因成本价和数量都不可为空
  303. if (!(row.putCost || row.putCost == 0)) {
  304. row.putCost = row.putCostBackups
  305. return
  306. }
  307. if (!row.putQty) {
  308. row.putQty = row.putQtyBackups
  309. return
  310. }
  311. }
  312. console.log(params)
  313. this.loading = true
  314. sparePartsPurDetailSave(params).then(res => {
  315. console.log(res,'添加')
  316. if (res.status == 200) {
  317. this.loading = false
  318. this.pageInit()
  319. } else {
  320. this.loading = false
  321. if(res.message == '采购成本价不能为空;'){
  322. this.$refs.popup.open()
  323. this.tempProduct = row
  324. }
  325. }
  326. })
  327. },
  328. // 详情
  329. getDetail(){
  330. sparePartsPurDetail({sn: this.sparePartsPurchaseSn}).then(res => {
  331. if(res.status == 200){
  332. this.baseData = res.data
  333. }
  334. })
  335. },
  336. selRow(item){
  337. this.curProduct = item
  338. this.code = item.qrCode
  339. },
  340. resetForm(){
  341. this.curProduct = null
  342. this.code = ''
  343. this.scrollTop = 0
  344. },
  345. // 已添加产品列表
  346. getDetailList(){
  347. sparePartsPurDetailList({pageNo:1,pageSize:1000,sparePartsPurchaseSn:this.sparePartsPurchaseSn}).then(res => {
  348. console.log(res,'已添加产品列表')
  349. if(res.status == 200){
  350. this.detailList = res.data.list
  351. this.detailList.map(item => {
  352. item.putCostBackups = item.putCost
  353. item.putQtyBackups = item.putQty
  354. })
  355. const curProduct = this.detailList.find(item => item.qrCode == this.code)
  356. this.curProduct = curProduct || null
  357. this.scrollToRow(this.curProduct)
  358. }
  359. })
  360. },
  361. // 滚动到指定行
  362. scrollToRow(cur){
  363. const idx = this.detailList.findIndex(item => item.id == cur.id)
  364. this.scrollTop = idx * 30
  365. },
  366. getTotal(){
  367. sparePartsQueryCount({sparePartsPurchaseSn:this.sparePartsPurchaseSn}).then(res => {
  368. console.log(res,'getTotal')
  369. this.countData = res.data
  370. })
  371. },
  372. toDetail(item) {
  373. this.$store.state.vuex_tempData = item
  374. uni.navigateTo({
  375. url:"/pages/stockIn/detail?state="+this.baseData.state
  376. })
  377. },
  378. submitInStock(){
  379. sparePartsPurSubmitPut({id: this.sparePartsPurchaseId}).then(res => {
  380. if(res.status == 200){
  381. uni.$emit("refashList")
  382. uni.navigateBack()
  383. }
  384. })
  385. }
  386. },
  387. }
  388. </script>
  389. <style lang="scss">
  390. .p-content{
  391. button{
  392. line-height: 1.7;
  393. }
  394. .p-head{
  395. font-size: 32upx;
  396. color: $uni-text-color;
  397. >view{
  398. display: flex;
  399. align-items: center;
  400. padding: 15upx 20upx;
  401. border-bottom: 1px solid #eee;
  402. justify-content: space-between;
  403. > view{
  404. display: flex;
  405. padding: 0 10upx;
  406. align-items: center;
  407. }
  408. }
  409. .uni-input{
  410. border: 1px solid #eee;
  411. width: 150upx;
  412. text-align: center;
  413. }
  414. }
  415. .p-body{
  416. flex-grow: 1;
  417. height: calc(100vh - 180px);
  418. .scrollView{
  419. height: 100%;
  420. }
  421. }
  422. .p-footer{
  423. padding: 20upx;
  424. display: flex;
  425. > button{
  426. width: 40%;
  427. padding: 3px 0;
  428. }
  429. }
  430. }
  431. </style>