sparepart.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <template>
  2. <view class="main">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" right-icon="scan" title="申请备品备件"
  4. @clickLeft="goHome"></uni-nav-bar>
  5. <KdTabs v-model="active" :list="['基本信息','设备信息','备品备件信息']" />
  6. <view v-show="active==0">
  7. <Cell cellType="more" title="编号">
  8. <view class="cell-tip-right" slot="more">
  9. {{ addForm.code }}
  10. </view>
  11. </Cell>
  12. <Cell cellType="more" title="工单编码">
  13. <view class="cell-tip-right" slot="more">
  14. {{ addForm.repairCode }}
  15. </view>
  16. </Cell>
  17. <Cell cellType="more" title="工单名称">
  18. <view class="cell-tip-right" slot="more">
  19. {{ addForm.repairName }}
  20. </view>
  21. </Cell>
  22. <!-- <Cell cellType="more" title="设备编号">
  23. <view class="cell-tip-right" slot="more">
  24. {{ addForm.deviceCode }}
  25. </view>
  26. </Cell>
  27. <Cell cellType="more" title="设备名称">
  28. <view class="cell-tip-right" slot="more" v-if="sparePartsApplyList.length==0">
  29. {{ addForm.deviceName }}
  30. </view>
  31. <view class="cell-tip-right" slot="more" v-else>
  32. <uni-data-select style="width: 500rpx;" v-model="addForm.deviceId"
  33. :localdata="sparePartsApplyList" @change="sparePartsApplyChange"
  34. :clear="true"></uni-data-select>
  35. </view>
  36. </Cell>
  37. <Cell cellType="more" title="固资编码">
  38. <view class="cell-tip-right" slot="more">
  39. {{ addForm.fixCode }}
  40. </view>
  41. </Cell> -->
  42. <Cell cellType="more" title="领用部门">
  43. <view class="cell-tip-right" slot="more">
  44. {{ addForm.receivingDeptName }}
  45. </view>
  46. </Cell>
  47. <Cell cellType="more" title="领用人">
  48. <view class="cell-tip-right" slot="more">
  49. {{ addForm.recipientName }}
  50. </view>
  51. </Cell>
  52. <Cell cellType="more" title="使用部门">
  53. <view class="cell-tip-right" slot="more">
  54. <text class="input_text"
  55. @click="openPicker">{{ addForm.useDeptName ? addForm.useDeptName : '请选择' }}</text>
  56. </view>
  57. </Cell>
  58. <Cell cellType="more" title="使用人">
  59. <view class="cell-tip-right" slot="more" >
  60. <zxz-uni-data-select v-if="type=='add'" style="width: 300rpx;" :localdata="userList" v-model="addForm.userId"
  61. @change="handleUserChange"></zxz-uni-data-select>
  62. <text v-else>{{addForm.userName}}</text>
  63. </view>
  64. </Cell>
  65. <Cell cellType="more" title="使用时间">
  66. <view class="cell-tip-right" slot="more">
  67. <uni-datetime-picker v-if="type=='add'" type="date" class="picker" v-model="addForm.usageTime">
  68. </uni-datetime-picker>
  69. <text v-else>{{addForm.usageTime}}</text>
  70. </view>
  71. </Cell>
  72. <Cell cellType="more" title="用途">
  73. <u--textarea :disabled="type=='detail'" v-model="addForm.purpose" class="border" maxlength="500"
  74. placeholder="请输入内容" count></u--textarea>
  75. </Cell>
  76. </view>
  77. <view v-show="active==1" class="kd-equipment">
  78. <!-- <u-button v-if="type=='add'" type="success" size="small" class="u-reset-button" @click="addDevice()"
  79. text="添加物品"></u-button> -->
  80. <view class="kd-list-container">
  81. <u-list>
  82. <u-list-item v-for="(item, index) in deviceList" :key="index">
  83. <view class="kd-card">
  84. <view class="kd-card-wrapper">
  85. <uni-icons @click="del(item.id,1)" v-if="type=='add'" custom-prefix="iconfont"
  86. type="icon-shanchu" size="20" color="#fa3534"></uni-icons>
  87. <view class="kd-cell">
  88. <text class="kd-label">设备编码</text>
  89. {{ item.code }}
  90. </view>
  91. <view class="kd-cell">
  92. <text class="kd-label">设备名称</text>
  93. {{ item.name }}
  94. </view>
  95. <view class="kd-cell">
  96. <text class="kd-label">设备型号</text>
  97. {{ item.category&&item.category.modelType||item.model }}
  98. </view>
  99. <!-- <view class="kd-cell">
  100. <text class="kd-label">设备位置</text>
  101. {{ item.deviceLocationName.pathName }}
  102. </view> -->
  103. </view>
  104. </view>
  105. </u-list-item>
  106. </u-list>
  107. </view>
  108. </view>
  109. <view v-show="active==2">
  110. <u-button v-if="type=='add'" type="success" size="small" class="u-reset-button" @click="addPicking()"
  111. text="添加物品"></u-button>
  112. <view class="list_box">
  113. <u-list>
  114. <view v-for="(item, index) in tableList" :key="index" @change="e => selectVal(e, item, index)">
  115. <view class="listBox-con">
  116. <view class="listBox-top rx-bc">
  117. <view @click="del(item.id)"> <uni-icons v-if="type=='add'" custom-prefix="iconfont"
  118. type="icon-shanchu" size="20" color="#fa3534"></uni-icons>
  119. {{ item.categoryName }}
  120. </view>
  121. </view>
  122. <view class="listBox-bottom rx">
  123. <view class="items">
  124. <text>编码</text>
  125. {{ item.categoryCode }}
  126. </view>
  127. <view class="items">
  128. <text>牌号</text>
  129. {{ item.brandNum }}
  130. </view>
  131. <view class="items">
  132. <text>型号</text>
  133. {{ item.categoryModel }}
  134. </view>
  135. <view class="items">
  136. <text>规格</text>
  137. {{ item.specification }}
  138. </view>
  139. <view class="items">
  140. <text>级别</text>
  141. {{ item.level }}
  142. </view>
  143. <view class="items" style="display: flex;">
  144. <text>出库数量</text>
  145. <input v-if="type=='add'" style="width: 80px;" v-model="item.totalCount"
  146. type="number" @blur="handleInput(item,index)" placeholder="请输入出库数量" />
  147. <text v-else>{{item.totalCount}}</text>
  148. </view>
  149. <view class="items">
  150. <text>计量数量</text>
  151. {{ item.measureQuantity }}
  152. </view>
  153. <view class="items">
  154. <text>计量单位</text>
  155. {{ item.measureUnit }}
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. <view v-if="tableList.length == 0" style="margin-top: 20vh">
  161. <u-empty iconSize="150" textSize="32" text="暂无数据"></u-empty>
  162. </view>
  163. </u-list>
  164. </view>
  165. </view>
  166. <view class="footer" v-if="type=='add'">
  167. <text @click="submitAdd">提交</text>
  168. </view>
  169. <ba-tree-picker ref="treePicker" :multiple="false" @select-change="confirm" title="选择部门" :localdata="listData"
  170. valueKey="id" textKey="name" childrenKey="children" />
  171. </view>
  172. </template>
  173. <script>
  174. import KdTabs from '@/components/KdTabs.vue'
  175. import {
  176. listOrganizations,
  177. getUserPage
  178. } from '@/api/myTicket/index.js'
  179. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  180. import {
  181. applySpareParts,
  182. detailsId
  183. } from '@/api/repair'
  184. import Cell from '@/components/Cell.vue'
  185. import {
  186. postJ,
  187. get
  188. } from '@/utils/api.js'
  189. import dayjs from 'dayjs'
  190. export default {
  191. components: {
  192. Cell,
  193. KdTabs,
  194. baTreePicker
  195. },
  196. data() {
  197. return {
  198. active: 0,
  199. addForm: {
  200. name: '',
  201. repairId: '', //维修工单id
  202. repairCode: '',
  203. code: '',
  204. repairName: '',
  205. deviceName: '',
  206. fixCode: '',
  207. deviceCode: '',
  208. type: '4', //类型
  209. status: '1', //状态
  210. purpose: '',
  211. userId: '', //使用人id
  212. userName: '',
  213. useDeptId: '', //使用部门
  214. useDeptName: '',
  215. warehouseId: '',
  216. usageTime: '', //使用时间 //详情信息
  217. detailList: [],
  218. deviceId: '',
  219. executorDeptName: ''
  220. },
  221. tableList: [],
  222. deviceList: [],
  223. // sparePartsApplyList: [],
  224. type: 'add',
  225. showTime: '请选择时间',
  226. userList: [],
  227. listData: []
  228. }
  229. },
  230. onShow() {
  231. uni.$off('sparePartsApply')
  232. uni.$on('sparePartsApply', (data) => {
  233. this.tableList = data
  234. // console.log(data,'data')
  235. })
  236. },
  237. async onLoad(data) {
  238. const obj = JSON.parse(data.data)
  239. this.type = obj.pageType
  240. this.getDept()
  241. if (this.type == 'add') {
  242. this.addForm.repairCode = obj.code;
  243. this.addForm.repairName = obj.planName;
  244. this.addForm.repairId = obj.id;
  245. this.deviceList = obj.deviceList;
  246. // if (!obj.sparePartsApplyList) {
  247. // this.addForm.deviceName = obj.deviceName;
  248. // this.addForm.fixCode = obj.fixCode;
  249. // this.addForm.deviceCode = obj.deviceCode;
  250. // } else {
  251. // this.sparePartsApplyList = obj.sparePartsApplyList;
  252. // }
  253. } else {
  254. const form = await detailsId(obj.id)
  255. this.tableList = form.detailList
  256. this.deviceList = form.deviceList
  257. this.addForm = form
  258. if (this.addForm.useDeptId) {
  259. this.getUser(this.addForm.useDeptId)
  260. }
  261. }
  262. },
  263. methods: {
  264. openPicker() {
  265. this.$refs.treePicker._show()
  266. },
  267. del(id, type) {
  268. if (this.type != 'add') {
  269. return
  270. }
  271. if (type == 1) {
  272. this.deviceList = this.deviceList.filter((item) => item.id != id);
  273. return
  274. }
  275. this.tableList = this.tableList.filter((item) => item.id != id);
  276. },
  277. sparePartsApplyChange(value) {
  278. const data = this.sparePartsApplyList.find(item => item.value == value)
  279. this.addForm.deviceName = data.text;
  280. this.addForm.fixCode = data.fixCode;
  281. this.addForm.deviceCode = data.deviceCode;
  282. },
  283. // 出库数量限制
  284. handleInput(row, index) {
  285. if (row.totalCount > row.measureQuantity) {
  286. this.$set(this.tableList[index], 'totalCount', row.measureQuantity)
  287. }
  288. },
  289. addPicking() {
  290. uni.navigateTo({
  291. url: `/pages/maintenanceWorkorder/sparepart/sparepartList?codeS=` + JSON.stringify(this
  292. .tableList.map(item => item.categoryCode))
  293. })
  294. },
  295. goHome() {
  296. uni.navigateBack({
  297. delta: 1
  298. })
  299. },
  300. // 提交新增
  301. submitAdd() {
  302. if (this.deviceList.length == 0) {
  303. uni.showToast({
  304. title: '请选择设备!',
  305. icon: 'none'
  306. })
  307. return
  308. }
  309. if (this.tableList.length == 0) {
  310. uni.showToast({
  311. title: '请选择备品备件!',
  312. icon: 'none'
  313. })
  314. return
  315. }
  316. let boolen = this.tableList.every((item) => item.totalCount > 0);
  317. if (!boolen) {
  318. uni.showToast({
  319. title: '请输入出库数量!',
  320. icon: 'none'
  321. })
  322. return
  323. }
  324. uni.showLoading({
  325. title: '加载中'
  326. })
  327. this.addForm.detailList = this.tableList
  328. this.addForm.deviceList = this.deviceList
  329. applySpareParts(this.addForm)
  330. .then(res => {
  331. uni.showToast({
  332. title: '申请成功',
  333. icon: 'success',
  334. duration: 2000
  335. })
  336. setTimeout(() => {
  337. this.goHome()
  338. }, 2000)
  339. })
  340. .catch(e => {
  341. this.loading = false
  342. })
  343. },
  344. confirm(data, name) {
  345. this.addForm.useDeptName = name
  346. this.addForm.useDeptId = data[0]
  347. this.addForm.userName = ''
  348. this.addForm.userId = ''
  349. this.getUser(data[0])
  350. },
  351. getDept() {
  352. listOrganizations(1).then(data => {
  353. this.listData = data
  354. })
  355. },
  356. getUser(deptCode) {
  357. getUserPage({
  358. pageNum: 1,
  359. size: -1,
  360. groupId: deptCode
  361. }).then(data => {
  362. this.userList = data.list.map(item => {
  363. item.text = item.name
  364. item.value = item.id
  365. return item
  366. })
  367. })
  368. },
  369. handleUserChange(obj) {
  370. this.addForm.userName = obj.text
  371. },
  372. }
  373. }
  374. </script>
  375. <style scoped lang="scss">
  376. //底部按钮
  377. .footer {
  378. display: flex;
  379. flex-direction: row;
  380. justify-content: center;
  381. align-items: center;
  382. bottom: 0;
  383. width: 100%;
  384. height: 100rpx;
  385. text-align: center;
  386. position: fixed;
  387. // text {
  388. // width: 100%;
  389. // background-color: $j-primary-green;
  390. // font-size: 34rpx;
  391. // color: #FFFFFF;
  392. // line-height: 100rpx;
  393. // }
  394. text {
  395. width: 100%;
  396. background-color: $j-primary-green;
  397. font-size: 34rpx;
  398. color: #ffffff;
  399. line-height: 100rpx;
  400. }
  401. }
  402. .main {
  403. padding-bottom: 130rpx;
  404. }
  405. .border {
  406. border: 1px solid #eee;
  407. }
  408. .list_box {
  409. flex: 1;
  410. overflow: hidden;
  411. padding: 6rpx 0;
  412. .u-list {
  413. height: 100% !important;
  414. }
  415. }
  416. .list_box {
  417. margin-top: 8rpx;
  418. padding: 8rpx 24rpx;
  419. background: #fff;
  420. /deep/ .uni-checkbox-input-checked {
  421. background-color: $theme-color !important;
  422. border-color: $theme-color !important;
  423. }
  424. .listBox-con {
  425. // width: 650rpx;
  426. font-weight: 400;
  427. }
  428. .listBox-top {
  429. margin-top: 6rpx;
  430. color: #090a0a;
  431. font-size: 28rpx;
  432. font-style: normal;
  433. font-weight: 800;
  434. }
  435. .listBox-bottom {
  436. color: #090a0a;
  437. font-size: 24rpx;
  438. font-style: normal;
  439. flex-wrap: wrap;
  440. .items {
  441. width: calc(50% - 1px);
  442. border-left: 1rpx solid #e3e5e5;
  443. border-right: 1rpx solid #e3e5e5;
  444. border-bottom: 1rpx solid #e3e5e5;
  445. box-sizing: border-box;
  446. word-break: break-all;
  447. text {
  448. display: inline-block;
  449. background: #f7f9fa;
  450. padding: 8rpx 10rpx;
  451. color: #157a2c;
  452. }
  453. &:nth-child(1),
  454. &:nth-child(2) {
  455. border-top: 1rpx solid #e3e5e5;
  456. margin-top: 8rpx;
  457. }
  458. }
  459. }
  460. }
  461. .kd-equipment {
  462. flex: 1;
  463. display: flex;
  464. flex-direction: column;
  465. overflow: hidden;
  466. .kd-type-box {
  467. text-align: center;
  468. padding: 26rpx 0;
  469. view {
  470. position: relative;
  471. display: inline-block;
  472. width: 120rpx;
  473. padding: 4rpx 0;
  474. color: #747474;
  475. margin: 0 20rpx;
  476. background-color: rgba(215, 215, 215, 0.5);
  477. &.type—active {
  478. background-color: #1e7f35;
  479. color: #fff;
  480. }
  481. .count {
  482. position: absolute;
  483. top: -9px;
  484. right: -9px;
  485. width: 18px;
  486. height: 18px;
  487. border-radius: 50%;
  488. font-size: 12px;
  489. background-color: red;
  490. color: #fff;
  491. }
  492. }
  493. }
  494. .kd-list-container {
  495. flex: 1;
  496. display: flex;
  497. flex-direction: column;
  498. overflow: hidden;
  499. padding: 12rpx 18rpx;
  500. background-color: $page-bg;
  501. .u-list {
  502. flex: 1;
  503. height: 100% !important;
  504. }
  505. }
  506. }
  507. .kd-card {
  508. background-color: #fff;
  509. margin-bottom: 20rpx;
  510. padding: 8rpx 0;
  511. font-size: 28rpx;
  512. word-break: break-all;
  513. .kd-card-wrapper {
  514. padding: 0 30rpx;
  515. border-bottom: 1px solid #dadada;
  516. }
  517. .kd-cell {
  518. line-height: 60rpx;
  519. }
  520. .kd-cell:last-of-type {
  521. border-bottom: none;
  522. }
  523. .status-box {
  524. margin-right: 16rpx;
  525. }
  526. .card-footer {
  527. display: flex;
  528. justify-content: flex-end;
  529. align-items: center;
  530. padding: 8rpx 0 20rpx;
  531. button {
  532. width: 180rpx;
  533. height: 56rpx;
  534. line-height: 56rpx;
  535. font-size: 28rpx;
  536. margin: 0 8rpx;
  537. }
  538. .primary-btn {
  539. background-color: $j-primary-border-green;
  540. }
  541. }
  542. }
  543. .kd-cell {
  544. min-height: 90rpx;
  545. border-bottom: 1px dashed #dadada;
  546. display: flex;
  547. align-items: center;
  548. .kd-label {
  549. display: inline-block;
  550. width: 7em;
  551. font-weight: bold;
  552. }
  553. .kd-content {
  554. flex: 1;
  555. word-break: break-all;
  556. }
  557. }
  558. .kd-baseInfo {
  559. padding: 0 32rpx;
  560. font-size: 28rpx;
  561. }
  562. </style>