index.vue 14.7 KB
Newer Older
1 2 3 4 5
<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
Marcus's avatar
Marcus committed
6 7
      <!-- <el-form-item :label="$t('标题')" prop="titleZh">
        <el-input v-model="queryParams.titleZh" :placeholder="$t('请输入标题')" clearable @keyup.enter.native="handleQuery"/>
dragondean@qq.com's avatar
dragondean@qq.com committed
8
      </el-form-item> -->
Marcus's avatar
Marcus committed
9 10
      <!-- <el-form-item :label="$t('标题')" prop="titleEn">
        <el-input v-model="queryParams.titleEn" :placeholder="$t('请输入标题')" clearable @keyup.enter.native="handleQuery"/>
11
      </el-form-item> -->
Marcus's avatar
Marcus committed
12
      <el-form-item :label="$t('类型')" prop="type">
dragondean@qq.com's avatar
dragondean@qq.com committed
13
        <dict-selector :type='DICT_TYPE.ECW_COUPON_TYPE' v-model="queryParams.type" clearable />
14
      </el-form-item>
Marcus's avatar
Marcus committed
15
      <el-form-item :label="$t('状态')" prop="status" clearable>
dragondean@qq.com's avatar
dragondean@qq.com committed
16
        <!-- <dict-selector :type="DICT_TYPE.ECW_COUPON_STATUS" v-model="queryParams.status"/> -->
Marcus's avatar
Marcus committed
17 18 19 20
        <el-select v-model="queryParams.status" :placeholder="$t('请选择')" clearable size="small">
          <el-option :label="$t('草稿')" value="0" />
          <el-option :label="$t('已发布')" value="1" />
          <el-option :label="$t('已过期')" value="2" />
dragondean@qq.com's avatar
dragondean@qq.com committed
21
        </el-select>
dragondean@qq.com's avatar
dragondean@qq.com committed
22
      </el-form-item>
23
      <el-form-item :label="$t('关键字')" prop="searchKey">
Marcus's avatar
Marcus committed
24
        <el-input v-model="queryParams.searchKey" :placeholder="$t('请输入关键字')" clearable @keyup.enter.native="handleQuery"/>
dragondean@qq.com's avatar
dragondean@qq.com committed
25
      </el-form-item>
26
      <el-form-item>
Marcus's avatar
Marcus committed
27 28
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('重置') }}</el-button>
29 30 31 32 33 34 35
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
Marcus's avatar
Marcus committed
36
                   v-hasPermi="['ecw:coupon:create']">{{ $t('新增') }}</el-button>
37 38 39
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
Marcus's avatar
Marcus committed
40
                   v-hasPermi="['ecw:coupon:export']">{{ $t('导出') }}</el-button>
41 42 43 44 45
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
46
    <el-table v-loading="loading" :data="list" border>
dragondean@qq.com's avatar
dragondean@qq.com committed
47
      <el-table-column :label="$t('优惠券ID')" align="center" prop="couponId" />
Marcus's avatar
Marcus committed
48
      <el-table-column :label="$t('类型')" align="center" prop="type">
49
        <template slot-scope="{row}">
50
          <dict-tag :type="DICT_TYPE.ECW_COUPON_TYPE" :value="row.type" />
51 52
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
53 54
      <el-table-column :label="$t('标题')" align="center" prop="titleZh" />
      <!-- <el-table-column :label="$t('描述')" align="center" prop="type">
dragondean@qq.com's avatar
dragondean@qq.com committed
55 56 57
        <template slot-scope="{row}">
          {{$l(row, 'content')}}
        </template>
dragondean@qq.com's avatar
dragondean@qq.com committed
58
      </el-table-column> -->
dragondean@qq.com's avatar
dragondean@qq.com committed
59
      <el-table-column :label="$t('发布人') + '/' + $t('发布时间')" align="center" prop="startTime" width="180">
60 61
        <template slot-scope="scope">
          <div>{{ scope.row.creatorName }}</div>
