zss
2023-12-01 e87aa5d7b6b44e36a7dfb3b0a705446d0fe55e2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!--
  -    Copyright (c) 2018-2025, ztt All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: ztt
  -->
 
  <template>
    <div class="app-container calendar-list-container">
      <basic-container>
        <avue-crud
          ref="crud"
          :option="tableOption"
          :data="list"
          :page="page"
          v-model="form"
          :table-loading="listLoading"
          @on-load="getList"
          @search-change="searchChange"
          @refresh-change="refreshChange"
          @size-change="sizeChange"
          @current-change="currentChange">
          <template slot="staffName" slot-scope="scope">{{ scope.row.staffName }}</template>
          <template slot="type" slot-scope="scope">{{ scope.row.type }}</template>
          <template slot="menuLeft">
            <el-button
              v-if="prodManager_btn_add"
              class="filter-item"
              type="primary"
              icon="el-icon-plus"
              @click="dialogAddVisible=true">添加</el-button>
          </template>
          <template slot="menu" slot-scope="scope">
              <el-button
                v-if="prodManager_btn_del"
                type="text"
                size="small"
                icon="el-icon-delete"
                @click="handleDelete(scope.row,scope.index)">删除
              </el-button>
          </template>
        </avue-crud>
      </basic-container>
      <el-dialog :visible.sync="dialogAddVisible" :close-on-click-modal="false" title="新增配置">
      <el-form :model="prodForm" :rules="rules" ref="addDialog">
        <el-form-item prop="staffName" label="用户名称:" label-width="90px">
            <el-select style="width:100%" v-model="prodForm.staffName" filterable placeholder="请选择">
              <el-option v-for="(item,index) in staffNamesOptions" :key="index" :value="item.id" :label="item.staffName"/>
            </el-select>
        </el-form-item>
        <el-form-item prop="type" label="关键字:" label-width="90px">
          <el-input style="width:100%" v-model="prodForm.type" placeholder="请输入隶属品牌关键字"/>
        </el-form-item>
      </el-form>
      <div slot="footer"
        class="dialog-footer">
        <el-button type="primary" size="small" @click="createConfirm">确 认</el-button>
        <el-button type="default" size="small" @click="reset">取消</el-button>
      </div>
    </el-dialog>
    </div>
  </template>
 
  <script>
  import { tableOption } from '@/const/crud/admin/productType'
  import { getList,addObj,delObj,chooseStaff } from '@/api/admin/productType'
  import { mapGetters } from 'vuex'
 
  export default {
    name: 'TableProduct',
    data() {
      return {
        dialogAddVisible: false,
        prodForm: {
          staffName: '',
          type: ''
        },
        rules: {
          staffName:[{ required:true,message:"用户名不能为空", trigger: 'change' }],
          type:[{required:true,message:"产品类型关键字不能为空", trigger: 'blur'}]
        },
        staffNamesOptions: [],
        tableOption: tableOption,
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20 // 每页显示多少条
        },
        list: [],
        listLoading: false,
        form: {},
        prodManager_btn_add: false,
        prodManager_btn_del: false,
      }
    },
    created() {
      this.prodManager_btn_add = this.permissions['sys_prod_add']
      this.prodManager_btn_del = this.permissions['sys_prod_del']
      this.getStaffList()
    },
    computed: {
      ...mapGetters(['elements', 'permissions'])
    },
    methods: {
      getStaffList(){
        chooseStaff(Object.assign({})).then(response => {
          this.staffNamesOptions = response.data.data
        })
      },
      getList(page, params) {
        this.listLoading = true
        getList(Object.assign({
          current: page.currentPage,
          size: page.pageSize
        }, params, this.searchForm)).then(response => {
          this.list = response.data.data
          this.page.total = response.data.data.total
          this.listLoading = false
        }).catch(() => {
          this.listLoading = false
        })
      },
      refreshChange() {
        this.getList(this.page)
      },
      searchChange(form, done) {
        this.searchForm = form
        this.page.currentPage = 1
        this.getList(this.page, form)
        done()
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize
      },
      currentChange(current){
        this.page.currentPage = current
      },
      handleCreate() {
        this.$refs.crud.rowAdd()
      },
      createConfirm(){
          this.$refs['addDialog'].validate(val=>{
            if(val){
              addObj({
                staffId: this.prodForm.staffName,
                productType: this.prodForm.type
              }).then(response => {
                this.dialogAddVisible = false
                this.$message.success("添加成功")
                this.refreshChange()
              }).catch(() => {
                this.$message.error("添加失败")
              })
            }
          })
      },
      reset(){
        this.dialogAddVisible =false;
        this.$refs['addDialog'].resetFields()
      },
      handleDelete(row, index) {
        this.$confirm('是否确认删除名称为"' + row.staffName + '"' + '"的数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          closeOnClickModal:false,
          type: 'warning'
        }).then(function() {
          return delObj(row.id)
        }).then(() => {
          this.getList(this.page)
          this.$notify.success('删除成功')
        })
      },
    }
  }
  </script>
 
  <style lang="scss" scoped>
    .el-dialog__wrapper {
    .el-dialog {
      width: 61% !important;
    .dialog-main-tree {
      max-height: 400px;
      overflow-y: auto;
    }
    }
    .el-form-item__label {
      width: 100px !important;
      padding-right: 20px;
    }
    .el-form-item__content {
      margin-left: 200px !important;
    }
    }
  </style>