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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<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="adName" show-overflow-tooltip width="180px">
        </el-table-column>
        <el-table-column label="广告编号" prop="adId" width="100px"></el-table-column>
        <el-table-column label="所属页面" show-overflow-tooltip width="120px">
          <template slot-scope="scope">
            {{ scope.row.pageId | filtterPage(pageList) }}
          </template>
        </el-table-column>
        <el-table-column label="所属栏目" prop="columnId" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.columnId | filtterColumnId(programList) }}
          </template>
        </el-table-column>
        <el-table-column label="图片" align="center">
          <template slot-scope="scope">
            <product-img :imgUrl="scope.row.adImgUrl"></product-img>
          </template>
        </el-table-column>
        <el-table-column label="链接目标" prop="adHrefUrl" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.adHrefUrl ? scope.row.adHrefUrl : '-'}}
          </template>
        </el-table-column>
        <el-table-column label="发布起止时间" width="300px">
          <template slot-scope="scope">
            {{scope.row.publishedOn}} - {{scope.row.closeTon}}
          </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" v-if="addDaligVis" width="55%">
      <common-form labelWidth="120px" :inline="inline" :form="addForm" ref="form"
                   :formLabel="addFormLabel" :defaultStyle="true" :formRules="formRules"
                   defaultPadding="0">
        <template slot="otherElement">
          <el-col :span="24" :offset="0">
            <el-form-item label="品牌图片:" prop="age" labelWidth="120px">
              <upload-img :limitNumber="1" :isAppendTobody="true" @handle-success="handleSuccess"
                          @handle-remove="handleRemove" :fileList="fileList" :imgSize="true">
              </upload-img>
            </el-form-item>
          </el-col>
        </template>
      </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 AdvertisingContentApi from '@/api/marketing/contentMgt'
