sparepartList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template slot-scope="scope">
  2. <view>
  3. <view class="sparepartList">
  4. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="申请备品备件" @clickLeft="back">
  5. <view slot="right" @click="confirm">确定</view>
  6. </uni-nav-bar>
  7. <view class="searchBar">
  8. <u-icon class="icon" :size="50" name="list" @click="show = true"></u-icon>
  9. <u-search v-model="searchForm.assetName" shape="round" searchIconSize="50" :clearabled="true" :actionStyle="searchStyle" @search="search" @custom="search" @clear="search"></u-search>
  10. </view>
  11. <view class="listBox">
  12. <u-list v-if="tableData.length > 0" class="list" @scrolltolower="scrolltolower">
  13. <u-list-item v-for="(item, index) in tableData" :key="index">
  14. <u-cell value="内容">
  15. <view slot="title" class="u-slot-title">{{ item.name }}</view>
  16. <!-- <view slot="label" class="u-slot-title">{{ item.modelType }}/{{ item.specification }}</view> -->
  17. <view slot="value" class="u-cell-value">
  18. <u-checkbox-group size="30" iconPlacement="right" placement="column" @change="selectItem($event, index)">
  19. <u-checkbox size="30" :labelSize="30" :customStyle="{ marginBottom: '8px' }" :key="index" :label="item.availableCountBase" :name="item"></u-checkbox>
  20. </u-checkbox-group>
  21. </view>
  22. </u-cell>
  23. </u-list-item>
  24. </u-list>
  25. <view v-else class="no-data">暂无数据</view>
  26. </view>
  27. <u-picker v-if="show" :show="show" :columns="columns" keyName="label" @cancel="close" @confirm="config" :defaultIndex="dimensionIndex"></u-picker>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import { getDetailById, getBatchDetails, applySpareParts, saveNew, getInventoryDetails, getMaterielDetails } from '@/api/repair'
  33. export default {
  34. data() {
  35. return {
  36. checkboxList: [],
  37. tableData: [],
  38. dimensionIndex: [0],
  39. dimension: 4,
  40. show: false,
  41. columns: [
  42. [
  43. {
  44. label: '物料维度',
  45. value: '4'
  46. },
  47. {
  48. label: '包装维度',
  49. value: '3'
  50. },
  51. {
  52. label: '批次维度',
  53. value: '2'
  54. }
  55. ]
  56. ],
  57. searchForm: {
  58. assetName: ''
  59. },
  60. searchStyle: {
  61. background: '#F62F33',
  62. width: '105rpx',
  63. height: '50rpx',
  64. borderRadius: '30rpx',
  65. fontSize: '28rpx',
  66. color: '#FFFFFF',
  67. lineHeight: '50rpx',
  68. textAlign: 'center'
  69. },
  70. pageNum: 1,
  71. warehousingMaterialList: [],
  72. batchDetailsVOList: [],
  73. materialCodeReqList: [],
  74. selectionList: [],
  75. wlParams: {},
  76. materialObj: {},
  77. total: 0
  78. }
  79. },
  80. onLoad(options) {
  81. this.id = options.id
  82. },
  83. onShow() {
  84. this.getList()
  85. },
  86. methods: {
  87. search() {
  88. this.pageNum = 1
  89. this.tableData = []
  90. this.getList()
  91. },
  92. getList() {
  93. uni.showLoading({
  94. title: '加载中'
  95. })
  96. return new Promise(async (resolve, reject) => {
  97. try {
  98. let params = { assetName: this.searchForm.assetName, dimension: this.dimension, pageNum: this.pageNum, size: 15, categoryLevelId: 6 }
  99. if (this.dimension == 2) {
  100. let res = await getBatchDetails(params)
  101. this.total = res.count
  102. this.tableData = this.tableData.concat(
  103. res.list.map(item => {
  104. return {
  105. ...item,
  106. minUnit: item.packingUnit,
  107. oid: item.stockBatchId,
  108. assetCode: item.code
  109. }
  110. })
  111. )
  112. } else if (this.dimension == 3) {
  113. let res = await getInventoryDetails(params)
  114. this.total = res.count
  115. this.tableData = this.tableData.concat(
  116. res.list.map(item => {
  117. return {
  118. ...item,
  119. batchNo: item.batchNum,
  120. minUnit: item.packingUnit,
  121. packingCountBase: 1,
  122. oid: item.id,
  123. assetCode: item.code
  124. }
  125. })
  126. )
  127. } else if (this.dimension == 4) {
  128. let res = await getMaterielDetails(params)
  129. this.total = res.count
  130. this.tableData = this.tableData.concat(
  131. res.list.map((item, index) => {
  132. return {
  133. ...item,
  134. availableCountBase: 1,
  135. packingCountBase: 1,
  136. minUnit: item.packingUnit,
  137. oid: item.id + this.pages.pageNum + (index + 1)
  138. }
  139. })
  140. )
  141. }
  142. uni.hideLoading()
  143. resolve()
  144. } catch (error) {
  145. console.log(error)
  146. uni.hideLoading()
  147. reject()
  148. }
  149. })
  150. },
  151. selectItem(data, index) {
  152. if (data[0]) {
  153. this.checkboxList[index] = data[0]
  154. } else {
  155. this.checkboxList[index] = ''
  156. }
  157. },
  158. config(data) {
  159. console.log(data)
  160. this.dimension = data.value[0].value
  161. this.dimensionIndex = data.indexs
  162. this.show = false
  163. this.pageNum = 1
  164. this.tableData = []
  165. this.getList()
  166. },
  167. close() {
  168. this.show = false
  169. },
  170. scrolltolower(e) {
  171. console.log(e)
  172. },
  173. back() {
  174. uni.navigateBack({
  175. delta: 1
  176. })
  177. },
  178. async handleExit(arr) {
  179. console.log(arr)
  180. let ids = null
  181. let batchIds = null
  182. let materielIds = null
  183. if (this.dimension == 3) {
  184. ids = arr.map(item => {
  185. return item.id
  186. })
  187. } else if (this.dimension == 2) {
  188. ids = arr.map(item => {
  189. return item.recordId
  190. })
  191. batchIds = arr.map(item => {
  192. return item.stockBatchId
  193. })
  194. } else if (this.dimension == 4) {
  195. materielIds = arr.map(item => {
  196. return item.materielId
  197. })
  198. ids = arr.map(item => {
  199. return item.recordId
  200. })
  201. } else {
  202. ids = arr.map(item => {
  203. return item.recordId
  204. })
  205. }
  206. let categoryIds = arr.map(item => {
  207. return item.id
  208. })
  209. let batchNos = arr.map(item => {
  210. return item.batchNo
  211. })
  212. let outInDetailIds = arr.map(item => {
  213. return item.outInDetailId
  214. })
  215. const parmas = {
  216. categoryLevelId: 6,
  217. type: this.dimension,
  218. categoryIds,
  219. batchNos,
  220. batchIds,
  221. ids,
  222. outInDetailIds,
  223. materielIds
  224. }
  225. const data = await getDetailById(parmas)
  226. return data
  227. },
  228. async confirm() {
  229. let checkboxList = this.checkboxList.filter(item => !!item)
  230. if (!checkboxList.length) {
  231. uni.showToast({
  232. icon: 'error',
  233. title: '请选择备品备件!',
  234. duration: 2000
  235. })
  236. return
  237. }
  238. const data = await this.handleExit(checkboxList)
  239. let arr = []
  240. if (this.dimension == 4) {
  241. arr = checkboxList.map(item => {
  242. return { ...item, assetName: item.name }
  243. })
  244. }
  245. this.detailData({ ...data, wlList: arr }, this.dimension)
  246. },
  247. detailData(data, dimension) {
  248. this.dimension = dimension
  249. console.log('总数居', data)
  250. console.log(dimension)
  251. // this.onSelectTableDataVal = data.realTimeInventoryVOList;
  252. this.warehousingMaterialList = data.realTimeInventoryVOList.map(next => {
  253. delete next.updateTime
  254. delete next.createTime
  255. return {
  256. ...next,
  257. realInventoryAmount: 0,
  258. assetType: 6,
  259. outInNum: '',
  260. assetCode: next.code,
  261. assetName: next.name,
  262. bizStatus: 2,
  263. contactCode: next.contactCode
  264. }
  265. })
  266. // this.batchDetailsVOList = data.batchDetailsVOList;
  267. if (dimension == 4) {
  268. this.materialCodeReqList = data.wlList
  269. this.selectionList = data.wlList
  270. let params = {
  271. realTimeInventoryNewPOList: data.realTimeInventoryVOList
  272. }
  273. for (const item of params.realTimeInventoryNewPOList) {
  274. item.inventoryDetailsNewPOList = item.inventoryDetailsVOList
  275. for (const detail of item.inventoryDetailsNewPOList) {
  276. detail.outInMaterialDetailsAddPOList = []
  277. for (const wlItem of data.wlList) {
  278. if (detail.id === wlItem.recordId) {
  279. detail.outInMaterialDetailsAddPOList.push({
  280. ...wlItem
  281. })
  282. }
  283. }
  284. }
  285. }
  286. this.wlParams = params
  287. this.materialObj = data
  288. } else if (dimension == 3) {
  289. //包装维度出库
  290. const list = data.realTimeInventoryVOList
  291. //获取包装维度
  292. let packArr = []
  293. for (const item of list) {
  294. if (item.inventoryDetailsVOList.length != 0) {
  295. for (const iterator of item.inventoryDetailsVOList) {
  296. packArr.push({ ...iterator, batchNo: iterator.batchNum })
  297. }
  298. }
  299. }
  300. this.batchDetailsVOList = packArr.map(item => {
  301. return {
  302. ...item,
  303. packingCountBase: dimension == 4 || dimension == 3 ? 1 : item.packingCountBase
  304. // weight: 0
  305. }
  306. })
  307. //物料维度数据
  308. let meteArr = []
  309. for (const item of packArr) {
  310. if (item.materialDetailsVOList.length != 0) {
  311. for (const iterator of item.materialDetailsVOList) {
  312. meteArr.push({
  313. ...iterator
  314. })
  315. }
  316. }
  317. }
  318. this.materialCodeReqList = meteArr
  319. //再次打开选择上
  320. this.selectionList = list
  321. //send数据
  322. this.wlParams = { realTimeInventoryNewPOList: list }
  323. this.wlParams.realTimeInventoryNewPOList.forEach(item => {
  324. item.inventoryDetailsNewPOList = item.inventoryDetailsVOList
  325. item.inventoryDetailsNewPOList.forEach(ite => {
  326. // ite.weight = 0;
  327. ite.outInMaterialDetailsAddPOList = ite.materialDetailsVOList
  328. })
  329. })
  330. } else {
  331. // else if (dimension == 2) {
  332. // this.batchDetailsVOList = data.wlList;
  333. // this.selectionList = data.wlList;
  334. // }
  335. //物品维度出库
  336. const list = data.realTimeInventoryVOList
  337. //获取包装维度
  338. let packArr = []
  339. for (const item of list) {
  340. if (item.inventoryDetailsVOList.length != 0) {
  341. for (const iterator of item.inventoryDetailsVOList) {
  342. packArr.push({ ...iterator, batchNo: iterator.batchNum })
  343. }
  344. }
  345. }
  346. this.batchDetailsVOList = packArr.map(item => {
  347. return {
  348. ...item,
  349. packingCountBase: dimension == 3 ? 1 : item.packingCountBase
  350. // weight: 0
  351. }
  352. })
  353. //物料维度数据
  354. let meteArr = []
  355. for (const item of packArr) {
  356. if (item.materialDetailsVOList.length != 0) {
  357. for (const iterator of item.materialDetailsVOList) {
  358. meteArr.push({
  359. ...iterator
  360. })
  361. }
  362. }
  363. }
  364. this.materialCodeReqList = meteArr
  365. //再次打开选择上
  366. this.selectionList = list
  367. //send数据
  368. this.wlParams = { realTimeInventoryNewPOList: list }
  369. this.wlParams.realTimeInventoryNewPOList.forEach(item => {
  370. item.inventoryDetailsNewPOList = item.inventoryDetailsVOList
  371. item.inventoryDetailsNewPOList.forEach(ite => {
  372. // ite.weight = 0;
  373. ite.outInMaterialDetailsAddPOList = ite.materialDetailsVOList
  374. })
  375. })
  376. }
  377. this.handleNewSave()
  378. },
  379. async handleNewSave() {
  380. let userInfo = wx.getStorageSync('userInfo')
  381. let obj = {
  382. fromUser: userInfo.userId,
  383. bizType: '4', // 领用出库
  384. extInfo: {
  385. assetType: 6,
  386. verifyDeptCode: userInfo.deptId[0],
  387. verifyDeptName: userInfo.deptName
  388. },
  389. type: 2,
  390. fromType: 2
  391. }
  392. obj = { ...obj, ...this.wlParams }
  393. if (this.dimension == 4) {
  394. obj.num = this.materialObj.wlList.length
  395. } else {
  396. obj.num = this.materialCodeReqList.length
  397. }
  398. obj.storageSource = 1
  399. try {
  400. const res = await saveNew(obj)
  401. if (res.code == 0) {
  402. let arr = obj.realTimeInventoryNewPOList.map(item => {
  403. return {
  404. sparePartsId: item.id,
  405. sparePartsList: JSON.stringify({
  406. ...item,
  407. inventoryDetailsNewPOList: [],
  408. inventoryDetailsVOList: [],
  409. outInIds: res.data
  410. })
  411. }
  412. })
  413. applySpareParts({
  414. workOrderId: this.id,
  415. infoList: arr
  416. }).then(res => {
  417. uni.showToast({
  418. icon: 'success',
  419. title: '申请成功!',
  420. duration: 2000
  421. })
  422. setTimeout(() => {
  423. this.back()
  424. }, 1000)
  425. })
  426. }
  427. } catch (error) {
  428. console.log(error)
  429. }
  430. },
  431. // 触底加载
  432. scrolltolower() {
  433. this.loadmore()
  434. },
  435. loadmore() {
  436. if (this.tableData.length < this.total) {
  437. this.pageNum += 1
  438. this.getList()
  439. }
  440. }
  441. }
  442. }
  443. </script>
  444. <style lang="scss" scoped>
  445. .sparepartList {
  446. height: 100vh;
  447. width: 100%;
  448. overflow: hidden;
  449. display: flex;
  450. flex-direction: column;
  451. .searchBar {
  452. padding: 20rpx;
  453. display: flex;
  454. .icon {
  455. margin-right: 20rpx;
  456. }
  457. }
  458. .listBox {
  459. flex: 1;
  460. height: 0;
  461. .list {
  462. height: 100% !important;
  463. }
  464. .u-cell-value {
  465. width: 70rpx;
  466. }
  467. .no-data {
  468. height: 100%;
  469. width: 100%;
  470. display: flex;
  471. align-items: center;
  472. justify-content: center;
  473. font-size: 30rpx;
  474. }
  475. }
  476. }
  477. </style>