fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<template>
  <div>
    <list-condition-template ref="table" :form="listQuery" :formLabel="formLabel"
                             :tableData="tableData" :total="total"
                             @page-info-change="pageInfoChange">
      <template slot="otherElement">
        <el-col :span="6" :offset="0">
          <el-form-item>
            <el-button size="mini" type="primary" @click="queryData">查询</el-button>
            <el-button size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </template>
      <template slot="operationSection">
        <el-button size="mini" type="success" @click="addItem">新增</el-button>
      </template>
      <template slot="columns">
        <!-- <el-table-column label="栏位类目编号" prop="columnId"></el-table-column> -->
        <el-table-column label="栏目名称" prop="columnName" show-overflow-tooltip></el-table-column>
        <el-table-column label="栏目编号" prop="columnId"></el-table-column>
        <el-table-column label="序列号" prop="seqNum"></el-table-column>
        <el-table-column label="所属页面" prop="pageId"></el-table-column>
        <el-table-column label="状态" width="100px">
          <template slot-scope="scope">
            <span class="statusTag"
                  :style="{ background: scope.row.columnStatus ==='0' ? '#f5222d' :'#52c41a'}"></span>
            <span>{{scope.row.columnStatus ==='0' ? '不可用' : '可用'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" :width="`${2 * $store.getters.colSize}px`">
          <template slot-scope="scope">
            <wly-btn type="primary" @click="updateItem(scope.row,scope.$index)">编辑</wly-btn>
            <wly-btn type="danger" @click="delitem(scope.row,scope.$index)">删除</wly-btn>
          </template>
        </el-table-column>
      </template>
    </list-condition-template>
    <el-dialog :title="title" :visible.sync="addDaligVis" :close-on-click-modal="false"
               :modal-append-to-body="false" width="50%" v-if="addDaligVis">
      <common-form labelWidth="120px" :inline="inline" :form="addForm" :defaultStyle="true"
                   ref="form" :formLabel="addFormLabel" :formRules="formRules" defaultPadding="0">
      </common-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="addBtnLoading" @click="confirmAdd" size="mini">保存
        </el-button>
        <el-button @click="addDaligVis = false" size="mini">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import AdvertisingProgramApi from '@/api/marketing/programMgt'
import AdvertisingPageApi from '@/api/marketing/pageMgt'
export default {
  name: 'ProgramMgt',
  data() {
    const inputNumberValid = (rule, value, callback) => {
      const reg = /^[0-9]*$/ // 只能输入正整数
      if (value < 1 || !reg.test(value)) {
        callback(new Error('请输入1-99999之间的正整数'))
      } else {
        callback()
      }
    }
    return {
      edit: false,
      title: null,
      addBtnLoading: false,
      pageList: [], // 页面信息
      inline: false,
      addDaligVis: false,
      tableData: [],
      total: 0,
      listQuery: {
        columnName: null,
        columnStatus: null
      },
      formLabel: [
        {
          model: 'columnName',
          label: '栏目名称',
          type: 'input'
        },
        {
          model: 'columnStatus',
          label: '栏目状态 ',
          type: 'select',
          opts: [
            {
              id: '1',
              name: '可用'
            },
            {
              id: '0',
              name: '不可用'
            }
          ]
        }
      ],
      addForm: {
        columnId: null,
        columnName: null,
        seqNum: null,
        columnStatus: '1',
        pageId: null,
        columnDesc: null
      },
      addFormLabel: [
        {
          model: 'columnId',
          label: '栏目编号',
          type: 'number',
          disabled: null,
          sx: 24,
          sm: 12
        },
        {
          model: 'columnName',
          label: ' 栏目名称',
          type: 'input',
          sx: 24,
          sm: 12
        },
        {
          model: 'seqNum',
          label: '序列号',
          type: 'number',
          sx: 24,
          sm: 12
        },
        {
          model: 'columnStatus',
          label: '状态',
          type: 'select',
          sx: 24,
          sm: 12,
          opts: [
            {
              id: '1',
              name: '可用'
            },
            {
              id: '0',
              name: '不可用'
            }
          ]
        },
        {
          model: 'pageId',
          label: '所属页面',
          type: 'select',
          sx: 24,
          sm: 12,
          opts: []
        },
        {
          model: 'columnDesc',
          label: '栏目描述',
          sx: 24,
          sm: 12,
          type: 'input'
        }
      ],
      formRules: {
        columnName: [
          { required: true, message: '请输入栏目名称' },
          { max: 60, message: '栏目名称最多只能输入 60 个字' }
        ],
        columnId: [
          { required: true, message: '请输入栏目编号' },
          { validator: inputNumberValid }
        ],
        seqNum: [
          { required: true, message: '请输入序列号' }
        ],
        columnStatus: [{ required: true, message: '请选择状态' }],
        pageId: [{ required: true, message: '请选择所属页面' }],
        columnDesc: [
          { max: 100, message: '栏目描述最多只能输入 100 个字' }
        ]
      }
    }
  },
  /**
   * 数据变化后刷新列表
   */
  activated() {
    this.queryList(this.$refs.table.getPageInfo())
    this.getPage() // 查询页面信息
  },
  methods: {
    /**
     * 新增
     */
    addItem() {
      this.addDaligVis = true
      this.edit = false
      this.title = '新增'
      this.addFormLabel[0].disabled = false
      this.intiForm()
    },
    /**
     * 清空表单数据
     */
    intiForm() {
      for (const key in this.addForm) {
        this.addForm[key] = null
      }
      this.addForm.columnStatus = '1'
    },
    getPage() {
      AdvertisingPageApi.getList({ pageSize: 1000000, param: {} }).then(
        (res) => {
          if (res.data) {
            this.pageList = res.data.list
            var arr = []
            this.pageList.map(v => {
              var obj = {
                id: v.pageId,
                name: v.pageName
              }
              arr.push(obj)
            })
            this.addFormLabel.map(item => {
              if (item.model === 'pageId') {
                item.opts = arr
              }
            })
          }
        }
      )
    },
    /**
     *删除
     */
    delitem(row, index) {
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        AdvertisingProgramApi.del({ columnId: row.columnId }).then(
          (res) => {
            if (res.code === '0') {
              this.queryData()
            }
          }
        )
      }).catch(() => {
      })
    },
    /**
     * 修改
     */
    updateItem(row, index) {
      this.edit = true
      this.addDaligVis = true
      this.title = '编辑'
      this.addFormLabel[0].disabled = true
      this.addForm = JSON.parse(JSON.stringify(row))
    },
    /**
     * '分页信息改变时查询列表
     */
    pageInfoChange(pageInfo) {
      this.queryList(pageInfo)
    },
    /**
     * 重置
     */
    resetQuery() {
      this.$refs.table.reloadCurrent()
    },
    /**
     * 点击查询按钮
     */
    queryData() {
      this.$refs.table.changeCondition()
    },
    /**
     * 查询列表
     */
    queryList(pageInfo = { pageNum: 1, pageSize: 10 }) {
      AdvertisingProgramApi.getList({ param: this.listQuery, ...pageInfo }).then(
        (res) => {
          if (res.data) {
            this.tableData = res.data.list
            this.total = res.data.total
          }
        }
      )
    },
    // 添加
    confirmAdd() {
      this.$refs.form.$refs.form.validate().then((res) => {
        this.addBtnLoading = true
        if (this.edit) {
          AdvertisingProgramApi.edit(this.addForm).then(
            (res) => {
              this.edit = false
              this.addBtnLoading = false
              if (res.code === '0') {
                this.$message.success('操作成功')
                this.addDaligVis = false
                this.queryData()
              }
            }
          )
        } else {
          AdvertisingProgramApi.add(this.addForm).then(
            (res) => {
              this.addBtnLoading = false
              if (res.code === '0') {
                this.$message.success('操作成功')
                this.addDaligVis = false
                this.queryData()
              }
            }
          )
        }
      })
    }
  }
}
</script>