link-material-dialog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. </ele-pro-table
  145. ></el-col>
  146. </el-row>
  147. <div slot="footer" class="footer">
  148. <el-button type="primary" @click="save">保存</el-button>
  149. <el-button @click="cancel">取消</el-button>
  150. </div>
  151. </ele-modal>
  152. </template>
  153. <script>
  154. import {
  155. getRelatesInformationList,
  156. unassociated,
  157. productTieUpMaterial
  158. } from '@/api/material/product.js';
  159. import dictMixins from '@/mixins/dictMixins';
  160. import categorySelect from '@/components/CommomSelect/category-select.vue';
  161. export default {
  162. mixins: [dictMixins],
  163. components: { categorySelect },
  164. data () {
  165. return {
  166. visible: false,
  167. row: {},
  168. datasource: [],
  169. datasourceShow: [],
  170. datasourceRightShow: [],
  171. datasourceRight: [],
  172. selectionRight: [],
  173. selection: [],
  174. whereRight: {},
  175. where: {},
  176. type: '',
  177. idMap: {
  178. 6: '1678278090828136449',
  179. 5: '1678277781556936705'
  180. }
  181. };
  182. },
  183. created () {
  184. this.requestDict('类型用途');
  185. },
  186. computed: {
  187. catogaryName () {
  188. return this.getDictValue('类型用途', this.type);
  189. },
  190. dict () {},
  191. columns () {
  192. return [
  193. {
  194. type: 'selection',
  195. align: 'center'
  196. },
  197. {
  198. label: `${this.catogaryName}分类`,
  199. prop: 'categoryLevelGroupName'
  200. },
  201. {
  202. label: `${this.catogaryName}编码`,
  203. prop: 'code'
  204. },
  205. {
  206. label: `${this.catogaryName}名称`,
  207. prop: 'name'
  208. },
  209. {
  210. label: '型号',
  211. prop: 'modelType'
  212. }
  213. ];
  214. },
  215. columnsRight () {
  216. return [
  217. {
  218. type: 'selection',
  219. align: 'center'
  220. },
  221. {
  222. label: `${this.catogaryName}分类`,
  223. prop: 'categoryLevelGroupName'
  224. },
  225. {
  226. label: `${this.catogaryName}编码`,
  227. prop: 'code'
  228. },
  229. {
  230. label: `${this.catogaryName}名称`,
  231. prop: 'name'
  232. },
  233. {
  234. label: '型号',
  235. prop: 'modelType'
  236. }
  237. ];
  238. }
  239. },
  240. methods: {
  241. open (type, row) {
  242. this.type = type;
  243. this.row = row;
  244. this.getDatasource();
  245. this.getDatasourceRight();
  246. this.visible = true;
  247. },
  248. cancel () {
  249. this.visible = false;
  250. },
  251. async save () {
  252. if (!this.datasourceRightShow.length) {
  253. return this.$message.error('请添加关联数据');
  254. }
  255. const params = {
  256. mainCategoryId: this.row.categoryLevelId,
  257. mainCategoryLevelRootId: this.row.categoryLevelGroupId,
  258. materialDetailsPOList: this.datasourceRightShow.map((i) => ({
  259. ...i,
  260. categoryLevelRootId: this.type
  261. }))
  262. };
  263. await productTieUpMaterial(params);
  264. this.cancel();
  265. this.$message.success('操作成功!');
  266. this.$emit('success');
  267. },
  268. handleConect () {
  269. if (!this.selection.length) {
  270. return this.$message.error('请选择关联数据');
  271. }
  272. this.datasource = this.datasource.filter((i) =>
  273. this.selection.find((t) => t.categoryId != i.categoryId)
  274. );
  275. this.datasourceShow = this.datasourceShow.filter((i) =>
  276. this.selection.find((t) => t.categoryId != i.categoryId)
  277. );
  278. this.datasourceRightShow.push(...this.selection);
  279. this.datasourceRight.push(...this.selection);
  280. this.selection = [];
  281. },
  282. handleCancelConect () {
  283. if (!this.selectionRight.length) {
  284. return this.$message.error('请选择取消关联数据');
  285. }
  286. this.datasourceRight = this.datasourceRight.filter((i) =>
  287. this.selectionRight.find((t) => t.categoryId != i.categoryId)
  288. );
  289. this.datasourceRightShow = this.datasourceRightShow.filter((i) =>
  290. this.selectionRight.find((t) => t.categoryId != i.categoryId)
  291. );
  292. this.datasourceShow.push(...this.selectionRight);
  293. this.datasource.push(...this.selectionRight);
  294. this.selectionRight = [];
  295. },
  296. reload () {
  297. this.datasourceShow = this.datasource.filter((item) => {
  298. return (
  299. (!this.where.categoryLevelGroupId ||
  300. item.categoryLevelGroupId.includes(
  301. this.where.categoryLevelGroupId
  302. )) &&
  303. (!this.where.code || item.code.includes(this.where.code)) &&
  304. (!this.where.name || item.name.includes(this.where.name)) &&
  305. (!this.where.modelType ||
  306. item.modelType.includes(this.where.modelType))
  307. );
  308. });
  309. },
  310. reloadRight () {
  311. this.datasourceRightShow = this.datasourceRight.filter((item) => {
  312. return (
  313. (!this.whereRight.categoryLevelGroupId ||
  314. item.categoryLevelGroupId.includes(
  315. this.whereRight.categoryLevelGroupId
  316. )) &&
  317. (!this.whereRight.code ||
  318. item.code.includes(this.whereRight.code)) &&
  319. (!this.whereRight.name ||
  320. item.name.includes(this.whereRight.name)) &&
  321. (!this.whereRight.modelType ||
  322. item.modelType.includes(this.whereRight.modelType))
  323. );
  324. });
  325. },
  326. async getDatasource () {
  327. const data = await unassociated({
  328. categoryLevelGroupId: this.idMap[this.type]
  329. });
  330. this.datasource = data.slice(0);
  331. this.datasourceShow = data.slice(0);
  332. },
  333. async getDatasourceRight () {
  334. const data = await getRelatesInformationList({
  335. mainCategoryId: this.row.categoryLevelId,
  336. // categoryLevelGroupId: this.idMap[this.type],
  337. categoryLevelRootId: this.type
  338. });
  339. this.datasourceRight = data.slice(0);
  340. this.datasourceRightShow = data.slice(0);
  341. }
  342. }
  343. };
  344. </script>
  345. <style lang="scss" scoped>
  346. .ml20 {
  347. margin-left: 20px;
  348. }
  349. .footer {
  350. text-align: right;
  351. }
  352. </style>