cBom-list.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <el-dialog
  3. title="选择"
  4. :visible.sync="cBomListDialogFlag"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. top="5vh"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. width="80%"
  11. >
  12. <el-card shadow="never">
  13. <el-form
  14. size="small"
  15. label-width="60px"
  16. @keyup.enter.native="search"
  17. @submit.native.prevent
  18. >
  19. <el-row :gutter="10">
  20. <el-col :span="6">
  21. <el-form-item label="编码">
  22. <el-input
  23. clearable
  24. size="small"
  25. v-model="where.code"
  26. placeholder="请输入"
  27. />
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="6">
  31. <el-form-item label="名称">
  32. <el-input
  33. clearable
  34. size="small"
  35. v-model="where.name"
  36. placeholder="请输入"
  37. />
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="6">
  41. <el-form-item label="规格">
  42. <el-input
  43. clearable
  44. size="small"
  45. v-model="where.specification"
  46. placeholder="请输入"
  47. />
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="6">
  51. <el-form-item>
  52. <el-button
  53. size="small"
  54. type="primary"
  55. icon="el-icon-search"
  56. class="ele-btn-icon"
  57. @click="search"
  58. >
  59. 查询
  60. </el-button>
  61. <el-button
  62. @click="reset"
  63. icon="el-icon-refresh"
  64. class="ele-btn-icon"
  65. size="medium"
  66. >重置
  67. </el-button>
  68. <slot></slot>
  69. </el-form-item>
  70. </el-col>
  71. </el-row>
  72. </el-form>
  73. <ele-pro-table
  74. ref="table"
  75. :need-page="false"
  76. :columns="cBomColumns"
  77. :datasource="datasource"
  78. v-loading="loading"
  79. row-key="id"
  80. height="calc(100vh - 480px)"
  81. class="dict-table"
  82. :selection.sync="selection"
  83. >
  84. <!-- 表头工具栏 -->
  85. <template v-slot:action="{ row }">
  86. <el-radio class="radio" v-model="radio" :label="row.code">
  87. <i></i>
  88. </el-radio>
  89. </template>
  90. </ele-pro-table>
  91. </el-card>
  92. <div slot="footer">
  93. <el-button type="primary" size="small" @click="selected">选择</el-button>
  94. <el-button size="small" @click="handleClose">关闭</el-button>
  95. </div>
  96. </el-dialog>
  97. </template>
  98. <script>
  99. import { getCBomAPI } from '@/api/main';
  100. import { getInventoryTotalAPI } from '@/api/wms';
  101. export default {
  102. props: {
  103. /*是否需要获取仓库产品数量*/
  104. isGetInventoryTotal: {
  105. type: Boolean,
  106. default: false
  107. },
  108. /*已选择的产品*/
  109. currentRow: {
  110. type: Object,
  111. default: () => {}
  112. },
  113. cBomListDialogFlag: {
  114. type: Boolean,
  115. default: false
  116. }
  117. },
  118. data() {
  119. return {
  120. selection: [],
  121. datasource: [],
  122. oldDatasource: [],
  123. loading: false,
  124. where: {
  125. name: '',
  126. code: '',
  127. specification: ''
  128. }
  129. };
  130. },
  131. watch: {},
  132. computed: {
  133. cBomColumns() {
  134. return [
  135. {
  136. label: '选择',
  137. width: 45,
  138. type: 'selection',
  139. columnKey: 'selection',
  140. align: 'center'
  141. },
  142. {
  143. columnKey: 'index',
  144. type: 'index',
  145. width: 50,
  146. align: 'center',
  147. showOverflowTooltip: true,
  148. label: '序号'
  149. },
  150. {
  151. prop: 'category.categoryLevelPath',
  152. label: '分类',
  153. align: 'center',
  154. showOverflowTooltip: true
  155. },
  156. {
  157. prop: 'code',
  158. label: '编码',
  159. align: 'center',
  160. showOverflowTooltip: true,
  161. minWidth: 110
  162. },
  163. {
  164. prop: 'categoryCode',
  165. label: '物品编码',
  166. align: 'center',
  167. showOverflowTooltip: true,
  168. minWidth: 110
  169. },
  170. {
  171. prop: 'name',
  172. label: '名称',
  173. align: 'center',
  174. showOverflowTooltip: true,
  175. minWidth: 110
  176. },
  177. {
  178. prop: 'category.brandNum',
  179. align: 'center',
  180. label: '牌号',
  181. showOverflowTooltip: true
  182. },
  183. {
  184. prop: 'category.specification',
  185. label: '规格',
  186. align: 'center',
  187. showOverflowTooltip: true
  188. },
  189. {
  190. prop: 'category.modelType',
  191. label: '型号',
  192. align: 'center',
  193. showOverflowTooltip: true
  194. },
  195. {
  196. prop: 'dosage',
  197. label: '用量',
  198. align: 'center',
  199. showOverflowTooltip: true
  200. },
  201. {
  202. prop: 'category.measuringUnit',
  203. label: '单位',
  204. align: 'center',
  205. showOverflowTooltip: true
  206. },
  207. {
  208. prop: 'versions',
  209. label: '版本',
  210. align: 'center',
  211. showOverflowTooltip: true,
  212. formatter: (_row, _column, cellValue) => {
  213. return cellValue?'V'+cellValue+'.0':'';
  214. }
  215. }
  216. ];
  217. }
  218. },
  219. methods: {
  220. open(item) {
  221. this.getCBomDatasource();
  222. },
  223. /* 表格数据源 */
  224. async getCBomDatasource() {
  225. this.loading = true;
  226. this.datasource = await getCBomAPI({
  227. categoryId: this.currentRow?.id,
  228. bomType: 1,
  229. isLatestVersion: true
  230. // produceType: 2
  231. });
  232. this.oldDatasource = this.datasource;
  233. this.loading = false;
  234. /*
  235. * this.$util.toTreeData({
  236. data: list,
  237. idField: 'id',
  238. parentIdField: 'parentId'
  239. });*/
  240. },
  241. search() {
  242. //tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))
  243. this.loading = true;
  244. this.loading = false;
  245. this.datasource = this.oldDatasource.filter((data) => {
  246. return (
  247. data.name.toLowerCase().includes(this.where.name.toLowerCase()) &&
  248. data.code.toLowerCase().includes(this.where.code.toLowerCase()) &&
  249. data.specification
  250. .toLowerCase()
  251. .includes(this.where.specification.toLowerCase())
  252. );
  253. });
  254. },
  255. /* 刷新表格 */
  256. reset() {
  257. this.where = {
  258. name: '',
  259. code: '',
  260. specification: ''
  261. };
  262. this.datasource = this.oldDatasource;
  263. },
  264. handleClose() {
  265. this.$emit('update:cBomListDialogFlag', false);
  266. },
  267. async selected() {
  268. if (!this.selection.length) {
  269. return this.$message.warning('请至少选择一条数据');
  270. }
  271. let codeList = [];
  272. let list = this.selection;
  273. //获取仓库库存
  274. if (this.isGetInventoryTotal) {
  275. codeList = list.map((item) => item.code);
  276. let inventoryTotalList = await getInventoryTotalAPI(codeList);
  277. list.forEach((item) => {
  278. let find =
  279. inventoryTotalList.find((key) => key.code == item.code) || {};
  280. item.availableCountBase = find.availableCountBase;
  281. });
  282. }
  283. this.$emit('changeParent', list);
  284. this.handleClose();
  285. }
  286. }
  287. };
  288. </script>
  289. <style lang="scss" scoped>
  290. .tree_col {
  291. border: 1px solid #eee;
  292. padding: 10px 0;
  293. box-sizing: border-box;
  294. height: 500px;
  295. overflow: auto;
  296. }
  297. .table_col {
  298. padding-left: 10px;
  299. ::v-deep .el-table th.el-table__cell {
  300. background: #f2f2f2;
  301. }
  302. }
  303. .pagination {
  304. text-align: right;
  305. padding: 10px 0;
  306. }
  307. .btns {
  308. text-align: center;
  309. padding: 10px 0;
  310. }
  311. .topsearch {
  312. margin-bottom: 15px;
  313. }
  314. </style>