cBom-list.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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: 'name',
  165. label: '名称',
  166. align: 'center',
  167. showOverflowTooltip: true,
  168. minWidth: 110
  169. },
  170. {
  171. prop: 'category.brandNum',
  172. align: 'center',
  173. label: '牌号',
  174. showOverflowTooltip: true
  175. },
  176. {
  177. prop: 'category.specification',
  178. label: '规格',
  179. align: 'center',
  180. showOverflowTooltip: true
  181. },
  182. {
  183. prop: 'category.modelType',
  184. label: '型号',
  185. align: 'center',
  186. showOverflowTooltip: true
  187. },
  188. {
  189. prop: 'dosage',
  190. label: '用量',
  191. align: 'center',
  192. showOverflowTooltip: true
  193. },
  194. {
  195. prop: 'category.measuringUnit',
  196. label: '单位',
  197. align: 'center',
  198. showOverflowTooltip: true
  199. },
  200. {
  201. prop: 'versions',
  202. label: '版本',
  203. align: 'center',
  204. showOverflowTooltip: true,
  205. formatter: (_row, _column, cellValue) => {
  206. return cellValue?'V'+cellValue+'.0':'';
  207. }
  208. }
  209. ];
  210. }
  211. },
  212. methods: {
  213. open(item) {
  214. this.getCBomDatasource();
  215. },
  216. /* 表格数据源 */
  217. async getCBomDatasource() {
  218. this.loading = true;
  219. this.datasource = await getCBomAPI({
  220. categoryId: this.currentRow?.id,
  221. bomType: 1
  222. // produceType: 2
  223. });
  224. this.oldDatasource = this.datasource;
  225. this.loading = false;
  226. /*
  227. * this.$util.toTreeData({
  228. data: list,
  229. idField: 'id',
  230. parentIdField: 'parentId'
  231. });*/
  232. },
  233. search() {
  234. //tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))
  235. this.loading = true;
  236. this.loading = false;
  237. this.datasource = this.oldDatasource.filter((data) => {
  238. return (
  239. data.name.toLowerCase().includes(this.where.name.toLowerCase()) &&
  240. data.code.toLowerCase().includes(this.where.code.toLowerCase()) &&
  241. data.specification
  242. .toLowerCase()
  243. .includes(this.where.specification.toLowerCase())
  244. );
  245. });
  246. },
  247. /* 刷新表格 */
  248. reset() {
  249. this.where = {
  250. name: '',
  251. code: '',
  252. specification: ''
  253. };
  254. this.datasource = this.oldDatasource;
  255. },
  256. handleClose() {
  257. this.$emit('update:cBomListDialogFlag', false);
  258. },
  259. async selected() {
  260. if (!this.selection.length) {
  261. return this.$message.warning('请至少选择一条数据');
  262. }
  263. let codeList = [];
  264. let list = this.selection;
  265. //获取仓库库存
  266. if (this.isGetInventoryTotal) {
  267. codeList = list.map((item) => item.code);
  268. let inventoryTotalList = await getInventoryTotalAPI(codeList);
  269. list.forEach((item) => {
  270. let find =
  271. inventoryTotalList.find((key) => key.code == item.code) || {};
  272. item.availableCountBase = find.availableCountBase;
  273. });
  274. }
  275. this.$emit('changeParent', list);
  276. this.handleClose();
  277. }
  278. }
  279. };
  280. </script>
  281. <style lang="scss" scoped>
  282. .tree_col {
  283. border: 1px solid #eee;
  284. padding: 10px 0;
  285. box-sizing: border-box;
  286. height: 500px;
  287. overflow: auto;
  288. }
  289. .table_col {
  290. padding-left: 10px;
  291. ::v-deep .el-table th.el-table__cell {
  292. background: #f2f2f2;
  293. }
  294. }
  295. .pagination {
  296. text-align: right;
  297. padding: 10px 0;
  298. }
  299. .btns {
  300. text-align: center;
  301. padding: 10px 0;
  302. }
  303. .topsearch {
  304. margin-bottom: 15px;
  305. }
  306. </style>