邓春圆's avatar
邓春圆 committed
62
          <div>{{ parseTime(scope.row.createTime) }}</div>
63 64
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
65
      <el-table-column :label="$t('开始时间')" align="center" prop="startTime" width="180">
66
        <template slot-scope="scope">
dragondean@qq.com's avatar
dragondean@qq.com committed
67
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
68 69
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
70
      <el-table-column :label="$t('结束时间')" align="center" prop="endTime" width="180">
dragondean@qq.com's avatar
dragondean@qq.com committed
71
        <template slot-scope="{row}">
72
          <div :style="{color: !row.overdueStatus ? 'red' : null}">{{ parseTime(row.endTime, '{y}-{m}-{d}') }}</div>
73
          <div style="color: red">{{ !row.overdueStatus ? $t('已过期') : expireTips(row.endTime) }}</div>
74 75
        </template>
      </el-table-column>
邓春圆's avatar
邓春圆 committed
76
      <!--
Marcus's avatar
Marcus committed
77
      <el-table-column :label="$t('创建时间')" align="center" prop="createTime" width="180">
78 79 80
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
dragondean@qq.com's avatar
dragondean@qq.com committed
81
      </el-table-column-->
82 83 84
      <el-table-column :label="$t('更新人') + '/' + $t('更新时间')" align="center" width="180">
        <template slot-scope="scope">
          <div>{{ scope.row.updaterName }}</div>
邓春圆's avatar
邓春圆 committed
85
          <div>{{ parseTime(scope.row.updateTime)}}</div>
86 87
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
88
      <el-table-column :label="$t('状态')" align="center" prop="createTime" width="180">
dragondean@qq.com's avatar
dragondean@qq.com committed
89
        <template slot-scope="{row}">
90 91 92 93 94 95 96
          <template v-if="row.status === 1">
            <template v-if="row.putonStatus === 1">{{$t('已发布,投放中')}}</template>
            <template v-else-if="row.putonStatus === -1">{{$t('取消投放')}}</template>
            <!--投放状态暂时就只有上诉两种,如果出现了其他的应该视为异常状态,为了方便发现问题所以直接显示投放字典-->
						<dict-tag v-else :type="DICT_TYPE.ECW_COUPON_PUTON_STATUS" :value="row.putonStatus" />
          </template>
          <template v-else>{{$t('草稿')}}</template>
dragondean@qq.com's avatar
dragondean@qq.com committed
97
        </template>
dragondean@qq.com's avatar
dragondean@qq.com committed
98
      </el-table-column>
99
      <!--<el-table-column :label="$t('投放状态')" align="center" prop="putonStatus" width="180">
100 101 102
        <template slot-scope="{row}">
          <dict-tag :type="DICT_TYPE.ECW_COUPON_PUTON_STATUS" :value="row.putonStatus" />
        </template>
103
      </el-table-column>-->
Marcus's avatar
Marcus committed
104
      <el-table-column :label="$t('操作')" align="center" fixed="right" class-name="small-padding fixed-width">
105
        <template slot-scope="scope">
106
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetail(scope.row, true)"
107
                     v-hasPermi="['ecw:coupon:show']">{{ $t('查看') }}</el-button>
108

109
          <el-button v-if="scope.row.status === 1 && scope.row.putonStatus == 1" size="mini" type="text" icon="el-icon-edit" @click="setPutonStatus(scope.row, -1)"
110
                     v-hasPermi="['ecw:coupon:show']">{{ $t('取消投放') }}</el-button>
111
          <el-button v-else-if="scope.row.status === 1" size="mini" type="text" icon="el-icon-edit" @click="setPutonStatus(scope.row, 1)"
112 113
                     v-hasPermi="['ecw:coupon:show']">{{ $t('投放') }}</el-button>

dragondean@qq.com's avatar
dragondean@qq.com committed
114
          <el-button v-if="scope.row.status != 1" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
