sparepartList_new.vue 13 KB

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