index.vue 9.9 KB

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