Marcus's avatar
Marcus committed
115
                     v-hasPermi="['ecw:coupon:update']">{{ $t('编辑') }}</el-button>
dragondean@qq.com's avatar
dragondean@qq.com committed
116
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleCopy(scope.row)"
117
                     v-hasPermi="['ecw:coupon:copy']">{{ $t('复制') }}</el-button>
118
          <el-button size="mini" type="text" icon="el-icon-edit" @click="updateEndtimeItem = scope.row" v-if="scope.row.endTime"
119
                     v-hasPermi="['ecw:coupon:delay']">{{ $t('延期') }}</el-button>
120
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
Marcus's avatar
Marcus committed
121
                     v-hasPermi="['ecw:coupon:delete']">{{ $t('删除') }}</el-button>
122 123 124 125 126 127
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
邓春圆's avatar
邓春圆 committed
128

129 130 131
    <el-dialog :title="$t('延期活动时间')" :visible="!!updateEndtimeItem" :before-close="() => updateEndtimeItem=null">
      <div v-if="updateEndtimeItem">
        {{$t('优惠活动“{name}”的当前结束时间:{time}',{
dragondean@qq.com's avatar
dragondean@qq.com committed
132
          name: $l(updateEndtimeItem, 'title'),
133 134 135 136 137 138
          time: updateEndtimeItem.endTime || $t('永久有效')
          })}}
      </div>
      <div>{{$t('请问您确定延长活动吗?')}}</div>
      <el-form :model="updateEndtimeForm" :rules="updateEndtimeRules" label-position="left" >
        <el-form-item :label="$t('活动结束时间')" prop="endTime">
dragondean@qq.com's avatar
dragondean@qq.com committed
139
          <el-date-picker v-if="!updateEndtimeForm.forever" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" v-model="updateEndtimeForm.endTime" placeholder=""></el-date-picker>
140 141 142 143 144 145 146 147
          <el-checkbox :label="$t('永久有效')" v-model="updateEndtimeForm.forever" class="ml-10"></el-checkbox>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="updateEndtime">{{$t('确定')}}</el-button>
        <el-button type="default" @click="updateEndtimeItem = null">{{$t('取消')}}</el-button>
      </div>
    </el-dialog>
148 149 150 151 152

  </div>
</template>

<script>
153 154 155 156 157 158 159 160 161 162 163
import {
  createCoupon,
  updateCoupon,
  deleteCoupon,
  getCoupon,
  getCouponPage,
  exportCouponExcel,
  updateEndtime,
  updatePutonStatus
} from "@/api/ecw/coupon";
import Template from "@/views/cms/template/index.vue";
164 165

export default {
166
  name: "EcwCouponIndex",
167
  components: {
168
    Template
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
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 优惠券信息列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeStartTime: [],
      dateRangeEndTime: [],
      dateRangeCreateTime: null,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        titleZh: null,
        titleEn: null,
        type: null,
        cashCondition: null,
        reduceAmount: null,
        conditionCurrencyId: null,
        reduceCurrencyId: null,
        afterReceiveDays: null,
        validDays: null,
        costType: null,
        discountDetailed: null,
        isSimilarSuperposition: null,
        couponIds: null,
        suitableUserType: null,
        suitableLineType: null,
        suitableProdType: null,
        limitNum: null,
        overdueStatus: null,
        putonStatus: null,
        getWay: null,
        orderAttr: null,
        isSiteContent: null,
        isCargoControl: null,
        documentDeclaration: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
223 224 225
      },
      updateEndtimeItem: null, // 延期操作的数据
      updateEndtimeForm:{} // 延长有效期的表单数据
226 227
    };
  },
