index.vue 11 KB

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