link-material-dialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <ele-modal :visible.sync="visible" title="" width="95%" @close="cancel">
  3. <el-row :gutter="40">
  4. <el-col :span="11">
  5. <headerTitle>
  6. <template v-slot:title>
  7. 可选
  8. <el-button
  9. type="primary"
  10. class="ml20"
  11. size="mini"
  12. @click="handleConect"
  13. >关联</el-button
  14. >
  15. <el-button
  16. type="primary"
  17. size="mini"
  18. icon="icon-search"
  19. @click="reload"
  20. >搜索</el-button
  21. >
  22. </template>
  23. </headerTitle>
  24. <el-form label-width="60px">
  25. <el-row>
  26. <el-col :span="12">
  27. <el-form-item :label="`分类`">
  28. <categorySelect
  29. :pid="type"
  30. :key="type"
  31. v-model="where.categoryId"
  32. />
  33. <!-- <el-input
  34. placeholder="请输入"
  35. clearable
  36. v-model="where.categoryLevelGroupId"
  37. ></el-input> -->
  38. </el-form-item></el-col
  39. >
  40. <el-col :span="12">
  41. <el-form-item :label="`编码`">
  42. <el-input
  43. placeholder="请输入"
  44. clearable
  45. v-model="where.code"
  46. ></el-input></el-form-item
  47. ></el-col>
  48. <el-col :span="12">
  49. <el-form-item :label="`名称`">
  50. <el-input
  51. placeholder="请输入"
  52. clearable
  53. v-model="where.name"
  54. ></el-input></el-form-item
  55. ></el-col>
  56. <el-col :span="12">
  57. <el-form-item label="型号">
  58. <el-input
  59. placeholder="请输入"
  60. clearable
  61. v-model="where.modelType"
  62. ></el-input></el-form-item
  63. ></el-col>
  64. </el-row>
  65. </el-form>
  66. <ele-pro-table
  67. ref="table"
  68. :columns="columns"
  69. :datasource="datasourceShow"
  70. :selection.sync="selection"
  71. cache-key="link-material-dialog"
  72. height="45vh"
  73. :initLoad="false"
  74. :need-page="false"
  75. >
  76. </ele-pro-table>
  77. </el-col>
  78. <el-col :span="13">
  79. <headerTitle
  80. ><template v-slot:title
  81. >已关联
  82. <el-button
  83. type="primary"
  84. class="ml20"
  85. size="mini"
  86. @click="handleCancelConect"
  87. >取消关联</el-button
  88. >
  89. <el-button
  90. type="primary"
  91. size="mini"
  92. icon="icon-search"
  93. @click="reloadRight"
  94. >搜索</el-button
  95. ></template
  96. ></headerTitle
  97. >
  98. <el-form label-width="60px">
  99. <el-row>
  100. <el-col :span="12">
  101. <el-form-item :label="`分类`">
  102. <categorySelect
  103. :pid="type"
  104. :key="type"
  105. v-model="whereRight.categoryId"
  106. /> </el-form-item
  107. ></el-col>
  108. <el-col :span="12">
  109. <el-form-item :label="`编码`">
  110. <el-input
  111. clearable
  112. placeholder="请输入"
  113. v-model="whereRight.code"
  114. ></el-input></el-form-item
  115. ></el-col>
  116. <el-col :span="12">
  117. <el-form-item :label="`名称`">
  118. <el-input
  119. clearable
  120. placeholder="请输入"
  121. v-model="whereRight.name"
  122. ></el-input></el-form-item
  123. ></el-col>
  124. <el-col :span="12">
  125. <el-form-item label="型号">
  126. <el-input
  127. clearable
  128. placeholder="请输入"
  129. v-model="whereRight.modelType"
  130. ></el-input></el-form-item
  131. ></el-col>
  132. </el-row>
  133. </el-form>
  134. <ele-pro-table
  135. ref="tableRight"
  136. :columns="columnsRight"
  137. :datasource="datasourceRightShow"
  138. :selection.sync="selectionRight"
  139. height="45vh"
  140. :initLoad="false"
  141. :need-page="false"
  142. cache-key="link-material-dialog-right"
  143. >
  144. <template v-slot:capacity="{ row }">
  145. <el-row>
  146. <el-col :span="8">
  147. <el-input v-model="row.quantity"></el-input
  148. ></el-col>
  149. <el-col :span="8">
  150. <DictSelection
  151. class="line-select"
  152. dictName="重量单位"
  153. clearable
  154. v-model="row.quantityUnitId"
  155. >
  156. </DictSelection
  157. ></el-col>
  158. <el-col :span="8">
  159. <DictSelection
  160. class="line-select"
  161. dictName="提前期单位"
  162. clearable
  163. v-model="row.timeUnit"
  164. >
  165. </DictSelection
  166. ></el-col>
  167. </el-row>
  168. </template>
  169. <template v-slot:angle="{ row }">
  170. <DictSelection dictName="角度" clearable v-model="row.angle">
  171. </DictSelection>
  172. </template>
  173. </ele-pro-table>
  174. </el-col>
  175. </el-row>
  176. <div slot="footer" class="footer">
  177. <el-button type="primary" @click="save">保存</el-button>
  178. <el-button @click="cancel">取消</el-button>
  179. </div>
  180. </ele-modal>
  181. </template>
  182. <script>
  183. import {
  184. getRelatesInformationList,
  185. unassociated,
  186. productTieUpMaterial
  187. } from '@/api/material/product.js';
  188. import dictMixins from '@/mixins/dictMixins';
  189. import categorySelect from '@/components/CommomSelect/category-select.vue';
  190. export default {
  191. mixins: [dictMixins],
  192. components: { categorySelect },
  193. data () {
  194. return {
  195. visible: false,
  196. row: {},
  197. datasource: [],
  198. datasourceShow: [],
  199. datasourceRightShow: [],
  200. datasourceRight: [],
  201. selectionRight: [],
  202. selection: [],
  203. whereRight: {},
  204. where: {},
  205. type: '',
  206. idMap: {
  207. 8: '1678278350275198977',
  208. 4: '1678277959244431361',
  209. 5: '1678277781556936705'
  210. }
  211. };
  212. },
  213. created () {
  214. this.requestDict('类型用途');
  215. },
  216. computed: {
  217. catogaryName () {
  218. return this.getDictValue('类型用途', this.type);
  219. },
  220. dict () {},
  221. columns () {
  222. return [
  223. {
  224. type: 'selection',
  225. align: 'center'
  226. },
  227. {
  228. label: `${this.catogaryName}分类`,
  229. prop: 'categoryLevelGroupName'
  230. },
  231. {
  232. label: `${this.catogaryName}编码`,
  233. prop: 'code'
  234. },
  235. {
  236. label: `${this.catogaryName}名称`,
  237. prop: 'name'
  238. },
  239. {
  240. label: '型号',
  241. prop: 'modelType'
  242. }
  243. ];
  244. },
  245. columnsRight () {
  246. return [
  247. {
  248. type: 'selection',
  249. align: 'center'
  250. },
  251. {
  252. label: `${this.catogaryName}分类`,
  253. prop: 'categoryLevelGroupName',
  254. width: 110
  255. },
  256. {
  257. label: `${this.catogaryName}编码`,
  258. prop: 'code',
  259. width: 110
  260. },
  261. {
  262. label: `${this.catogaryName}名称`,
  263. prop: 'name',
  264. width: 110
  265. },
  266. {
  267. label: '型号',
  268. prop: 'modelType'
  269. },
  270. ...(this.type == 8
  271. ? [
  272. {
  273. label: '槽数',
  274. prop: 'slotNum',
  275. formatter:(_row, _column, cellValue) => {
  276. return _row.extendInfo.slotNum;
  277. }
  278. },
  279. {
  280. label: '角度',
  281. slot: 'angle',
  282. action: 'angle'
  283. }
  284. ]
  285. : []),
  286. ...(this.type == 4
  287. ? [
  288. {
  289. label: '产能',
  290. slot: 'capacity',
  291. action: 'capacity',
  292. width: 240
  293. }
  294. ]
  295. : [])
  296. ];
  297. }
  298. },
  299. methods: {
  300. open (type, row) {
  301. this.type = type;
  302. this.row = row;
  303. // console.log('this.row',this.row)
  304. this.getDatasource();
  305. this.getDatasourceRight();
  306. this.visible = true;
  307. },
  308. cancel () {
  309. this.visible = false;
  310. },
  311. async save () {
  312. // if (!this.datasourceRightShow.length) {
  313. // return this.$message.error('请添加关联数据');
  314. // }
  315. const params = {
  316. mainCategoryId: this.row.id,
  317. mainCategoryLevelRootId: this.type,
  318. materialDetailsPOList: this.datasourceRightShow.map((i) => ({
  319. ...i,
  320. categoryLevelRootId: this.type
  321. }))
  322. };
  323. await productTieUpMaterial(params);
  324. this.cancel();
  325. this.$message.success('操作成功!');
  326. this.$emit('success');
  327. },
  328. handleConect () {
  329. if (!this.selection.length) {
  330. return this.$message.error('请选择关联数据');
  331. }
  332. this.datasource = this.datasource.filter(
  333. (i) => !this.selection.find((t) => t.categoryId == i.categoryId)
  334. );
  335. this.datasourceShow = this.datasourceShow.filter(
  336. (i) => !this.selection.find((t) => t.categoryId == i.categoryId)
  337. );
  338. this.datasourceRightShow.push(...this.selection);
  339. this.datasourceRight.push(...this.selection);
  340. this.selection = [];
  341. },
  342. handleCancelConect () {
  343. if (!this.selectionRight.length) {
  344. return this.$message.error('请选择取消关联数据');
  345. }
  346. this.datasourceRight = this.datasourceRight.filter(
  347. (i) => !this.selectionRight.find((t) => t.categoryId == i.categoryId)
  348. );
  349. this.datasourceRightShow = this.datasourceRightShow.filter(
  350. (i) => !this.selectionRight.find((t) => t.categoryId == i.categoryId)
  351. );
  352. this.datasourceShow.push(...this.selectionRight);
  353. this.datasource.push(...this.selectionRight);
  354. this.selectionRight = [];
  355. },
  356. reload () {
  357. this.datasourceShow = this.datasource.filter((item) => {
  358. return (
  359. (!this.where.categoryId ||
  360. item.parentId.includes(
  361. this.where.categoryId
  362. )) &&
  363. (!this.where.code || item.code.includes(this.where.code)) &&
  364. (!this.where.name || item.name.includes(this.where.name)) &&
  365. (!this.where.modelType ||
  366. item.modelType.includes(this.where.modelType))
  367. );
  368. });
  369. },
  370. reloadRight () {
  371. this.datasourceRightShow = this.datasourceRight.filter((item) => {
  372. return (
  373. (!this.whereRight.categoryId ||
  374. item.parentId.includes(
  375. this.whereRight.categoryId
  376. )) &&
  377. (!this.whereRight.code ||
  378. item.code.includes(this.whereRight.code)) &&
  379. (!this.whereRight.name ||
  380. item.name.includes(this.whereRight.name)) &&
  381. (!this.whereRight.modelType ||
  382. item.modelType.includes(this.whereRight.modelType))
  383. );
  384. });
  385. },
  386. async getDatasource () {
  387. const data = await unassociated({
  388. categoryLevelGroupId: this.idMap[this.type],
  389. categoryLevelRootId: this.type,
  390. mainCategoryId: this.row.id
  391. });
  392. this.datasource = data.slice(0);
  393. this.datasourceShow = data.slice(0);
  394. },
  395. async getDatasourceRight () {
  396. const data = await getRelatesInformationList({
  397. categoryLevelGroupId: this.idMap[this.type],
  398. categoryLevelRootId: this.type,
  399. mainCategoryId: this.row.id
  400. });
  401. this.datasourceRight = data.slice(0);
  402. this.datasourceRightShow = data.slice(0);
  403. }
  404. }
  405. };
  406. </script>
  407. <style lang="scss" scoped>
  408. .ml20 {
  409. margin-left: 20px;
  410. }
  411. .footer {
  412. text-align: right;
  413. }
  414. </style>