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
<template>
  <div>
    <list-condition-template ref="table" :form="listQuery" :formLabel="formLabel"
                             :multipleSelected="true" :selectable="selecetInit" dataKey="id"
                             :tableData="tableData" :total="total" @selected="handSelected"
                             @page-info-change="handlePageInfoChange">
      <template slot="otherElement">
        <el-col :span="24" :offset="0" class="buttonPosition">
          <el-button size="mini" type="primary" @click="queryData">查询</el-button>
          <el-button size="mini" @click="resetQuery">重置</el-button>
        </el-col>
      </template>
      <template slot="operationSection">
        <el-button size="mini" type="success" @click="addItem">新增</el-button>
        <el-button size="mini" type="primary" @click="deleteItem">删除</el-button>
      </template>
      <template slot="columns">
        <el-table-column label="套餐编码" prop="code" show-overflow-tooltip></el-table-column>
        <el-table-column label="套餐名称" prop="name" show-overflow-tooltip></el-table-column>
        <el-table-column label="适用渠道" prop="belongSource" show-overflow-tooltip>
          <template slot-scope="scope">
            {{getLabel(applicableChannels,scope.row.belongSource)}}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" width="180px">
          <template slot-scope="scope">
            <span>{{scope.row.createTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="修改时间" width="180px">
          <template slot-scope="scope">
            <span>{{scope.row.updateTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status" width="150px">
          <template slot-scope="scope">
            <span class="statusTag"
                  :style="{ background: scope.row.status === '10' ? '#52c41a' :'#f5222d'}"></span>
            <span>{{scope.row.status === '10' ? '启用' : '停用'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" :width="`${3 * $store.getters.colSize}px`">
          <template slot-scope="scope">
            <wly-btn v-if="scope.row.status !== '10'" :type="'primary'"
                     @click="editItem(scope.row,scope.$index)">编辑</wly-btn>
            <wly-btn @click="detailsInfo(scope.row,scope.$index)">详情</wly-btn>
            <wly-btn :type="scope.row.status === '10' ? 'warning' : 'success'"
                     @click="updateState(scope.row,scope.$index)">
              {{scope.row.status === '10' ? '停用' : '启用'}}</wly-btn>
          </template>
        </el-table-column>
      </template>
    </list-condition-template>
  </div>
</template>
<script>
import platformPackageApi from '@/api/platformPackage'
import applicableChannels from '@/utils/constant/orderSourceArr'
import { getArrayLable } from '@/utils/getArrayLable'
 
export default {
  data () {
    return {
      applicableChannels,
      tableData: [],
      total: 0,
      listQuery: {
        name: null,
        codeLike: null,
        belongSource: null,
        status: null,
        startDate: null,
        endDate: null
      },
      formLabel: [
        {
          model: 'codeLike',
          label: '套餐编码',
          type: 'input',
          rule: /[^\w]/g // 可输入数字字母
        },
        {
          model: 'name',
          label: '套餐名称',
          type: 'input'
        },
        {
          model: 'belongSource',
          label: '适用渠道',
          type: 'select',
          opts: applicableChannels
        },
        {
          model: 'status',
          label: '状态',
          type: 'select',
          opts: [
            {
              id: '10',
              name: '启用'
            },
            {
              id: '00',
              name: '停用'
            }
          ]
        }
        // {
        //   model: 'startDate',
        //   label: '创建时间',
        //   type: 'date',
        //   pickerOptions: {
        //     disabledDate: (time) => {
        //       return this.listQuery.endDate && time.getTime() >= new Date(this.listQuery.endDate).getTime() + 86400000
        //     }
        //   }
        // },
        // {
        //   model: 'endDate',
        //   label: '-',
        //   type: 'date',
        //   pickerOptions: {
        //     disabledDate: (time) => {
        //       return this.listQuery.startDate && time.getTime() <= new Date(this.listQuery.startDate).getTime() - 86400000
        //     }
        //   }
        // }
      ],
      rows: []
    }
  },
  /*
     * 数据变化后刷新列表
   */
  activated () {
    this.queryList(this.$refs.table.getPageInfo())
  },
  methods: {
    /**
     * 获取数组的label
     */
    getLabel (array, id) {
      let str = ''
      id.split(',').forEach((item, index, arr) => {
        const endTag = arr.length !== index + 1 ? ',' : ''
        str += getArrayLable(array, item) + endTag
      })
      return str
    },
    /**
     * 初始化表格
     */
    initTable () {
      this.$refs.table.reloadCurrent()
      this.rows = []
    },
    /**
     * 批量删除
     */
    async deleteItem () {
      if (!this.rows.length) {
        this.$message({
          message: '请选择需要删除的数据',
          type: 'info'
        })
        return
      }
      this.$confirm('确认删除数据吗?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        try {
          const ids = this.rows.map(item => item.id).join()
          console.log(ids)
          const res = await platformPackageApi.deleteItem({ ids })
          if (res.code === '0') {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.initTable()
          }
        } catch (error) {
        }
      }).catch(() => { })
    },
    /**
     *
     *获取勾选的表格数据
     */
    handSelected (val) {
      this.rows = val
    },
    /**
     * 初始化复选框
     */
    selecetInit (row, index) {
      if (row.status === '10') {
        return false // 不可勾选
      } else {
        return true // 可勾选
      }
    },
    /**
     * 启用/停用
     */
    async updateState (row, index) {
      console.log(row.status)
      if (row.status === '00') {
        this.enablePackage(row.id)
      } else if (row.status === '10') {
        this.disablePackage(row.id)
      }
    },
    /**
     * 启用
     */
    async enablePackage (id) {
      const res = await platformPackageApi.enableStatus(id)
      if (res.code === '0') {
        this.$message({
          message: '启用成功',
          type: 'success'
        })
        this.initTable()
      }
    },
    /**
     * 禁用
     */
    async disablePackage (id) {
      const res = await platformPackageApi.disabledStatus(id)
      if (res.code === '0') {
        this.$message({
          message: '禁用成功',
          type: 'success'
        })
        this.initTable()
      }
    },
    /**
     * 新增
     */
    addItem () {
      this.$router.push({ name: 'platformPgAdd' })
    },
    /**
     * 编辑
     */
    editItem (row, index) {
      this.$router.push({ name: 'platformPgEdit', query: { id: row.id } })
    },
    /**
     * 详情
     */
    detailsInfo (row, index) {
      this.$router.push({ name: 'platformPgInfo', query: { id: row.id } })
    },
    /**
       * '分页信息改变时查询列表
       */
    handlePageInfoChange (pageInfo) {
      this.queryList(pageInfo)
    },
 
    /**
     * 重置
     */
    resetQuery () {
      this.$refs.table.reloadCurrent()
    },
    /**
     * 点击查询按钮
     */
    queryData () {
      this.$refs.table.changeCondition()
    },
    /**
     * 查询列表
     */
    async queryList (pageInfo = { pageNum: 1, pageSize: 10 }) {
      try {
        const res = await platformPackageApi.getList({ ...this.listQuery, ...pageInfo })
        if (res.code === '0') {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      } catch (error) {
      }
    }
  }
}
</script>
<style lang="scss">
.statusTag {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
  position: relative;
  bottom: 2px;
}
</style>