index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="p-content">
  3. <view class="p-head">
  4. <view v-if="baseData">
  5. <view>
  6. <text>盘点单号:</text>
  7. <text style="color: crimson;">{{baseData.checkWarehouseNo}}</text>
  8. </view>
  9. <view>
  10. <button size="mini" :disabled="loading" type="warn" @click="submitIn"> 提交 <text class="iconfont icon-icon-test43"></text></button>
  11. </view>
  12. </view>
  13. <view>
  14. <view>
  15. <text>产品条码:</text>
  16. <view style="flex-grow: 1;display: flex;align-items: center;">
  17. <input
  18. style="width: 150px;text-align: left;font-size: 32rpx;padding: 6rpx 0 6rpx 7rpx;"
  19. class="uni-input"
  20. placeholder="扫描或输入条码"
  21. border="surround"
  22. v-model="code">
  23. <button size="mini" @click="queryProduct" :style="{padding:'2px 10px',color:'#00aaff'}">查询</button>
  24. </view>
  25. </view>
  26. <view></view>
  27. </view>
  28. <view>
  29. <view>
  30. <text>产品编码:</text>
  31. <view style="flex-grow: 1;display: flex;align-items: center;">
  32. <input
  33. style="width: 150px;text-align: left;font-size: 32rpx;padding: 6rpx 0 6rpx 7rpx;"
  34. class="uni-input"
  35. placeholder="请输入产品编码"
  36. border="surround"
  37. v-model="productCode">
  38. <button size="mini" @click="queryProduct" :style="{padding:'2px 10px',color:'#00aaff'}">查询</button>
  39. </view>
  40. </view>
  41. <view></view>
  42. </view>
  43. <view v-if="curProduct">
  44. <view>
  45. <text style="width:180rpx">产品名称:</text>
  46. <view>
  47. {{curProduct.productName}}
  48. </view>
  49. </view>
  50. </view>
  51. <view v-if="curProduct">
  52. <view>盘点数量:<input class="uni-input" v-model="curProduct.checkQty" :min="0" @blur="updateCurr" type="digit"/></view>
  53. <view>库存数量:{{curProduct.stockQty}}</view>
  54. </view>
  55. <view v-if="countData" style="justify-content: flex-start;flex-wrap: wrap;">
  56. <view>共{{countData.totalCategory||0}}款</view>
  57. <view>总数量:{{countData.stockQty||0}}</view>
  58. <view>盈亏数量:<span :style="{ color: countData.totalCheckProfitLossQty>0?'red':countData.totalCheckProfitLossQty<0?'green':'' }">{{ (countData.totalCheckProfitLossQty || countData.totalCheckProfitLossQty==0) ? Math.abs(countData.totalCheckProfitLossQty) : '--' }}</span></view>
  59. </view>
  60. </view>
  61. <view class="p-body">
  62. <uni-table style="width: 100%;" border emptyText="暂无数据" :loading="loading" >
  63. <!-- 表头行 -->
  64. <uni-tr>
  65. <uni-td align="center">产品编码</uni-td>
  66. <uni-td align="center">库存</uni-td>
  67. <uni-td align="center">盘点数量</uni-td>
  68. <uni-td align="center">盈亏数量</uni-td>
  69. </uni-tr>
  70. <!-- 表格数据行 -->
  71. <uni-tr v-for="item in detailList" :key="item.id" :checkedRow="curProduct&&curProduct.qrCode == item.qrCode" @click="toDetail(item)">
  72. <uni-td width="40%" align="center">{{item.productCode}}</uni-td>
  73. <uni-td width="20%" align="center">{{item.stockQty}}</uni-td>
  74. <uni-td width="20%" align="center">{{item.checkQty}}</uni-td>
  75. <uni-td width="20%" align="center">
  76. <span :style="{ color: item.checkProfitLossQty>0?'red':item.checkProfitLossQty<0?'green':'' }">{{ (item.checkProfitLossQty || item.checkProfitLossQty==0) ? Math.abs(item.checkProfitLossQty) : '--' }}</span>
  77. </uni-td>
  78. </uni-tr>
  79. </uni-table>
  80. </view>
  81. <view class="p-footer">
  82. <button size="mini" type="warn" @click="addQty(false)"> <text class="iconfont icon-reduce-btn"> 减 </text></button>
  83. <button size="mini" type="primary" @click="addQty(true)"> <text class="iconfont icon-add-btn"> 加 </text></button>
  84. </view>
  85. <scanCode @onKeyDown="keyDown"></scanCode>
  86. </view>
  87. </template>
  88. <script>
  89. import scanCode from '@/libs/scan-code.vue';
  90. import { playAudio } from '@/libs/tools.js'
  91. import {
  92. checkWarehouseDetailStockList,
  93. checkWarehouseDetailBySn,
  94. checkWarehouseDetailList,
  95. checkWarehouseDetailCount,
  96. checkWarehouseDetailSave,
  97. checkWarehouseDetailDel,
  98. checkWarehouseSubmit} from '@/config/api.js'
  99. export default {
  100. components: { scanCode },
  101. data() {
  102. return {
  103. checkWarehouseSn: '',
  104. checkWarehouseId: null,
  105. loading: false,
  106. detailList:[],
  107. countData: null,
  108. code:'',
  109. productCode: '',
  110. baseData: null,
  111. curProduct: null,
  112. };
  113. },
  114. onLoad(opts) {
  115. var _this = this
  116. this.checkWarehouseSn = opts.checkWarehouseSn
  117. this.checkWarehouseId = opts.id
  118. uni.$on('scancodedate', function(content) {
  119. console.log("扫描到的内容为:", content)
  120. _this.code = content||''
  121. _this.queryProduct()
  122. })
  123. this.getDetail()
  124. this.pageInit()
  125. },
  126. onShow() {
  127. this.pageInit()
  128. this.hideKeyborder()
  129. },
  130. onUnload() {
  131. uni.$off('scancodedate')
  132. },
  133. onNavigationBarButtonTap(e){
  134. if(e.index == 0){
  135. uni.navigateTo({
  136. url: "/pages/stockPan/list"
  137. })
  138. }
  139. },
  140. methods: {
  141. pageInit(){
  142. this.getTotal()
  143. this.getDetailList()
  144. },
  145. hideKeyborder(){
  146. uni.hideKeyboard()
  147. },
  148. // 物理按键
  149. keyDown(key,e){
  150. console.log(key,e)
  151. },
  152. // 修改数量和成本
  153. updateCurr(){
  154. if(this.curProduct.checkQty>0){
  155. this.addDetailProduct(this.curProduct, true)
  156. }else{
  157. // 删除
  158. this.delDetailProduct(this.curProduct)
  159. }
  160. },
  161. // 加减数量
  162. addQty(type){
  163. playAudio('info')
  164. const hasProduct = this.detailList.find(item => item.qrCode == this.code || item.productCode == this.productCode)
  165. if(hasProduct){
  166. hasProduct.checkQty = hasProduct.checkQty + (type ? 1 : -1)
  167. if(hasProduct.checkQty>0){
  168. this.addDetailProduct(hasProduct, true)
  169. }else{
  170. // 删除
  171. this.delDetailProduct(hasProduct)
  172. }
  173. }
  174. },
  175. // 删除
  176. delDetailProduct(item) {
  177. checkWarehouseDetailDel({ id: item.id, checkWarehouseSn: this.checkWarehouseSn }).then(res => {
  178. if (res.status == 200) {
  179. uni.$u.toast(res.message)
  180. this.pageInit()
  181. }
  182. })
  183. },
  184. // 查询产品
  185. queryProduct(){
  186. if(!this.code&&!this.productCode){
  187. uni.$u.toast("请输入条形码或编码!")
  188. playAudio('error')
  189. return
  190. }
  191. // 如果已添加产品,则累加数量
  192. const hasProduct = this.detailList.find(item => item.qrCode == this.code || item.productCode == this.productCode)
  193. console.log(hasProduct)
  194. if(!!hasProduct){
  195. this.addQty(true)
  196. return
  197. }
  198. const params = {
  199. checkWarehouseId: this.checkWarehouseId,
  200. qrCode: this.code,
  201. productCode: this.productCode,
  202. pageNo:1,
  203. pageSize:1 ,
  204. }
  205. console.log(params)
  206. checkWarehouseDetailStockList(params).then(res => {
  207. console.log(res)
  208. if(res.status == 200){
  209. const curProduct = res.data && res.data.list[0] || null
  210. console.log(curProduct)
  211. if(curProduct){
  212. // 添加产品
  213. this.addDetailProduct(curProduct, false)
  214. }else{
  215. uni.$u.toast("此商品不存在!")
  216. playAudio('error')
  217. }
  218. }
  219. })
  220. },
  221. // 添加明细
  222. addDetailProduct(row, isEdit){
  223. const params = isEdit ? row : {
  224. checkWarehouseSn: this.checkWarehouseSn,
  225. checkCost: row.putCost,
  226. productSn: row.productSn,
  227. productCode: row.productCode,
  228. productOrigCode: row.productOrigCode || undefined,
  229. productTypeSn1: row.productTypeSn1,
  230. productTypeSn2: row.productTypeSn2,
  231. productTypeSn3: row.productTypeSn3,
  232. brandSn: row.brandSn,
  233. stockQty: row.currentQty,
  234. lastStockTime: row.lastStockTime,
  235. checkProfitLossCost: row.lastStockCost,
  236. stockBatchNo: row.stockBatchNo || undefined,
  237. productProduceDate: row.productProduceDate || undefined,
  238. productExpiryDate: row.productExpiryDate || undefined,
  239. warehouseSn: row.warehouseSn || undefined,
  240. warehouseLocationSn: row.warehouseLocationSn || undefined
  241. };
  242. console.log(params)
  243. this.loading = true
  244. checkWarehouseDetailSave(params).then(res => {
  245. console.log(res,'添加')
  246. if (res.status == 200) {
  247. this.loading = false
  248. this.pageInit()
  249. } else {
  250. this.loading = false
  251. }
  252. })
  253. },
  254. // 详情
  255. getDetail(){
  256. checkWarehouseDetailBySn({sn: this.checkWarehouseSn}).then(res => {
  257. console.log(res,'详情')
  258. if(res.status == 200){
  259. this.baseData = res.data
  260. }
  261. })
  262. },
  263. // 已添加产品列表
  264. getDetailList(){
  265. checkWarehouseDetailList({pageNo:1,pageSize:1000,checkWarehouseSn:this.checkWarehouseSn}).then(res => {
  266. console.log(res,'已添加产品列表')
  267. if(res.status == 200){
  268. this.detailList = res.data.list
  269. const curProduct = this.detailList.find(item => item.qrCode == this.code || item.productCode == this.productCode)
  270. this.curProduct = curProduct || null
  271. }
  272. })
  273. },
  274. getTotal(){
  275. checkWarehouseDetailCount({checkWarehouseSn:this.checkWarehouseSn}).then(res => {
  276. console.log(res,'getTotal')
  277. this.countData = res.data
  278. })
  279. },
  280. // 商品详情
  281. toDetail(item) {
  282. this.$store.state.vuex_tempData = item
  283. uni.navigateTo({
  284. url:"/pages/stockPan/detail?state="+this.baseData.state
  285. })
  286. },
  287. // 提交盘点
  288. submitIn(){
  289. checkWarehouseSubmit({id: this.checkWarehouseId, auditFlag: true}).then(res => {
  290. if(res.status == 200){
  291. uni.$emit("refashList")
  292. uni.navigateBack()
  293. }
  294. })
  295. }
  296. },
  297. }
  298. </script>
  299. <style lang="scss">
  300. .p-content{
  301. button{
  302. line-height: 1.7;
  303. }
  304. .p-head{
  305. font-size: 32upx;
  306. color: $uni-text-color;
  307. >view{
  308. display: flex;
  309. align-items: center;
  310. padding: 15upx 20upx;
  311. border-bottom: 1px solid #eee;
  312. justify-content: space-between;
  313. > view{
  314. display: flex;
  315. padding: 0 10upx;
  316. align-items: center;
  317. }
  318. }
  319. .uni-input{
  320. border: 1px solid #eee;
  321. width: 150upx;
  322. text-align: center;
  323. }
  324. }
  325. .p-body{
  326. overflow: auto;
  327. flex-grow: 1;
  328. height: 50%;
  329. }
  330. .p-footer{
  331. padding:20upx 30upx;
  332. display: flex;
  333. > button{
  334. width: 30%;
  335. }
  336. }
  337. }
  338. </style>