link-material-dialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <ele-modal :visible.sync="visible" title="" width="80%" @close="cancel">
  3. <el-row :gutter="40">
  4. <el-col :span="12">
  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="100px">
  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.categoryLevelGroupId"
  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="12">
  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="100px">
  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.categoryLevelGroupId"
  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> </ele-pro-table
  173. ></el-col>
  174. </el-row>
  175. <div slot="footer" class="footer">
  176. <el-button type="primary" @click="save">保存</el-button>
  177. <el-button @click="cancel">取消</el-button>
  178. </div>
  179. </ele-modal>
  180. </template>
  181. <script>
  182. import {
  183. getRelatesInformationList,
  184. unassociated,
  185. productTieUpMaterial
  186. } from '@/api/material/product.js';
  187. import dictMixins from '@/mixins/dictMixins';
  188. import categorySelect from '@/components/CommomSelect/category-select.vue';
  189. export default {
  190. mixins: [dictMixins],
  191. components: { categorySelect },
  192. data () {
  193. return {
  194. visible: false,
  195. row: {},
  196. datasource: [],
  197. datasourceShow: [],
  198. datasourceRightShow: [],
  199. datasourceRight: [],
  200. selectionRight: [],
  201. selection: [],
  202. whereRight: {},
  203. where: {},
  204. type: '',
  205. idMap: {
  206. 8: '1678278350275198977',
  207. 4: '1678277959244431361',
  208. 5: '1678277781556936705'
  209. }
  210. };
  211. },
  212. created () {
  213. this.requestDict('类型用途');
  214. },
  215. computed: {
  216. catogaryName () {
  217. return this.getDictValue('类型用途', this.type);
  218. },
  219. dict () {},
  220. columns () {
  221. return [
  222. {
  223. type: 'selection',
  224. align: 'center'
  225. },
  226. {
  227. label: `${this.catogaryName}分类`,
  228. prop: 'categoryLevelGroupName'
  229. },
  230. {
  231. label: `${this.catogaryName}编码`,
  232. prop: 'code'
  233. },
  234. {
  235. label: `${this.catogaryName}名称`,
  236. prop: 'name'
  237. },
  238. {
  239. label: '型号',
  240. prop: 'modelType'
  241. }
  242. ];
  243. },
  244. columnsRight () {
  245. return [
  246. {
  247. type: 'selection',
  248. align: 'center'
  249. },
  250. {
  251. label: `${this.catogaryName}分类`,
  252. prop: 'categoryLevelGroupName'
  253. },
  254. {
  255. label: `${this.catogaryName}编码`,
  256. prop: 'code'
  257. },
  258. {
  259. label: `${this.catogaryName}名称`,
  260. prop: 'name'
  261. },
  262. {
  263. label: '型号',
  264. prop: 'modelType'
  265. },
  266. ...(this.type == 8
  267. ? [
  268. {
  269. label: '槽数',
  270. prop: 'modelType'
  271. },
  272. {
  273. label: '角度',
  274. slot: 'angle',
  275. action: 'angle'
  276. }
  277. ]
  278. : []),
  279. ...(this.type == 4
  280. ? [
  281. {
  282. label: '产能',
  283. slot: 'capacity',
  284. action: 'capacity'
  285. }
  286. ]
  287. : [])
  288. ];
  289. }
  290. },
  291. methods: {
  292. open (type, row) {
  293. this.type = type;
  294. this.row = row;
  295. this.getDatasource();
  296. this.getDatasourceRight();
  297. this.visible = true;
  298. },
  299. cancel () {
  300. this.visible = false;
  301. },
  302. async save () {
  303. if (!this.datasourceRightShow.length) {
  304. return this.$message.error('请添加关联数据');
  305. }
  306. const params = {
  307. mainCategoryId: this.row.categoryLevelId,
  308. mainCategoryLevelRootId: this.row.categoryLevelGroupId,
  309. materialDetailsPOList: this.datasourceRightShow.map((i) => ({
  310. ...i,
  311. categoryLevelRootId: this.type
  312. }))
  313. };
  314. await productTieUpMaterial(params);
  315. this.$message.success('操作成功!');
  316. this.$emit('success');
  317. },
  318. handleConect () {
  319. if (!this.selection.length) {
  320. return this.$message.error('请选择关联数据');
  321. }
  322. this.datasource = this.datasource.filter((i) =>
  323. this.selection.find((t) => t.categoryId != i.categoryId)
  324. );
  325. this.datasourceShow = this.datasourceShow.filter((i) =>
  326. this.selection.find((t) => t.categoryId != i.categoryId)
  327. );
  328. this.datasourceRightShow.push(...this.selection);
  329. this.datasourceRight.push(...this.selection);
  330. this.selection = [];
  331. },
  332. handleCancelConect () {
  333. if (!this.selectionRight.length) {
  334. return this.$message.error('请选择取消关联数据');
  335. }
  336. this.datasourceRight = this.datasourceRight.filter((i) =>
  337. this.selectionRight.find((t) => t.categoryId != i.categoryId)
  338. );
  339. this.datasourceRightShow = this.datasourceRightShow.filter((i) =>
  340. this.selectionRight.find((t) => t.categoryId != i.categoryId)
  341. );
  342. this.datasourceShow.push(...this.selectionRight);
  343. this.datasource.push(...this.selectionRight);
  344. this.selectionRight = [];
  345. },
  346. reload () {
  347. this.datasourceShow = this.datasource.filter((item) => {
  348. return (
  349. (!this.where.categoryLevelGroupId ||
  350. item.categoryLevelGroupId.includes(
  351. this.where.categoryLevelGroupId
  352. )) &&
  353. (!this.where.code || item.code.includes(this.where.code)) &&
  354. (!this.where.name || item.name.includes(this.where.name)) &&
  355. (!this.where.modelType ||
  356. item.modelType.includes(this.where.modelType))
  357. );
  358. });
  359. },
  360. reloadRight () {
  361. this.datasourceRightShow = this.datasourceRight.filter((item) => {
  362. return (
  363. (!this.whereRight.categoryLevelGroupId ||
  364. item.categoryLevelGroupId.includes(
  365. this.whereRight.categoryLevelGroupId
  366. )) &&
  367. (!this.whereRight.code ||
  368. item.code.includes(this.whereRight.code)) &&
  369. (!this.whereRight.name ||
  370. item.name.includes(this.whereRight.name)) &&
  371. (!this.whereRight.modelType ||
  372. item.modelType.includes(this.whereRight.modelType))
  373. );
  374. });
  375. },
  376. async getDatasource () {
  377. const data = await unassociated({
  378. categoryLevelGroupId: this.idMap[this.type]
  379. });
  380. this.datasource = data.slice(0);
  381. this.datasourceShow = data.slice(0);
  382. },
  383. async getDatasourceRight () {
  384. const data = await getRelatesInformationList({
  385. mainCategoryId: this.row.categoryLevelId,
  386. // categoryLevelGroupId: this.idMap[this.type],
  387. categoryLevelRootId: this.type
  388. });
  389. this.datasourceRight = data.slice(0);
  390. this.datasourceRightShow = data.slice(0);
  391. }
  392. }
  393. };
  394. </script>
  395. <style lang="scss" scoped>
  396. .ml20 {
  397. margin-left: 20px;
  398. }
  399. .footer {
  400. text-align: right;
  401. }
  402. </style>