gjj
2023-02-07 08690e2fd123a710406a101a2a5bd98fa0992502
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
<template>
  <div class='subscription'>
    <c-r-m-list-head
      ref="listHead"
      title="订阅"
      main-title="PWS API" />
    <el-form :inline="true" :model="headObj" class="selectInline">
      <el-form-item>
          <span>开始时间:</span>
          <el-date-picker
            v-model="headObj.startDateSince"
            type="date"
            placeholder="选择开始日期"
            value-format="yyyy-MM-dd"
            :picker-options="pickerOptions">
          </el-date-picker>
      </el-form-item>
      <el-form-item>
          <span>截止时间:</span>
          <el-date-picker
            v-model="headObj.lastModifiedSince"
            type="date"
            placeholder="选择最后修改日期"
            value-format="yyyy-MM-dd"
            :picker-options="pickerOptions">
          </el-date-picker>
      </el-form-item>
      <!-- <el-form-item>
        <div style='display: flex;'>
          <span style="margin-right: 12px">状态:</span>
          <el-checkbox-group v-model="headObj.subscriptionStatus" style="display: flex; align-items: center;">
            <el-checkbox label="活动"></el-checkbox>
            <el-checkbox label="非活动"></el-checkbox>
            <el-checkbox label="已过期"></el-checkbox>
          </el-checkbox-group>
        </div>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="onSubmit('query')">新建导出任务</el-button>
        <el-button @click="onSubmit('reset')">重置</el-button>
      </el-form-item>
    </el-form>
    <el-card class="el-card">
      <el-table
        v-loading="loading"
        id="crm-table"
        :data="tableData"
        :height="tableHeight"
        :cell-style="cellStyle"
        class="n-table--border"
        border
        highlight-current-row
        style="width: 100%"
        @row-click="rowClick">
        <el-table-column
          v-for="(item, index) in fieldList"
          :key="index"
          :prop="item.field"
          :label="item.name"
          :formatter="fieldFormatter"
          show-overflow-tooltip>
          <template
            slot="header"
            slot-scope="scope">
            <div class="table-head-name">{{ scope.column.label }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="operation">
          <template
            title="hhhhhhhhh"
            slot="header"
            slot-scope="scope">
            <div class="table-head-name">操作</div>
          </template>
          <template slot-scope="scope">
            <span v-if="scope.row.TaskStatus === 0" style="font-size: 12px; color: #909398; font-weight: 500;">等待处理</span>
            <span v-else-if="scope.row.TaskStatus === 1" style="font-size: 12px; color: #80BF50; font-weight: 500;">正在处理</span>
            <span v-else-if="scope.row.TaskStatus === 2" style="font-size: 12px; color: #5B88F7; font-weight: 500;">导出完成</span>
            <span v-else-if="scope.row.TaskStatus === 3" style="font-size: 12px; color: #DBA450; font-weight: 500;">导出失败</span>
            <el-button style="margin-left: 12px" v-if="scope.row.TaskStatus === 2" size="mini" type="primary"  @click='exportFile(scope.row)'>导出</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="p-contianer" v-if='total>0'>
        <el-pagination
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size.sync="pageSize"
          :total="total"
          class="p-bar"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
    <c-r-m-export
      :show="showCRMExport"
      :crm-type="crmType"
      :head-obj="exportHeadObj"
      @close="showCRMExport=false"
      @queryList='queryList'/>
  </div>
</template>
 
<script>
import { ExportSubscriptionsTask, GetSubscriptionsTask } from '@/api/pwsApi/subscriptions'
import CRMListHead from '../clients/components/CRMListHead'
import CRMExport from '../clients/components/CRMExport'
export default {
  name: 'Subscriptions',
  components: {
    CRMListHead,
    CRMExport
  },
  data () {
    return {
      loading: false,
      currentPage: 1,
      // Lockr.get('crmPageSizes')
      pageSize: 10,
      pageSizes: [10, 30, 60, 100],
      total: 0,
      tableData: [],
      tableHeight: document.documentElement.clientHeight - 360, // 表的高度
      fieldList: [
        { name: 'CreateTime', field: 'CreateTime', formType: 'text' },
        { name: 'StartDateSince', field: 'StartDateSince', formType: 'text' },
        { name: 'LastModifiedSince', field: 'LastModifiedSince', formType: 'text' }
        // { name: '状态', field: 'SubscriptionStatus', formType: 'text' }
      ],
      // 导出
      showCRMExport: false,
      crmType: 'subscriptions',
      headObj: {
        startDateSince: '',
        lastModifiedSince: '',
        subscriptionStatus: []
      },
      exportHeadObj: {
        taskId: ''
      },
      pickerOptions: {
        disabledDate (time) {
          return time.getTime(new Date()) > Date.now()
        }
      }
    }
  },
  mounted () {
    var self = this
    /** 控制table的高度 */
    window.onresize = () => {
      self.updateTableHeight()
    }
    this.getList()
  },
  methods: {
    getList () {
      this.loading = true
      let params = {
        'PageIndex': this.currentPage,
        'PageSize': this.pageSize
      }
      GetSubscriptionsTask(params)
        .then(res => {
          if (res.data.ErrorCode === 200) {
            if (res.data.Result.Count > 0) {
              this.tableData = res.data.Result.List
            } else {
              this.tableData = []
            }
            this.total = res.data.Result.Count
            this.loading = false
          } else {
            this.$message.error(res.data.Message)
            this.loading = false
          }
        })
        .catch(() => {
          this.loading = false
        })
    },
    // 更改每页展示数量
    handleSizeChange (val) {
      // Lockr.set('crmPageSizes', val)
      this.pageSize = val
      this.getList()
    },
    // 更改当前页数
    handleCurrentChange (val) {
      this.currentPage = val
      this.getList()
    },
    updateTableHeight () {
      var offsetHei = document.documentElement.clientHeight
      // var removeHeight = Object.keys(this.filterObj).length > 0 ? 310 : 240
      var removeHeight = 240
      this.tableHeight = offsetHei - removeHeight
    },
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      return { textAlign: 'left' }
    },
    rowClick (row, column, event) {
    },
    queryList (data) {
      console.log(data)
    },
    // 列表信息格式化
    fieldFormatter (row, column) {
      if (column.property === 'Status') {
        switch (row[column.property]) {
          case true:
            row[column.property] = '是'
            break
          case false:
            row[column.property] = '否'
            break
        }
      }
      return row[column.property] || '--'
    },
    onSubmit (val) {
      if (val === 'query') {
        if (this.headObj.startDateSince === '') {
          this.$message.error('请选择导出任务的开始时间')
          return
        }
        this.loading = true
        // let status = ''
        // this.headObj.subscriptionStatus.forEach((item) => {
        //   if (status === '') {
        //     status = item
        //   } else {
        //     status = status + ',' + item
        //   }
        // })
        // this.headObj.subscriptionStatus = status
        let params
        if (this.headObj.lastModifiedSince === '') {
          params = {
            startDateSince: this.headObj.startDateSince
          }
        } else {
          params = {
            startDateSince: this.headObj.startDateSince,
            lastModifiedSince: this.headObj.lastModifiedSince
          }
        }
        ExportSubscriptionsTask(params)
          .then(res => {
            if (res.data.ErrorCode === 200) {
              this.loading = false
              this.getList()
            } else {
              this.$message.error(res.data.Message)
              this.loading = false
            }
          })
          .catch(() => {
            this.loading = false
          })
      } else if (val === 'reset') {
        this.headObj = {}
      }
    },
    exportFile (item) {
      console.log(item)
      this.exportHeadObj.taskId = item.Id
      // 需要设置参数 this.headObj
      this.showCRMExport = true
    }
  }
}
</script>
 
<style lang="scss" scoped>
@import '../clients/styles/table.scss';
.subscription {
  display: flex;
  flex-direction: column;
  .flex-box {
    flex: 1;
    padding: 20px;
    border-radius: 4px;
    border: 1px solid #EBEEF5;
    background-color: #FFF;
    overflow: hidden;
    color: #303133;
 
  }
}
.selectInline{
  background: #fff;
  padding:20px 20px 0;
  margin-bottom: 10px;
}
.datePicker{
  margin-top:3px;
  .el-date-editor .el-range__icon{
     line-height: 28px;
  }
}
/** 分页布局 */
.p-contianer {
  position: relative;
  background-color: white;
  height: 44px;
  .p-bar {
    float: right;
    margin: 5px 0 0 0;
    font-size: 14px !important;
  }
}
</style>