228 229 230 231 232 233 234
  computed:{
    updateEndtimeRules(){
      return {
        endTime: [
          {required: !this.updateEndtimeForm.forever, message: "请填写结束时间"}
        ]
      }
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    },
    expireTips(){
      return endTime => {
        if(!endTime) return ''
        console.log({endTime})
        // 7天以内用红色标注提醒:“还有N天到期”,最后一天显示1天过期
        let endDate = new Date(endTime.replace(/-/g, '/'))
        if(endDate.getHours() == 0){
          endDate.setHours(23)
          endDate.setMinutes(59)
          endDate.setSeconds(59)
        }
        let now = new Date()
        let diff = endDate.getTime() - now.getTime()
        let days = Math.ceil(diff / (24 * 60 * 60 * 1000))
        if(days <= 1){
          return this.$t('1天内过期')
        }else if(days <= 7){
          return this.$t('还有{days}天到期', {days})
        }
      }
256 257
    }
  },
dragondean@qq.com's avatar
dragondean@qq.com committed
258 259 260 261 262
  watch:{
    updateEndtimeItem(){
      this.updateEndtimeForm = {}
    }
  },
263 264 265
  created() {
    this.getList();
  },
266 267 268
  activated(){
    this.getList()
  },
269 270 271 272 273 274
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
dragondean@qq.com's avatar
dragondean@qq.com committed
275 276 277 278
      if(params.status == 2){
        params.overdueStatus=0
        params.status = null
      }
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
      this.addBeginAndEndTime(params, this.dateRangeStartTime, 'startTime');
      this.addBeginAndEndTime(params, this.dateRangeEndTime, 'endTime');
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行查询
      getCouponPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeStartTime = [];
      this.dateRangeEndTime = [];
      this.dateRangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      return this.$router.push('edit')
    },
    /** 修改按钮操作 */
307
    handleUpdate(row, readonly) {
308
      const couponId = row.couponId;
309 310 311 312 313
      let url = 'edit?id=' + couponId
      if(readonly){
        url += '&readonly=1'
      }
      return this.$router.push(url)
314
    },
315 316 317
    handleDetail(row){
      this.$router.push('detail?id=' + row.couponId + '&readonly=1')
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
318 319
    handleCopy(row){
      this.$router.push('edit?action=copy&id=' + row.couponId)
320 321 322 323
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const couponId = row.couponId;
dragondean@qq.com's avatar
dragondean@qq.com committed
324
      this.$confirm(this.$t('是否确认删除优惠券信息编号为{couponId}的数据项?', {couponId})).then(function() {
325 326 327
          return deleteCoupon(couponId);
        }).then(() => {
          this.getList();
dragondean@qq.com's avatar
dragondean@qq.com committed
328
          this.$message.success(this.$t("删除成功"));
329 330
        }).catch(() => {});
    },
331 332 333 334 335 336 337 338 339 340
    // 延期
    updateEndtime(){
      if(!this.updateEndtimeForm.forever && !this.updateEndtimeForm.endTime){
        return this.$message.error(this.$t("请填写结束时间"))
      }
      let form = {couponId: this.updateEndtimeItem.couponId, ...this.updateEndtimeForm}
      form.isValidity = !form.forever // 是否设置有效期
      updateEndtime(form).then(res => {
        this.getList()
        this.updateEndtimeItem = null
341
        this.$message.success(this.$t('操作成功'))
342 343
      })
    },
344 345 346 347 348 349 350 351 352 353
    // 投放,取消投放就
    setPutonStatus(row, status){
      updatePutonStatus({
        couponId: row.couponId,
        putonStatus: status
      }).then(res => {
        this.$message.success(this.$t('操作成功'))
        this.getList()
      })
    },
354 355 356 357 358 359 360 361 362 363
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeStartTime, 'startTime');
      this.addBeginAndEndTime(params, this.dateRangeEndTime, 'endTime');
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行导出
dragondean@qq.com's avatar
dragondean@qq.com committed
364
      this.$confirm(this.$t('是否确认导出所有优惠券信息数据项?')).then(() => {
365 366 367 368 369 370 371 372 373
          this.exportLoading = true;
          return exportCouponExcel(params);
        }).then(response => {
          this.$download.excel(response, '${table.classComment}.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
邓春圆's avatar
邓春圆 committed
374
</script>