index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. methods: {
  149. closePop(){
  150. this.$refs.popup.close()
  151. },
  152. okPop(){
  153. if(this.tempProduct.putCost || this.tempProduct.putCost === 0){
  154. this.closePop()
  155. this.addDetailProduct(this.tempProduct, false)
  156. }else{
  157. uni.$u.toast("请输入成本价!")
  158. }
  159. },
  160. pageInit(){
  161. this.getTotal()
  162. this.getDetailList()
  163. },
  164. // 仓库仓位 级联 列表
  165. getWarehouseCascade () {
  166. const _this = this
  167. const warehouseList = this.$store.state.vuex_warehouseList
  168. warehouseList.filter(item => {
  169. // 过滤默认仓库
  170. if (item.defaultFlag == 1 && item.wasteFlag == 0) { // defaultFlag为1,且不是废品仓
  171. _this.defaultWarehouseCascade[0] = item.warehouseSn
  172. // 过滤默认仓位
  173. item.warehouseLocationList.filter(subItem => {
  174. if (subItem.defaultFlag == 1 && subItem.wasteFlag == 0) {
  175. _this.defaultWarehouseCascade[1] = subItem.warehouseLocationSn
  176. }
  177. })
  178. }
  179. })
  180. },
  181. hideKeyborder(){
  182. uni.hideKeyboard()
  183. },
  184. // 修改数量和成本
  185. updateCurr(){
  186. if(this.curProduct.putQty>0){
  187. if(this.curProduct.putCost>0){
  188. this.addDetailProduct(this.curProduct, true)
  189. }else{
  190. uni.$u.toast("成本必须大于0!")
  191. this.curProduct.putCost = this.curProduct.putCostBackups
  192. }
  193. }else{
  194. // 删除
  195. this.delDetailProduct(this.curProduct)
  196. }
  197. },
  198. // 加减数量
  199. addQty(type){
  200. playAudio('info')
  201. const hasProduct = this.detailList.find(item => item.qrCode == this.code)
  202. if(hasProduct){
  203. hasProduct.putQty = hasProduct.putQty + (type ? 1 : -1)
  204. if(hasProduct.putQty>0){
  205. this.addDetailProduct(hasProduct, true)
  206. }else{
  207. // 删除
  208. this.delDetailProduct(hasProduct)
  209. }
  210. }
  211. },
  212. // 删除
  213. delDetailProduct(item) {
  214. sparePartsPurDetailDel({ sn: item.id }).then(res => {
  215. if (res.status == 200) {
  216. uni.$u.toast(res.message)
  217. this.pageInit()
  218. }
  219. })
  220. },
  221. // 查询产品
  222. queryProduct(){
  223. if(!this.code){
  224. uni.$u.toast("请扫码或输入条形码!")
  225. return
  226. }
  227. // 如果已添加产品,则累加数量
  228. const hasProduct = this.detailList.find(item => item.qrCode == this.code)
  229. console.log(hasProduct)
  230. if(!!hasProduct){
  231. this.addQty(true)
  232. return
  233. }
  234. if(this.code==''){
  235. uni.$u.toast("未识别到条形码!")
  236. playAudio('error')
  237. return
  238. }
  239. const params = {
  240. supplierSn: this.baseData.supplierSn,
  241. qrCode: this.code,
  242. pageNo:1,
  243. pageSize:1 ,
  244. }
  245. console.log(params)
  246. dealerProductQueryForSparePartsPur(params).then(res => {
  247. console.log(res)
  248. if(res.status == 200){
  249. const curProduct = res.data && res.data.list[0] || null
  250. console.log(curProduct)
  251. if(curProduct){
  252. curProduct.putCost = curProduct.purchasePrice
  253. curProduct.putQty = curProduct.putQty || 1
  254. if (this.defaultWarehouseCascade.length > 0) {
  255. curProduct.warehouseSn = this.defaultWarehouseCascade[0]
  256. curProduct.warehouseLocationSn = this.defaultWarehouseCascade[1]
  257. } else {
  258. curProduct.warehouseSn = undefined
  259. curProduct.warehouseLocationSn = undefined
  260. }
  261. // 添加产品
  262. this.addDetailProduct(curProduct, false)
  263. }else{
  264. uni.$u.toast("此商品不存在!")
  265. playAudio('error')
  266. }
  267. }
  268. })
  269. },
  270. // 添加明细
  271. addDetailProduct(row, isEdit){
  272. const params = {
  273. id: isEdit ? row.id : undefined,
  274. sparePartsPurchaseSn: this.sparePartsPurchaseSn,
  275. putCost: row.putCost,
  276. putQty: row.putQty,
  277. productCode: isEdit ? row.productCode : row.code,
  278. productOrigCode: (isEdit ? row.productOrigCode : row.origCode) || undefined,
  279. productSn: row.productSn,
  280. productTypeSn1: row.productTypeSn1,
  281. productTypeSn2: row.productTypeSn2,
  282. productTypeSn3: row.productTypeSn3,
  283. brandSn: isEdit ? row.brandSn : row.productBrandSn,
  284. warehouseLocationSn: row.warehouseLocationSn,
  285. warehouseSn: row.warehouseSn
  286. }
  287. if (isEdit) { // 编辑
  288. // 清空成本价或数量时,值应保持未清空前的值,因成本价和数量都不可为空
  289. if (!(row.putCost || row.putCost == 0)) {
  290. row.putCost = row.putCostBackups
  291. return
  292. }
  293. if (!row.putQty) {
  294. row.putQty = row.putQtyBackups
  295. return
  296. }
  297. }
  298. console.log(params)
  299. this.loading = true
  300. sparePartsPurDetailSave(params).then(res => {
  301. console.log(res,'添加')
  302. if (res.status == 200) {
  303. this.loading = false
  304. this.pageInit()
  305. } else {
  306. this.loading = false
  307. if(res.message == '采购成本价不能为空;'){
  308. this.$refs.popup.open()
  309. this.tempProduct = row
  310. }
  311. }
  312. })
  313. },
  314. // 详情
  315. getDetail(){
  316. sparePartsPurDetail({sn: this.sparePartsPurchaseSn}).then(res => {
  317. if(res.status == 200){
  318. this.baseData = res.data
  319. }
  320. })
  321. },
  322. // 已添加产品列表
  323. getDetailList(){
  324. sparePartsPurDetailList({pageNo:1,pageSize:1000,sparePartsPurchaseSn:this.sparePartsPurchaseSn}).then(res => {
  325. console.log(res,'已添加产品列表')
  326. if(res.status == 200){
  327. this.detailList = res.data.list
  328. this.detailList.map(item => {
  329. item.putCostBackups = item.putCost
  330. item.putQtyBackups = item.putQty
  331. })
  332. const curProduct = this.detailList.find(item => item.qrCode == this.code)
  333. this.curProduct = curProduct || null
  334. }
  335. })
  336. },
  337. getTotal(){
  338. sparePartsQueryCount({sparePartsPurchaseSn:this.sparePartsPurchaseSn}).then(res => {
  339. console.log(res,'getTotal')
  340. this.countData = res.data
  341. })
  342. },
  343. toDetail(item) {
  344. this.$store.state.vuex_tempData = item
  345. uni.navigateTo({
  346. url:"/pages/stockIn/detail?state="+this.baseData.state
  347. })
  348. },
  349. submitInStock(){
  350. sparePartsPurSubmitPut({id: this.sparePartsPurchaseId}).then(res => {
  351. if(res.status == 200){
  352. uni.$emit("refashList")
  353. uni.navigateBack()
  354. }
  355. })
  356. }
  357. },
  358. }
  359. </script>
  360. <style lang="scss">
  361. .p-content{
  362. button{
  363. line-height: 1.7;
  364. }
  365. .p-head{
  366. font-size: 32upx;
  367. color: $uni-text-color;
  368. >view{
  369. display: flex;
  370. align-items: center;
  371. padding: 15upx 20upx;
  372. border-bottom: 1px solid #eee;
  373. justify-content: space-between;
  374. > view{
  375. display: flex;
  376. padding: 0 10upx;
  377. align-items: center;
  378. }
  379. }
  380. .uni-input{
  381. border: 1px solid #eee;
  382. width: 150upx;
  383. text-align: center;
  384. }
  385. }
  386. .p-body{
  387. overflow: auto;
  388. flex-grow: 1;
  389. height: 50%;
  390. }
  391. .p-footer{
  392. padding:20upx 30upx;
  393. display: flex;
  394. > button{
  395. width: 30%;
  396. }
  397. }
  398. }
  399. </style>