index.vue 16.1 KB
Newer Older
lanbaoming's avatar
lanbaoming committed
1 2 3 4 5 6 7 8 9 10 11
<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item :label="$t('标题')" prop="titleZh">
        <el-input v-model="queryParams.titleZh" :placeholder="$t('请输入标题')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
      <!-- <el-form-item :label="$t('标题')" prop="titleEn">
        <el-input v-model="queryParams.titleEn" :placeholder="$t('请输入标题')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
12 13 14 15 16 17
      <el-form-item :label="$t('类型')" prop="types">
        <dict-selector
          :type='DICT_TYPE.ECW_COUPON_TYPE'
          v-model="queryParams.types"
          multiple
          clearable />
lanbaoming's avatar
lanbaoming committed
18
      </el-form-item>
19
      <el-form-item :label="$t('状态')" prop="statusList" clearable>
lanbaoming's avatar
lanbaoming committed
20
        <!-- <dict-selector :type="DICT_TYPE.ECW_COUPON_STATUS" v-model="queryParams.status"/> -->
21 22 23 24 25 26
        <el-select
          v-model="queryParams.statusList"
          :placeholder="$t('请选择')"
          clearable
          multiple
          size="small">
lanbaoming's avatar
lanbaoming committed
27 28
          <el-option :label="$t('草稿')" value="0" />
          <el-option :label="$t('已发布')" value="1" />
zhengyi's avatar
zhengyi committed
29 30
          <el-option :label="$t('已发布,未投放')" value="2" />
          <el-option :label="$t('已发布,投放中')" value="3" />
zhengyi's avatar
zhengyi committed
31
          <el-option :label="$t('已过期')" value="4" />
lanbaoming's avatar
lanbaoming committed
32 33 34 35 36
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('关键字')" prop="searchKey">
        <el-input v-model="queryParams.searchKey" :placeholder="$t('请输入关键字')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
37 38


39 40 41 42 43 44 45 46 47
      <el-form-item :label="$t('结束时间')">
        <el-date-picker
          v-model="dateRangeEndTime"
          type="daterange"
          :start-placeholder="$t('开始日期')"
          value-format="yyyy-MM-dd"
          :end-placeholder="$t('结束日期')"
        >
        </el-date-picker>
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
      </el-form-item>

      <el-form-item :label="$t('创建时间')">
        <el-date-picker
          v-model="dateRangeCreateTime"
          type="datetimerange"
          :start-placeholder="$t('开始日期')"
          value-format="yyyy-MM-dd HH:mm:ss"
          :end-placeholder="$t('结束日期')"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item :label="$t('创建人')" prop="creator">
        <el-input
          v-model.trim="queryParams.creator"
          :placeholder="$t('请输入创建人')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

lanbaoming's avatar
lanbaoming committed
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
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('重置') }}</el-button>
      </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"
                   v-hasPermi="['ecw:coupon:create']">{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                   v-hasPermi="['ecw:coupon:export']">{{ $t('导出') }}</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" border>
      <el-table-column :label="$t('优惠券ID')" align="center" prop="couponId" />
      <el-table-column :label="$t('类型')" align="center" prop="type">
        <template slot-scope="{row}">
          <dict-tag :type="DICT_TYPE.ECW_COUPON_TYPE" :value="row.type" />
        </template>
      </el-table-column>
97
      <el-table-column :label="$t('标题')" align="center" prop="titleZh"  width="180" />
lanbaoming's avatar
lanbaoming committed
98 99 100 101 102
      <!-- <el-table-column :label="$t('描述')" align="center" prop="type">
        <template slot-scope="{row}">
          {{$l(row, 'content')}}
        </template>
      </el-table-column> -->
103
      <el-table-column :label="$t('发布人') + '/' + $t('发布时间')" align="center" prop="startTime" width="150">
lanbaoming's avatar
lanbaoming committed
104 105 106 107 108
        <template slot-scope="scope">
          <div>{{ scope.row.creatorName }}</div>
          <div>{{ parseTime(scope.row.createTime) }}</div>
        </template>
      </el-table-column>
109 110

      <el-table-column :label="$t('开始时间')" align="center" prop="startTime" width="100">
lanbaoming's avatar
lanbaoming committed
111 112 113 114
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
115
      <el-table-column :label="$t('结束时间')" align="center" prop="endTime" width="100">
lanbaoming's avatar
lanbaoming committed
116 117 118 119 120
        <template slot-scope="{row}">
          <div :style="{color: !row.overdueStatus ? 'red' : null}">{{ parseTime(row.endTime, '{y}-{m}-{d}') }}</div>
          <div style="color: red">{{ !row.overdueStatus ? $t('已过期') : expireTips(row.endTime) }}</div>
        </template>
      </el-table-column>
121 122

      <el-table-column :label="$t('创建人') + '/' + $t('创建时间')" align="center" width="150">
lanbaoming's avatar
lanbaoming committed
123
        <template slot-scope="scope">
124 125
          <div>{{ scope.row.creatorName }}</div>
          <div>{{ parseTime(scope.row.createTime)}}</div>
lanbaoming's avatar
lanbaoming committed
126
        </template>
127 128 129
      </el-table-column>

      <el-table-column :label="$t('更新人') + '/' + $t('更新时间')" align="center" width="150">
lanbaoming's avatar
lanbaoming committed
130 131 132 133 134
        <template slot-scope="scope">
          <div>{{ scope.row.updaterName }}</div>
          <div>{{ parseTime(scope.row.updateTime)}}</div>
        </template>
      </el-table-column>
135
      <el-table-column :label="$t('状态')" align="center" prop="createTime" width="120">
lanbaoming's avatar
lanbaoming committed
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
        <template slot-scope="{row}">
          <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>
        </template>
      </el-table-column>
      <!--<el-table-column :label="$t('投放状态')" align="center" prop="putonStatus" width="180">
        <template slot-scope="{row}">
          <dict-tag :type="DICT_TYPE.ECW_COUPON_PUTON_STATUS" :value="row.putonStatus" />
        </template>
      </el-table-column>-->
      <el-table-column :label="$t('操作')" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetail(scope.row, true)"
                     v-hasPermi="['ecw:coupon:show']">{{ $t('查看') }}</el-button>

          <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)"
                     v-hasPermi="['ecw:coupon:show']">{{ $t('取消投放') }}</el-button>
          <el-button v-else-if="scope.row.status === 1" size="mini" type="text" icon="el-icon-edit" @click="setPutonStatus(scope.row, 1)"
                     v-hasPermi="['ecw:coupon:show']">{{ $t('投放') }}</el-button>

          <el-button v-if="scope.row.status != 1" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['ecw:coupon:update']">{{ $t('编辑') }}</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleCopy(scope.row)"
                     v-hasPermi="['ecw:coupon:copy']">{{ $t('复制') }}</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="updateEndtimeItem = scope.row" v-if="scope.row.endTime"
                     v-hasPermi="['ecw:coupon:delay']">{{ $t('延期') }}</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['ecw:coupon:delete']">{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <el-dialog :title="$t('延期活动时间')" :visible="!!updateEndtimeItem" :before-close="() => updateEndtimeItem=null">
      <div v-if="updateEndtimeItem">
        {{$t('优惠活动“{name}”的当前结束时间:{time}',{
          name: $l(updateEndtimeItem, 'title'),
          time: updateEndtimeItem.endTime || $t('永久有效')
          })}}
      </div>
      <div>{{$t('请问您确定延长活动吗?')}}</div>
      <el-form :model="updateEndtimeForm" :rules="updateEndtimeRules" label-position="left" >
        <el-form-item :label="$t('活动结束时间')" prop="endTime">
          <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>
          <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>

  </div>