import AdvertisingPageApi from '@/api/marketing/pageMgt'
import AdvertisingProgramApi from '@/api/marketing/programMgt'
import productImg from '@/views/product/components/productImg.vue'
export default {
  name: 'ContentMgt',
  components: { productImg },
  data() {
    const inputNumberValid = (rule, value, callback) => {
      const reg = /^[0-9]*$/ // 只能输入正整数
      if (value < 1 || !reg.test(value)) {
        callback(new Error('请输入1-99999之间的正整数'))
      } else {
        callback()
      }
    }
    return {
      fileList: [], // 图片数组集合
      pageList: [],
      programList: [],
      inline: false,
      addDaligVis: false,
      addBtnLoading: false,
      tableData: [],
      total: 0,
      listQuery: {
        adName: null,
        pageId: null,
        columnId: null
      },
      title: null,
      formLabel: [
        {
          model: 'adName',
          label: '广告名称',
          type: 'input'
        },
        {
          model: 'pageId',
          label: '所属页面',
          type: 'select',
          opts: []
        },
        {
          model: 'columnId',
          label: '所属栏目',
          type: 'select',
          opts: []
        }
      ],
      addForm: {},
      addFormLabel: [
        {
          model: 'adName',
          label: '广告名称',
          type: 'input',
          sx: 24,
          sm: 12
        },
        {
          model: 'adId',
          label: '广告编号',
          type: 'number',
          disabled: null,
          sx: 24,
          sm: 12
        },
        // {
        //   model: 'adType',
        //   label: '广告类型',
        //   type: 'select',
        //   opts: [
        //     {
        //       id: 'a',
        //       name: '图片'
        //     },
        //     {
        //       id: 'c',
        //       name: '文字'
        //     }
        //   ]
        // },
        {
          model: 'adHrefUrl',
          label: '链接目标',
          type: 'input',
          sx: 24,
          sm: 12
        },
        {
          model: 'adContent',
          label: '广告内容',
          type: 'input',
          sx: 24,
          sm: 12
        },
        {
          model: 'adDesc',
          label: '广告描述',
          type: 'input',
          sx: 24,
          sm: 12
        },
        {
          model: 'seqNum',
          label: '位置序号',
          type: 'number',
          sx: 24,
          sm: 12
        },
        {
          model: 'publisheTime',
          label: '发布起止时间',
          flag: 'datetimerange',
          type: 'date',
          sx: 24,
          sm: 12
        },
        {
          model: 'pageId',
          label: '所属页面',
          type: 'select',
          opts: [],
          sx: 24,
          sm: 12
        },
        {
          model: 'columnId',
          label: '所属栏目',
          type: 'select',
          opts: [],
          sx: 24,
          sm: 12,
        }
      ],
      formRules: {
        adName: [
          { required: true, message: '请输入广告名称' },
          { max: 100, message: '广告名称最多只能输入 100 个字' }
        ],
        adId: [
          { required: true, message: '请输入广告编号' },
          { validator: inputNumberValid }
        ],
        adType: [{ required: true, message: '请选择广告类型' }],
        adHrefUrl: [
          { max: 500, message: '链接目标最多只能输入 500 个字' }
        ],
        adDesc: [
          { max: 255, message: '广告描述最多只能输入 255 个字' }
        ],
        seqNum: [{ required: true, message: '请输入位置序号' }],
        pageDesc: [
          { max: 100, message: '页面描述最多只能输入 100 个字' }
        ],
        columnId: [{ required: true, message: '请选择所属栏目' }],
        pageId: [{ required: true, message: '请选择所属页面' }],
        publisheTime: [
          {
            type: 'array',
            required: true,
            message: '请选择发布起止时间'
          }
        ]
      }
    }
  },
  /**
   * 数据变化后刷新列表
   */
  activated() {
    this.queryList(this.$refs.table.getPageInfo())
    this.getPageList() // 获取页面信息
    this.getProgram() // 获取栏目信息
  },
  methods: {
    /**
         * 新增
         */
    addItem() {
      this.edit = false
      this.addDaligVis = true
      this.title = '新增'
      this.addFormLabel[1].disabled = false
      this.intiForm()
    },
    /**
         * 清空表单数据
         */
    intiForm() {
      for (const key in this.addForm) {
        this.addForm[key] = null
      }
      this.$set(this.addForm, 'publisheTime', [])
      this.fileList = []
    },
    handleSuccess(data) {
      this.addForm.adImgUrl = data.like
    },
    handleRemove(data) {
      this.addForm.adImgUrl = null
    },
    getPageList() {
      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
              }
            })
            this.formLabel.map((item) => {
              if (item.model === 'pageId') {
                item.opts = arr
              }
            })
          }
        }
      )
    },
    getProgram() {
      AdvertisingProgramApi.getList({
        pageSize: 1000000,
        param: {}
      }).then((res) => {
        if (res.data) {
          this.programList = res.data.list
          var arr = []
          this.programList.map((v) => {
            var obj = {
              id: v.columnId,
              name: v.columnName
            }
            arr.push(obj)
          })
          this.addFormLabel.map((item) => {
            if (item.model === 'columnId') {
              item.opts = arr
            }
          })
          this.formLabel.map((item) => {
            if (item.model === 'columnId') {
              item.opts = arr
            }
          })
        }
      })
    },
    /**
         *删除
         */
    delitem(row, index) {
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          AdvertisingContentApi.del({ AdId: row.adId }).then(
            (res) => {
              if (res.code === '0') {
                this.queryData()
              }
            }
          )
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    /**
         * 修改
         */
    updateItem(row, index) {
      this.fileList = []
      this.edit = true
      this.addDaligVis = true
      this.title = '编辑'
      this.addFormLabel[1].disabled = true
      row.publisheTime = []
      this.addForm = JSON.parse(JSON.stringify(row))
      this.addForm.publisheTime = [row.publishedOn, row.closeTon]
      if (this.addForm.adImgUrl) {
        this.fileList.push({
          url: this.addForm.adImgUrl
        })
      }
    },
    /**
         * '分页信息改变时查询列表
         */
    pageInfoChange(pageInfo) {
      this.queryList(pageInfo)
    },
    /**
         * 重置
         */
    resetQuery() {
      this.$refs.table.reloadCurrent()
    },
    /**
         * 点击查询按钮
         */
    queryData() {
      this.$refs.table.changeCondition()
    },
    /**
         * 查询列表
         */
    queryList(pageInfo = { pageNum: 1, pageSize: 10 }) {
      AdvertisingContentApi.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
        const { addForm, edit } = this
        if (addForm.publisheTime) {
          addForm.publishedOn = addForm.publisheTime[0]
          addForm.closeTon = addForm.publisheTime[1]
        }
        addForm.adType = 'a'
        if (edit) {
          AdvertisingContentApi.edit(addForm).then((res) => {
            this.addBtnLoading = false
            if (res.code === '0') {
              this.$message.success('操作成功')
              this.addDaligVis = false
              this.queryData()
            }
          })
        } else {
          AdvertisingContentApi.add(addForm).then((res) => {
            this.addBtnLoading = false
            if (res.code === '0') {
              this.$message.success('操作成功')
              this.addDaligVis = false
              this.queryData()
            }
          })
        }
      })
    }
  },
  filters: {
    filtterColumnId(val, list) {
      var name = ''
      list.map((v) => {
        if (v.columnId === val) {
          name = v.columnName
        }
      })
      return name
    },
    filtterPage(val, list) {
      var name = ''
      list.map((v) => {
        if (v.pageId === val) {
          name = v.pageName
        }
      })
      return name
    }
  }
}
</script>