代码和资料文档参考下一章:属性分组-后端(商品服务完成)

image.png

属性分组页面组件-attrgroup.vue

  1. <template>
  2. <el-row :gutter="20">
  3. <el-col :span="6">
  4. <category @tree-node-click="treenodeclick"></category>
  5. </el-col>
  6. <el-col :span="18">
  7. <div class="mod-config">
  8. <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
  9. <el-form-item>
  10. <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button @click="getDataList()">查询</el-button>
  14. <el-button type="success" @click="getAllDataList()">查询全部</el-button>
  15. <el-button
  16. v-if="isAuth('product:attrgroup:save')"
  17. type="primary"
  18. @click="addOrUpdateHandle()"
  19. >新增
  20. </el-button>
  21. <el-button
  22. v-if="isAuth('product:attrgroup:delete')"
  23. type="danger"
  24. @click="deleteHandle()"
  25. :disabled="dataListSelections.length <= 0"
  26. >批量删除
  27. </el-button>
  28. </el-form-item>
  29. </el-form>
  30. <el-table
  31. :data="dataList"
  32. border
  33. v-loading="dataListLoading"
  34. @selection-change="selectionChangeHandle"
  35. style="width: 100%;"
  36. >
  37. <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
  38. <el-table-column prop="attrGroupId" header-align="center" align="center" label="分组id"></el-table-column>
  39. <el-table-column prop="attrGroupName" header-align="center" align="center" label="组名"></el-table-column>
  40. <el-table-column prop="sort" header-align="center" align="center" label="排序"></el-table-column>
  41. <el-table-column prop="descript" header-align="center" align="center" label="描述"></el-table-column>
  42. <el-table-column prop="icon" header-align="center" align="center" label="组图标"></el-table-column>
  43. <el-table-column prop="catelogId" header-align="center" align="center" label="所属分类id"></el-table-column>
  44. <el-table-column
  45. fixed="right"
  46. header-align="center"
  47. align="center"
  48. width="150"
  49. label="操作"
  50. >
  51. <template slot-scope="scope">
  52. <el-button type="text" size="small" @click="relationHandle(scope.row.attrGroupId)">关联</el-button>
  53. <el-button
  54. type="text"
  55. size="small"
  56. @click="addOrUpdateHandle(scope.row.attrGroupId)"
  57. >修改
  58. </el-button>
  59. <el-button type="text" size="small" @click="deleteHandle(scope.row.attrGroupId)">删除</el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <el-pagination
  64. @size-change="sizeChangeHandle"
  65. @current-change="currentChangeHandle"
  66. :current-page="pageIndex"
  67. :page-sizes="[10, 20, 50, 100]"
  68. :page-size="pageSize"
  69. :total="totalPage"
  70. layout="total, sizes, prev, pager, next, jumper"
  71. ></el-pagination>
  72. <!-- 弹窗, 新增 / 修改 -->
  73. <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  74. <!-- 修改关联关系 -->
  75. <relation-update v-if="relationVisible" ref="relationUpdate" @refreshData="getDataList"></relation-update>
  76. </div>
  77. </el-col>
  78. </el-row>
  79. </template>
  80. <script>
  81. /**
  82. * 父子组件传递数据
  83. * 1)、子组件给父组件传递数据,事件机制;
  84. * 子组件给父组件发送一个事件,携带上数据。
  85. * // this.$emit("事件名",携带的数据...)
  86. */
  87. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  88. //例如:import 《组件名称》 from '《组件路径》';
  89. import Category from "@/views/common/category";
  90. import AddOrUpdate from "./attrgroup-add-or-update";
  91. import RelationUpdate from "./attr-group-relation";
  92. export default {
  93. //import引入的组件需要注入到对象中才能使用
  94. components: {Category, AddOrUpdate, RelationUpdate},
  95. props: {},
  96. data() {
  97. return {
  98. catId: 0,
  99. dataForm: {
  100. key: ""
  101. },
  102. dataList: [],
  103. pageIndex: 1,
  104. pageSize: 10,
  105. totalPage: 0,
  106. dataListLoading: false,
  107. dataListSelections: [],
  108. addOrUpdateVisible: false,
  109. relationVisible: false
  110. };
  111. },
  112. activated() {
  113. this.getDataList();
  114. },
  115. methods: {
  116. //处理分组与属性的关联
  117. relationHandle(groupId) {
  118. this.relationVisible = true;
  119. this.$nextTick(() => {
  120. this.$refs.relationUpdate.init(groupId);
  121. });
  122. },
  123. //感知树节点被点击
  124. treenodeclick(data, node, component) {
  125. if (node.level === 3) {
  126. this.catId = data.catId;
  127. this.getDataList(); //重新查询
  128. }
  129. },
  130. getAllDataList() {
  131. this.catId = 0;
  132. this.getDataList();
  133. },
  134. // 获取数据列表
  135. getDataList() {
  136. this.dataListLoading = true;
  137. this.$http({
  138. url: this.$http.adornUrl(`/product/attrgroup/list/${this.catId}`),
  139. method: "get",
  140. params: this.$http.adornParams({
  141. page: this.pageIndex,
  142. limit: this.pageSize,
  143. key: this.dataForm.key
  144. })
  145. }).then(({data}) => {
  146. if (data && data.code === 0) {
  147. this.dataList = data.page.list;
  148. this.totalPage = data.page.totalCount;
  149. } else {
  150. this.dataList = [];
  151. this.totalPage = 0;
  152. }
  153. this.dataListLoading = false;
  154. });
  155. },
  156. // 每页数
  157. sizeChangeHandle(val) {
  158. this.pageSize = val;
  159. this.pageIndex = 1;
  160. this.getDataList();
  161. },
  162. // 当前页
  163. currentChangeHandle(val) {
  164. this.pageIndex = val;
  165. this.getDataList();
  166. },
  167. // 多选
  168. selectionChangeHandle(val) {
  169. this.dataListSelections = val;
  170. },
  171. // 新增 / 修改
  172. addOrUpdateHandle(id) {
  173. this.addOrUpdateVisible = true;
  174. this.$nextTick(() => {
  175. this.$refs.addOrUpdate.init(id);
  176. });
  177. },
  178. // 删除
  179. deleteHandle(id) {
  180. var ids = id
  181. ? [id]
  182. : this.dataListSelections.map(item => {
  183. return item.attrGroupId;
  184. });
  185. this.$confirm(
  186. `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
  187. "提示",
  188. {
  189. confirmButtonText: "确定",
  190. cancelButtonText: "取消",
  191. type: "warning"
  192. }
  193. ).then(() => {
  194. this.$http({
  195. url: this.$http.adornUrl("/product/attrgroup/delete"),
  196. method: "post",
  197. data: this.$http.adornData(ids, false)
  198. }).then(({data}) => {
  199. if (data && data.code === 0) {
  200. this.$message({
  201. message: "操作成功",
  202. type: "success",
  203. duration: 1500,
  204. onClose: () => {
  205. this.getDataList();
  206. }
  207. });
  208. } else {
  209. this.$message.error(data.msg);
  210. }
  211. });
  212. });
  213. }
  214. }
  215. };
  216. </script>
  217. <style scoped>
  218. </style>

属性分组新增/修改组件-attrgroup-add-or-update.vue

此组件是属性分组点击新增或修改按钮弹出表单弹框的页面

  1. <template>
  2. <el-dialog
  3. :title="!dataForm.id ? '新增' : '修改'"
  4. :close-on-click-modal="false"
  5. :visible.sync="visible"
  6. @closed="dialogClose"
  7. >
  8. <el-form
  9. :model="dataForm"
  10. :rules="dataRule"
  11. ref="dataForm"
  12. @keyup.enter.native="dataFormSubmit()"
  13. label-width="120px"
  14. >
  15. <el-form-item label="组名" prop="attrGroupName">
  16. <el-input v-model="dataForm.attrGroupName" placeholder="组名"></el-input>
  17. </el-form-item>
  18. <el-form-item label="排序" prop="sort">
  19. <el-input v-model="dataForm.sort" placeholder="排序"></el-input>
  20. </el-form-item>
  21. <el-form-item label="描述" prop="descript">
  22. <el-input v-model="dataForm.descript" placeholder="描述"></el-input>
  23. </el-form-item>
  24. <el-form-item label="组图标" prop="icon">
  25. <el-input v-model="dataForm.icon" placeholder="组图标"></el-input>
  26. </el-form-item>
  27. <el-form-item label="所属分类" prop="catelogId">
  28. <!-- <el-input v-model="dataForm.catelogId" placeholder="所属分类id"></el-input> @change="handleChange" -->
  29. <!-- <el-cascader filterable placeholder="试试搜索:手机" v-model="catelogPath" :options="categorys" :props="props"></el-cascader> -->
  30. <!-- :catelogPath="catelogPath"自定义绑定的属性,可以给子组件传值 -->
  31. <category-cascader :catelogPath.sync="catelogPath"></category-cascader>
  32. </el-form-item>
  33. </el-form>
  34. <span slot="footer" class="dialog-footer">
  35. <el-button @click="visible = false">取消</el-button>
  36. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  37. </span>
  38. </el-dialog>
  39. </template>
  40. <script>
  41. import CategoryCascader from '@/views/common/category-cascader'
  42. export default {
  43. data() {
  44. return {
  45. props:{
  46. value:"catId",
  47. label:"name",
  48. children:"children"
  49. },
  50. visible: false,
  51. categorys: [],
  52. catelogPath: [],
  53. dataForm: {
  54. attrGroupId: 0,
  55. attrGroupName: "",
  56. sort: "",
  57. descript: "",
  58. icon: "",
  59. catelogId: 0
  60. },
  61. dataRule: {
  62. attrGroupName: [
  63. { required: true, message: "组名不能为空", trigger: "blur" }
  64. ],
  65. sort: [{ required: true, message: "排序不能为空", trigger: "blur" }],
  66. descript: [
  67. { required: true, message: "描述不能为空", trigger: "blur" }
  68. ],
  69. icon: [{ required: true, message: "组图标不能为空", trigger: "blur" }],
  70. catelogId: [
  71. { required: true, message: "所属分类id不能为空", trigger: "blur" }
  72. ]
  73. }
  74. };
  75. },
  76. components:{CategoryCascader},
  77. methods: {
  78. dialogClose(){
  79. this.catelogPath = [];
  80. },
  81. getCategorys(){
  82. this.$http({
  83. url: this.$http.adornUrl("/product/category/list/tree"),
  84. method: "get"
  85. }).then(({ data }) => {
  86. this.categorys = data.data;
  87. });
  88. },
  89. init(id) {
  90. this.dataForm.attrGroupId = id || 0;
  91. this.visible = true;
  92. this.$nextTick(() => {
  93. this.$refs["dataForm"].resetFields();
  94. if (this.dataForm.attrGroupId) {
  95. this.$http({
  96. url: this.$http.adornUrl(
  97. `/product/attrgroup/info/${this.dataForm.attrGroupId}`
  98. ),
  99. method: "get",
  100. params: this.$http.adornParams()
  101. }).then(({ data }) => {
  102. if (data && data.code === 0) {
  103. this.dataForm.attrGroupName = data.attrGroup.attrGroupName;
  104. this.dataForm.sort = data.attrGroup.sort;
  105. this.dataForm.descript = data.attrGroup.descript;
  106. this.dataForm.icon = data.attrGroup.icon;
  107. this.dataForm.catelogId = data.attrGroup.catelogId;
  108. //查出catelogId的完整路径
  109. this.catelogPath = data.attrGroup.catelogPath;
  110. }
  111. });
  112. }
  113. });
  114. },
  115. // 表单提交
  116. dataFormSubmit() {
  117. this.$refs["dataForm"].validate(valid => {
  118. if (valid) {
  119. this.$http({
  120. url: this.$http.adornUrl(
  121. `/product/attrgroup/${
  122. !this.dataForm.attrGroupId ? "save" : "update"
  123. }`
  124. ),
  125. method: "post",
  126. data: this.$http.adornData({
  127. attrGroupId: this.dataForm.attrGroupId || undefined,
  128. attrGroupName: this.dataForm.attrGroupName,
  129. sort: this.dataForm.sort,
  130. descript: this.dataForm.descript,
  131. icon: this.dataForm.icon,
  132. catelogId: this.catelogPath[this.catelogPath.length-1]
  133. })
  134. }).then(({ data }) => {
  135. if (data && data.code === 0) {
  136. this.$message({
  137. message: "操作成功",
  138. type: "success",
  139. duration: 1500,
  140. onClose: () => {
  141. this.visible = false;
  142. this.$emit("refreshDataList");
  143. }
  144. });
  145. } else {
  146. this.$message.error(data.msg);
  147. }
  148. });
  149. }
  150. });
  151. }
  152. },
  153. created(){
  154. this.getCategorys();
  155. }
  156. };
  157. </script>

获取三级分类组件-category.vue

属性分组页面左侧三级分类显示的组件

  1. <template>
  2. <div>
  3. <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input>
  4. <el-tree
  5. :data="menus"
  6. :props="defaultProps"
  7. node-key="catId"
  8. ref="menuTree"
  9. @node-click="nodeclick"
  10. :filter-node-method="filterNode"
  11. :highlight-current="true"
  12. ></el-tree>
  13. </div>
  14. </template>
  15. <script>
  16. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  17. //例如:import 《组件名称》 from '《组件路径》';
  18. export default {
  19. //import引入的组件需要注入到对象中才能使用
  20. components: {},
  21. props: {},
  22. data() {
  23. //这里存放数据
  24. return {
  25. filterText: "",
  26. menus: [],
  27. expandedKey: [],
  28. defaultProps: {
  29. children: "children",
  30. label: "name"
  31. }
  32. };
  33. },
  34. //计算属性 类似于data概念
  35. computed: {},
  36. //监控data中的数据变化
  37. watch: {
  38. filterText(val) {
  39. this.$refs.menuTree.filter(val);
  40. }
  41. },
  42. //方法集合
  43. methods: {
  44. //树节点过滤
  45. filterNode(value, data) {
  46. if (!value) return true;
  47. return data.name.indexOf(value) !== -1;
  48. },
  49. getMenus() {
  50. this.$http({
  51. url: this.$http.adornUrl("/product/category/list/tree"),
  52. method: "get"
  53. }).then(({data}) => {
  54. this.menus = data.data;
  55. });
  56. },
  57. nodeclick(data, node, component) {
  58. console.log("子组件category的节点被点击", data, node, component);
  59. //向父组件发送事件;
  60. this.$emit("tree-node-click", data, node, component);
  61. }
  62. },
  63. //生命周期 - 创建完成(可以访问当前this实例)
  64. created() {
  65. this.getMenus();
  66. },
  67. //生命周期 - 挂载完成(可以访问DOM元素)
  68. mounted() {
  69. },
  70. beforeCreate() {
  71. }, //生命周期 - 创建之前
  72. beforeMount() {
  73. }, //生命周期 - 挂载之前
  74. beforeUpdate() {
  75. }, //生命周期 - 更新之前
  76. updated() {
  77. }, //生命周期 - 更新之后
  78. beforeDestroy() {
  79. }, //生命周期 - 销毁之前
  80. destroyed() {
  81. }, //生命周期 - 销毁完成
  82. activated() {
  83. } //如果页面有keep-alive缓存功能,这个函数会触发
  84. };
  85. </script>
  86. <style scoped>
  87. </style>

分类级联选择组件-category-cascader.vue

此组件可以生成级联选择三级分类,属性分组新增修改时选择三级分类使用

  1. <template>
  2. <!--
  3. 使用说明:
  4. 1)、引入category-cascader.vue
  5. 2)、语法:<category-cascader :catelogPath.sync="catelogPath"></category-cascader>
  6. 解释:
  7. catelogPath:指定的值是cascader初始化需要显示的值,应该和父组件的catelogPath绑定;
  8. 由于有sync修饰符,所以cascader路径变化以后自动会修改父的catelogPath,这是结合子组件this.$emit("update:catelogPath",v);做的
  9. -->
  10. <div>
  11. <el-cascader
  12. filterable
  13. clearable
  14. placeholder="试试搜索:手机"
  15. v-model="paths"
  16. :options="categorys"
  17. :props="setting"
  18. ></el-cascader>
  19. </div>
  20. </template>
  21. <script>
  22. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  23. //例如:import 《组件名称》 from '《组件路径》';
  24. export default {
  25. //import引入的组件需要注入到对象中才能使用
  26. components: {},
  27. //接受父组件传来的值
  28. props: {
  29. catelogPath: {
  30. type: Array,
  31. default(){
  32. return [];
  33. }
  34. }
  35. },
  36. data() {
  37. //这里存放数据
  38. return {
  39. setting: {
  40. value: "catId",
  41. label: "name",
  42. children: "children"
  43. },
  44. categorys: [],
  45. paths: this.catelogPath
  46. };
  47. },
  48. watch:{
  49. catelogPath(v){
  50. this.paths = this.catelogPath;
  51. console.log(this.paths)
  52. },
  53. paths(v){
  54. this.$emit("update:catelogPath",v);
  55. //还可以使用pubsub-js进行传值
  56. PubSub.publish("catPath",v);
  57. }
  58. },
  59. //方法集合
  60. methods: {
  61. getCategorys() {
  62. this.$http({
  63. url: this.$http.adornUrl("/product/category/list/tree"),
  64. method: "get"
  65. }).then(({ data }) => {
  66. this.categorys = data.data;
  67. });
  68. }
  69. },
  70. //生命周期 - 创建完成(可以访问当前this实例)
  71. created() {
  72. this.getCategorys();
  73. }
  74. };
  75. </script>
  76. <style scoped>
  77. </style>

属性分组关联组件-attr-group-relation.vue

  1. <template>
  2. <div>
  3. <el-dialog :close-on-click-modal="false" :visible.sync="visible" @closed="dialogClose">
  4. <el-dialog width="40%" title="选择属性" :visible.sync="innerVisible" append-to-body>
  5. <div>
  6. <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
  7. <el-form-item>
  8. <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
  9. </el-form-item>
  10. <el-form-item>
  11. <el-button @click="getDataList()">查询</el-button>
  12. </el-form-item>
  13. </el-form>
  14. <el-table
  15. :data="dataList"
  16. border
  17. v-loading="dataListLoading"
  18. @selection-change="innerSelectionChangeHandle"
  19. style="width: 100%;"
  20. >
  21. <el-table-column type="selection" header-align="center" align="center"></el-table-column>
  22. <el-table-column prop="attrId" header-align="center" align="center" label="属性id"></el-table-column>
  23. <el-table-column prop="attrName" header-align="center" align="center" label="属性名"></el-table-column>
  24. <el-table-column prop="icon" header-align="center" align="center" label="属性图标"></el-table-column>
  25. <el-table-column prop="valueSelect" header-align="center" align="center" label="可选值列表"></el-table-column>
  26. </el-table>
  27. <el-pagination
  28. @size-change="sizeChangeHandle"
  29. @current-change="currentChangeHandle"
  30. :current-page="pageIndex"
  31. :page-sizes="[10, 20, 50, 100]"
  32. :page-size="pageSize"
  33. :total="totalPage"
  34. layout="total, sizes, prev, pager, next, jumper"
  35. ></el-pagination>
  36. </div>
  37. <div slot="footer" class="dialog-footer">
  38. <el-button @click="innerVisible = false">取 消</el-button>
  39. <el-button type="primary" @click="submitAddRealtion">确认新增</el-button>
  40. </div>
  41. </el-dialog>
  42. <el-row>
  43. <el-col :span="24">
  44. <el-button type="primary" @click="addRelation">新建关联</el-button>
  45. <el-button
  46. type="danger"
  47. @click="batchDeleteRelation"
  48. :disabled="dataListSelections.length <= 0"
  49. >批量删除
  50. </el-button>
  51. <!-- -->
  52. <el-table
  53. :data="relationAttrs"
  54. style="width: 100%"
  55. @selection-change="selectionChangeHandle"
  56. border
  57. >
  58. <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
  59. <el-table-column prop="attrId" label="#"></el-table-column>
  60. <el-table-column prop="attrName" label="属性名"></el-table-column>
  61. <el-table-column prop="valueSelect" label="可选值">
  62. <template slot-scope="scope">
  63. <el-tooltip placement="top">
  64. <div slot="content">
  65. <span v-for="(i,index) in scope.row.valueSelect.split(';')" :key="index">
  66. {{ i }}
  67. <br/>
  68. </span>
  69. </div>
  70. <el-tag>{{ scope.row.valueSelect.split(";")[0] + " ..." }}</el-tag>
  71. </el-tooltip>
  72. </template>
  73. </el-table-column>
  74. <el-table-column fixed="right" header-align="center" align="center" label="操作">
  75. <template slot-scope="scope">
  76. <el-button type="text" size="small" @click="relationRemove(scope.row.attrId)">移除</el-button>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. </el-col>
  81. </el-row>
  82. </el-dialog>
  83. </div>
  84. </template>
  85. <script>
  86. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  87. //例如:import 《组件名称》 from '《组件路径》';
  88. export default {
  89. //import引入的组件需要注入到对象中才能使用
  90. components: {},
  91. props: {},
  92. data() {
  93. //这里存放数据
  94. return {
  95. attrGroupId: 0,
  96. visible: false,
  97. innerVisible: false,
  98. relationAttrs: [],
  99. dataListSelections: [],
  100. dataForm: {
  101. key: ""
  102. },
  103. dataList: [],
  104. pageIndex: 1,
  105. pageSize: 10,
  106. totalPage: 0,
  107. dataListLoading: false,
  108. innerdataListSelections: []
  109. };
  110. },
  111. //计算属性 类似于data概念
  112. computed: {},
  113. //监控data中的数据变化
  114. watch: {},
  115. //方法集合
  116. methods: {
  117. selectionChangeHandle(val) {
  118. this.dataListSelections = val;
  119. },
  120. innerSelectionChangeHandle(val) {
  121. this.innerdataListSelections = val;
  122. },
  123. addRelation() {
  124. this.getDataList();
  125. this.innerVisible = true;
  126. },
  127. batchDeleteRelation(val) {
  128. let postData = [];
  129. this.dataListSelections.forEach(item => {
  130. postData.push({attrId: item.attrId, attrGroupId: this.attrGroupId});
  131. });
  132. this.$http({
  133. url: this.$http.adornUrl("/product/attrgroup/attr/relation/delete"),
  134. method: "post",
  135. data: this.$http.adornData(postData, false)
  136. }).then(({data}) => {
  137. if (data.code == 0) {
  138. this.$message({type: "success", message: "删除成功"});
  139. this.init(this.attrGroupId);
  140. } else {
  141. this.$message({type: "error", message: data.msg});
  142. }
  143. });
  144. },
  145. //移除关联
  146. relationRemove(attrId) {
  147. let data = [];
  148. data.push({attrId, attrGroupId: this.attrGroupId});
  149. this.$http({
  150. url: this.$http.adornUrl("/product/attrgroup/attr/relation/delete"),
  151. method: "post",
  152. data: this.$http.adornData(data, false)
  153. }).then(({data}) => {
  154. if (data.code == 0) {
  155. this.$message({type: "success", message: "删除成功"});
  156. this.init(this.attrGroupId);
  157. } else {
  158. this.$message({type: "error", message: data.msg});
  159. }
  160. });
  161. },
  162. submitAddRealtion() {
  163. this.innerVisible = false;
  164. //准备数据
  165. console.log("准备新增的数据", this.innerdataListSelections);
  166. if (this.innerdataListSelections.length > 0) {
  167. let postData = [];
  168. this.innerdataListSelections.forEach(item => {
  169. postData.push({attrId: item.attrId, attrGroupId: this.attrGroupId});
  170. });
  171. this.$http({
  172. url: this.$http.adornUrl("/product/attrgroup/attr/relation"),
  173. method: "post",
  174. data: this.$http.adornData(postData, false)
  175. }).then(({data}) => {
  176. if (data.code == 0) {
  177. this.$message({type: "success", message: "新增关联成功"});
  178. }
  179. this.$emit("refreshData");
  180. this.init(this.attrGroupId);
  181. });
  182. } else {
  183. }
  184. },
  185. init(id) {
  186. this.attrGroupId = id || 0;
  187. this.visible = true;
  188. this.$http({
  189. url: this.$http.adornUrl(
  190. "/product/attrgroup/" + this.attrGroupId + "/attr/relation"
  191. ),
  192. method: "get",
  193. params: this.$http.adornParams({})
  194. }).then(({data}) => {
  195. this.relationAttrs = data.data;
  196. });
  197. },
  198. dialogClose() {
  199. },
  200. //========
  201. // 获取数据列表
  202. getDataList() {
  203. this.dataListLoading = true;
  204. this.$http({
  205. url: this.$http.adornUrl(
  206. "/product/attrgroup/" + this.attrGroupId + "/noattr/relation"
  207. ),
  208. method: "get",
  209. params: this.$http.adornParams({
  210. page: this.pageIndex,
  211. limit: this.pageSize,
  212. key: this.dataForm.key
  213. })
  214. }).then(({data}) => {
  215. if (data && data.code === 0) {
  216. this.dataList = data.page.list;
  217. this.totalPage = data.page.totalCount;
  218. } else {
  219. this.dataList = [];
  220. this.totalPage = 0;
  221. }
  222. this.dataListLoading = false;
  223. });
  224. },
  225. // 每页数
  226. sizeChangeHandle(val) {
  227. this.pageSize = val;
  228. this.pageIndex = 1;
  229. this.getDataList();
  230. },
  231. // 当前页
  232. currentChangeHandle(val) {
  233. this.pageIndex = val;
  234. this.getDataList();
  235. }
  236. }
  237. };
  238. </script>
  239. <style scoped>
  240. </style>