</template>

<script>
import {
  createCoupon,
  updateCoupon,
  deleteCoupon,
  getCoupon,
  getCouponPage,
  exportCouponExcel,
  updateEndtime,
  updatePutonStatus
} from "@/api/ecw/coupon";
import Template from "@/views/cms/template/index.vue";

export default {
  name: "EcwCouponIndex",
  components: {
    Template
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 优惠券信息列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeStartTime: [],
      dateRangeEndTime: [],
235
      dateRangeCreateTime: [],
lanbaoming's avatar
lanbaoming committed
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
      // 查询参数
      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: {
      },
      updateEndtimeItem: null, // 延期操作的数据
      updateEndtimeForm:{} // 延长有效期的表单数据
    };
  },
  computed:{
    updateEndtimeRules(){
      return {
        endTime: [
          {required: !this.updateEndtimeForm.forever, message: "请填写结束时间"}
        ]
      }
    },
    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})
        }
      }
    }
  },
  watch:{
    updateEndtimeItem(){
      this.updateEndtimeForm = {}
    }
  },
  created() {
    this.getList();
  },
  activated(){
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      if(params.status == 2){
        params.overdueStatus=0
        params.status = null
      }
      this.addBeginAndEndTime(params, this.dateRangeStartTime, 'startTime');
      this.addBeginAndEndTime(params, this.dateRangeEndTime, 'endTime');
328 329 330 331 332 333 334 335

      this.addBeginAndEndTime(
        params,
        this.dateRangeCreateTime,
        "createTime",
        false
      );

lanbaoming's avatar
lanbaoming committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
      // 执行查询
      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 = [];
353 354
      this.queryParams.statusList =[];

lanbaoming's avatar
lanbaoming committed
355
      this.resetForm("queryForm");
356
      this.queryParams.types =[];
lanbaoming's avatar
lanbaoming committed
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
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      return this.$router.push('edit')
    },
    /** 修改按钮操作 */
    handleUpdate(row, readonly) {
      const couponId = row.couponId;
      let url = 'edit?id=' + couponId
      if(readonly){
        url += '&readonly=1'
      }
      return this.$router.push(url)
    },
    handleDetail(row){
      this.$router.push('detail?id=' + row.couponId + '&readonly=1')
    },
    handleCopy(row){
      this.$router.push('edit?action=copy&id=' + row.couponId)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const couponId = row.couponId;
      this.$confirm(this.$t('是否确认删除优惠券信息编号为{couponId}的数据项?', {couponId})).then(function() {
          return deleteCoupon(couponId);
        }).then(() => {
          this.getList();
          this.$message.success(this.$t("删除成功"));
        }).catch(() => {});
    },
    // 延期
    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
        this.$message.success(this.$t('操作成功'))
      })
    },
    // 投放,取消投放就
    setPutonStatus(row, status){
      updatePutonStatus({
        couponId: row.couponId,
        putonStatus: status
      }).then(res => {
        this.$message.success(this.$t('操作成功'))
        this.getList()
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeStartTime, 'startTime');
      this.addBeginAndEndTime(params, this.dateRangeEndTime, 'endTime');
419 420 421 422 423 424 425

      this.addBeginAndEndTime(
        params,
        this.dateRangeCreateTime,
        "createTime",
        false
      );
lanbaoming's avatar
lanbaoming committed
426 427 428 429 430 431 432 433 434 435 436 437
      // 执行导出
      this.$confirm(this.$t('是否确认导出所有优惠券信息数据项?')).then(() => {
          this.exportLoading = true;
          return exportCouponExcel(params);
        }).then(response => {
          this.$download.excel(response, '${table.classComment}.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>