index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template> 
  2. <div class="app-container">
  3. <el-card class="operate-container" shadow="never">
  4. <i class="el-icon-tickets" style="margin-top: 5px"></i>
  5. <span style="margin-top: 5px">数据列表</span>
  6. <el-button
  7. class="btn-add"
  8. @click="addProductAttrCate()"
  9. size="mini">
  10. 添加
  11. </el-button>
  12. </el-card>
  13. <div class="table-container">
  14. <el-table ref="productAttrCateTable"
  15. style="width: 100%"
  16. :data="list"
  17. v-loading="listLoading"
  18. border>
  19. <el-table-column label="编号" width="100" align="center">
  20. <template slot-scope="scope">{{scope.row.id}}</template>
  21. </el-table-column>
  22. <el-table-column label="类型名称" align="center">
  23. <template slot-scope="scope">{{scope.row.name}}</template>
  24. </el-table-column>
  25. <el-table-column label="属性数量" width="200" align="center">
  26. <template slot-scope="scope">{{scope.row.attributeCount==null?0:scope.row.attributeCount}}</template>
  27. </el-table-column>
  28. <el-table-column label="参数数量" width="200" align="center">
  29. <template slot-scope="scope">{{scope.row.paramCount==null?0:scope.row.paramCount}}</template>
  30. </el-table-column>
  31. <el-table-column label="设置" width="200" align="center">
  32. <template slot-scope="scope">
  33. <el-button
  34. size="mini"
  35. @click="getAttrList(scope.$index, scope.row)">属性列表
  36. </el-button>
  37. <el-button
  38. size="mini"
  39. @click="getParamList(scope.$index, scope.row)">参数列表
  40. </el-button>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="操作" width="200" align="center">
  44. <template slot-scope="scope">
  45. <el-button
  46. size="mini"
  47. @click="handleUpdate(scope.$index, scope.row)">编辑
  48. </el-button>
  49. <el-button
  50. size="mini"
  51. type="danger"
  52. @click="handleDelete(scope.$index, scope.row)">删除
  53. </el-button>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. </div>
  58. <div class="pagination-container">
  59. <el-pagination
  60. background
  61. @size-change="handleSizeChange"
  62. @current-change="handleCurrentChange"
  63. layout="total, sizes,prev, pager, next,jumper"
  64. :page-size="listQuery.pageSize"
  65. :page-sizes="[5,10,15]"
  66. :current-page.sync="listQuery.pageNum"
  67. :total="total">
  68. </el-pagination>
  69. </div>
  70. <el-dialog
  71. :title="dialogTitle"
  72. :visible.sync="dialogVisible"
  73. :before-close="handleClose()"
  74. width="30%">
  75. <el-form ref="productAttrCatForm" :model="productAttrCate" :rules="rules" label-width="120px">
  76. <el-form-item label="类型名称" prop="name">
  77. <el-input v-model="productAttrCate.name" auto-complete="off"></el-input>
  78. </el-form-item>
  79. </el-form>
  80. <span slot="footer" class="dialog-footer">
  81. <el-button @click="dialogVisible = false">取 消</el-button>
  82. <el-button type="primary" @click="handleConfirm('productAttrCatForm')">确 定</el-button>
  83. </span>
  84. </el-dialog>
  85. </div>
  86. </template>
  87. <script>
  88. import {fetchList,createProductAttrCate,deleteProductAttrCate,updateProductAttrCate} from '@/api/productAttrCate'
  89. export default {
  90. name: 'productAttrCateList',
  91. data() {
  92. return {
  93. list: null,
  94. total: null,
  95. listLoading: true,
  96. listQuery: {
  97. pageNum: 1,
  98. pageSize: 5
  99. },
  100. dialogVisible: false,
  101. dialogTitle:'',
  102. productAttrCate:{
  103. name:'',
  104. id:null
  105. },
  106. rules: {
  107. name: [
  108. { required: true, message: '请输入类型名称', trigger: 'blur' }
  109. ]
  110. }
  111. }
  112. },
  113. created() {
  114. this.getList();
  115. },
  116. methods: {
  117. getList() {
  118. this.listLoading = true;
  119. fetchList(this.listQuery).then(response => {
  120. this.listLoading = false;
  121. this.list = response.data.list;
  122. this.total = response.data.total;
  123. });
  124. },
  125. addProductAttrCate() {
  126. this.dialogVisible = true;
  127. this.dialogTitle = "添加类型";
  128. },
  129. handleSizeChange(val) {
  130. this.listQuery.pageNum = 1;
  131. this.listQuery.pageSize = val;
  132. this.getList();
  133. },
  134. handleCurrentChange(val) {
  135. this.listQuery.pageNum = val;
  136. this.getList();
  137. },
  138. handleDelete(index, row) {
  139. this.$confirm('是否要删除该品牌', '提示', {
  140. confirmButtonText: '确定',
  141. cancelButtonText: '取消',
  142. type: 'warning'
  143. }).then(() => {
  144. deleteProductAttrCate(row.id).then(response=>{
  145. this.$message({
  146. message: '删除成功',
  147. type: 'success',
  148. duration:1000
  149. });
  150. this.getList();
  151. });
  152. });
  153. },
  154. handleUpdate(index, row) {
  155. this.dialogVisible = true;
  156. this.dialogTitle = "编辑类型";
  157. this.productAttrCate.name = row.name;
  158. this.productAttrCate.id = row.id;
  159. },
  160. getAttrList(index, row) {
  161. this.$router.push({path: '/pms/productAttrList',query:{cid:row.id,cname:row.name,type:0}})
  162. },
  163. getParamList(index, row) {
  164. this.$router.push({path: '/pms/productAttrList',query:{cid:row.id,cname:row.name,type:1}})
  165. },
  166. handleConfirm(formName){
  167. this.$refs[formName].validate((valid) => {
  168. if (valid) {
  169. let data = new URLSearchParams();
  170. data.append("name",this.productAttrCate.name);
  171. let obj = {
  172. name:this.productAttrCate.name
  173. }
  174. if(this.dialogTitle==="添加类型"){
  175. createProductAttrCate(obj).then(response=>{
  176. this.$message({
  177. message: '添加成功',
  178. type: 'success',
  179. duration:1000
  180. });
  181. this.dialogVisible = false;
  182. this.productAttrCate.name = ''
  183. this.getList();
  184. });
  185. }else{
  186. updateProductAttrCate(this.productAttrCate.id,obj).then(response=>{
  187. this.$message({
  188. message: '修改成功',
  189. type: 'success',
  190. duration:1000
  191. });
  192. this.productAttrCate.name = ''
  193. this.dialogVisible = false;
  194. this.getList();
  195. });
  196. }
  197. } else {
  198. console.log('error submit!!');
  199. this.productAttrCate.name = ''
  200. return false;
  201. }
  202. });
  203. },
  204. handleClose(){
  205. if (!this.dialogVisible && this.$refs.productAttrCatForm) {
  206. this.$refs.productAttrCatForm.clearValidate()
  207. this.productAttrCate.name = ''
  208. }
  209. }
  210. }
  211. }
  212. </script>
  213. <style rel="stylesheet/scss" lang="scss" scoped>
  214. </style>