index.vue 9.6 KB

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