DetailDialog.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <uni-popup ref="popup" background-color="#fff" :is-mask-click="false">
  3. <view class="container">
  4. <view class="tools-box">
  5. <uni-easyinput
  6. prefixIcon="search"
  7. v-model="searchVal"
  8. placeholder="编码、名称"
  9. ></uni-easyinput>
  10. <view class="all" v-if="!type || type == 'input'">
  11. <view>已选 {{ selectionList.length }}/{{ tableData.length }} 项</view>
  12. <text @click="checkAll = !checkAll" class="text-primary">全选</text>
  13. </view>
  14. </view>
  15. <view class="list-container">
  16. <checkbox-group @change="checkboxChange">
  17. <view
  18. class="assets-cell"
  19. v-for="(item, index) in showList"
  20. :key="index"
  21. >
  22. <label>
  23. <view class="title"
  24. >{{ item.assetName }} <text>{{ item.onlyCode }}</text></view
  25. >
  26. <view class="col">
  27. <text
  28. ><text class="label">批次号</text> {{ item.batchNo }}</text
  29. >
  30. <text><text class="label">包装编码</text>{{ item.num }}</text>
  31. </view>
  32. <view class="col" v-if="!row.isUnpack">
  33. <text
  34. ><text class="label">最小包装单元</text
  35. >{{
  36. `${item.measurementUnit || ''}${item.unit}/${
  37. item.minPackUnit
  38. }`
  39. }}</text
  40. >
  41. <text><text class="label">入库天数</text>{{ item.day }}</text>
  42. </view>
  43. <view class="col">
  44. <text
  45. ><text class="label">{{
  46. item.manufactureTime ? '生产日期' : '采购日期'
  47. }}</text
  48. >{{ item.manufactureTime || item.procurementTime }}</text
  49. >
  50. </view>
  51. <view class="col">
  52. <text
  53. ><text class="label">过期日期</text
  54. >{{ item.expirationTime }}</text
  55. >
  56. </view>
  57. <checkbox
  58. :key="forceUpdate"
  59. :value="item.id + ''"
  60. :checked="item.checked || !!item.disabled"
  61. :disabled="!!item.disabled"
  62. v-if="type != 'detail'"
  63. ></checkbox>
  64. </label>
  65. </view>
  66. </checkbox-group>
  67. </view>
  68. </view>
  69. <view class="footer">
  70. <u-button
  71. size="large"
  72. type="success"
  73. @click="confirm"
  74. v-if="type != 'detail'"
  75. >确认添加</u-button
  76. >
  77. <u-button size="large" @click="cancel">返回</u-button>
  78. </view>
  79. </uni-popup>
  80. </template>
  81. <script>
  82. import { tableHeader } from '../../common'
  83. import { get } from '@/utils/api.js'
  84. export default {
  85. props: {
  86. // 新增 or 反显
  87. type: {
  88. type: String,
  89. default: '' //新增
  90. },
  91. assetsList: {
  92. type: Array,
  93. default: () => []
  94. },
  95. preAssetsList: {
  96. type: Array,
  97. default: () => []
  98. }
  99. },
  100. data () {
  101. return {
  102. tableHeader,
  103. searchVal: '',
  104. tableData: [],
  105. selectionList: [],
  106. cargoSpace: '',
  107. row: {},
  108. callback: null,
  109. forceUpdate: true
  110. }
  111. },
  112. computed: {
  113. checkAll: {
  114. get () {
  115. return (
  116. this.selectionList.length &&
  117. this.selectionList.length == this.showList.length
  118. )
  119. },
  120. set (val) {
  121. if (val) {
  122. this.selectionList = this.showList.map(item => item.id + '')
  123. this.showList.map(item => (item.checked = true))
  124. } else {
  125. this.selectionList = []
  126. this.showList.map(item => (item.checked = false))
  127. }
  128. this.forceUpdate = !this.forceUpdate
  129. }
  130. },
  131. showList () {
  132. if (this.searchVal) {
  133. return this.tableData.filter(
  134. ({ assetName, onlyCode, assetCode, batchNo }) => {
  135. return (
  136. String(assetName).indexOf(this.searchVal) != -1 ||
  137. String(onlyCode).indexOf(this.searchVal) != -1
  138. )
  139. }
  140. )
  141. }
  142. return this.tableData
  143. }
  144. },
  145. methods: {
  146. async open (row, cargoSpaceId, callback) {
  147. this.row = row
  148. this.callback = callback
  149. this.$refs.popup.open('right')
  150. const disabledDetailReqList = [
  151. ...(this.preAssetsList.find(i => i.curId == row.curId)?.detailReqList ||
  152. []),
  153. ...(this.assetsList.find(i => i.curId == row.curId)?.detailReqList ||
  154. [])
  155. ]
  156. if (!this.type) {
  157. const res = await get(
  158. this.apiUrl + '/conventionalStockTransfer/warehouse/getGoodsSingle',
  159. {
  160. assetCode: row.assetCode,
  161. assetType: row.assetType,
  162. cargoSpaceId: cargoSpaceId
  163. }
  164. )
  165. if (res?.success) {
  166. this.tableData = res.data
  167. .map(i => {
  168. i.checked = false
  169. i.batchNo = i.batchNum
  170. const obj = (this.row.detailReqList || []).find(
  171. itm => itm.id == i.id
  172. )
  173. if (obj) {
  174. i.checked = true
  175. this.selectionList.push(i.id + '')
  176. }
  177. if (disabledDetailReqList.find(p => p.onlyCode == i.onlyCode)) {
  178. i.checked = false
  179. i.disabled = true
  180. }
  181. return i
  182. })
  183. .filter(item => !item.disabled)
  184. }
  185. } else {
  186. // 反显
  187. const reList =
  188. this.type == 'output' ? 'curDetailReqList' : 'detailReqList' //反显列表
  189. console.log(this.row[reList], 'this.row')
  190. this.tableData = uni.$u.deepClone(this.row[reList])
  191. this.tableData.forEach(itm => {
  192. if (itm.checked) {
  193. this.selectionList.push(itm.id + '')
  194. }
  195. })
  196. }
  197. },
  198. checkboxChange (val) {
  199. this.selectionList = val.detail.value
  200. },
  201. confirm () {
  202. let selection = this.tableData.map(item => {
  203. item.checked = this.selectionList.includes(item.id + '')
  204. return item
  205. })
  206. if (this.type !== 'output') {
  207. selection = this.tableData.filter(item => item.checked)
  208. }
  209. this.callback && this.callback(selection)
  210. this.cancel()
  211. },
  212. cancel () {
  213. this.tableData = []
  214. this.selectionList = []
  215. this.$refs.popup.close()
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .container {
  222. width: 100vw;
  223. padding: 88rpx + $tab-height 10rpx 0; //安全高度
  224. box-sizing: border-box;
  225. background-color: $page-bg;
  226. height: 100vh;
  227. display: flex;
  228. flex-direction: column;
  229. overflow: hidden;
  230. }
  231. .tools-box {
  232. margin-bottom: 20rpx;
  233. }
  234. .all {
  235. display: flex;
  236. justify-content: flex-end;
  237. padding: 10rpx;
  238. padding-right: 30rpx;
  239. text {
  240. margin-left: 40rpx;
  241. }
  242. }
  243. .footer {
  244. position: fixed;
  245. bottom: 0;
  246. left: 0;
  247. right: 0;
  248. }
  249. .list-container {
  250. flex: 1;
  251. box-sizing: border-box;
  252. padding-bottom: 220rpx;
  253. overflow: auto;
  254. }
  255. .assets-cell {
  256. padding: 10rpx;
  257. font-size: 28rpx;
  258. position: relative;
  259. background-color: #fff;
  260. margin-bottom: 30rpx;
  261. color: #7f7f7f;
  262. .title {
  263. display: flex;
  264. justify-content: space-between;
  265. font-weight: bold;
  266. font-size: 32rpx;
  267. color: #555;
  268. margin-bottom: 10rpx;
  269. }
  270. .col {
  271. display: flex;
  272. justify-content: space-between;
  273. margin-bottom: 8rpx;
  274. text {
  275. flex: 1;
  276. }
  277. .label {
  278. margin-right: 40rpx;
  279. }
  280. }
  281. uni-checkbox {
  282. position: absolute;
  283. right: 0;
  284. bottom: 10rpx;
  285. }
  286. }
  287. </style>