提交 c6425bd8 authored 作者: 吴德鹏's avatar 吴德鹏

完成首页活动管理

上级 83b90639
package com.platform.controller;
import com.platform.entity.TbCfActivityEntity;
import com.platform.service.TbCfActivityService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* 活动Controller
*
* @author lipengjun
* @date 2020-06-02 16:33:55
*/
@Controller
@RequestMapping("tbcfactivity")
public class TbCfActivityController {
@Autowired
private TbCfActivityService tbCfActivityService;
/**
* 查看列表
*/
@RequestMapping("/list")
@RequiresPermissions("tbcfactivity:list")
@ResponseBody
public R list(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<TbCfActivityEntity> tbCfActivityList = tbCfActivityService.queryList(query);
int total = tbCfActivityService.queryTotal(query);
PageUtils pageUtil = new PageUtils(tbCfActivityList, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 查看信息
*/
@RequestMapping("/info/{id}")
@RequiresPermissions("tbcfactivity:info")
@ResponseBody
public R info(@PathVariable("id") String id) {
TbCfActivityEntity tbCfActivity = tbCfActivityService.queryObject(id);
return R.ok().put("tbCfActivity", tbCfActivity);
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("tbcfactivity:save")
@ResponseBody
public R save(@RequestBody TbCfActivityEntity tbCfActivity) {
tbCfActivityService.save(tbCfActivity);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("tbcfactivity:update")
@ResponseBody
public R update(@RequestBody TbCfActivityEntity tbCfActivity) {
tbCfActivityService.update(tbCfActivity);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("tbcfactivity:delete")
@ResponseBody
public R delete(@RequestBody String[] ids) {
tbCfActivityService.deleteBatch(ids);
return R.ok();
}
/**
* 查看所有列表
*/
@RequestMapping("/queryAll")
@ResponseBody
public R queryAll(@RequestParam Map<String, Object> params) {
List<TbCfActivityEntity> list = tbCfActivityService.queryList(params);
return R.ok().put("list", list);
}
}
package com.platform.dao;
import com.platform.entity.TbCfActivityEntity;
import java.util.List;
/**
* 活动Dao
*
* @author lipengjun
* @date 2020-06-02 16:33:55
*/
public interface TbCfActivityDao extends BaseDao<TbCfActivityEntity> {
List<TbCfActivityEntity> getTopActivity();
}
package com.platform.entity;
import java.io.Serializable;
import java.util.Date;
/**
* 活动实体
* 表名 tb_cf_activity
*
* @author lipengjun
* @date 2020-06-02 18:19:07
*/
public class TbCfActivityEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 活动ID
*/
private String id;
/**
* 活动类型 0.外链,1.分类子页面,2.商品列表页,3.商品 , 4.不跳转
*/
private Integer activityType;
/**
* 活动标题
*/
private String activityTitle;
/**
* 活动链接
*/
private String activityLink;
/**
* 活动主图
*/
private String activityImage;
/**
* 活动按钮
*/
private String activityButton;
/**
* 是否置顶 0: 不置顶 1:置顶
*/
private Integer isTop;
/**
* 是否启用 0:不启用 1:启用
*/
private Integer isEnabled;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 设置:活动ID
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:活动ID
*/
public String getId() {
return id;
}
/**
* 设置:活动类型 0.外链,1.分类子页面,2.商品列表页,3.商品 , 4.不跳转
*/
public void setActivityType(Integer activityType) {
this.activityType = activityType;
}
/**
* 获取:活动类型 0.外链,1.分类子页面,2.商品列表页,3.商品 , 4.不跳转
*/
public Integer getActivityType() {
return activityType;
}
/**
* 设置:活动标题
*/
public void setActivityTitle(String activityTitle) {
this.activityTitle = activityTitle;
}
/**
* 获取:活动标题
*/
public String getActivityTitle() {
return activityTitle;
}
/**
* 设置:活动链接
*/
public void setActivityLink(String activityLink) {
this.activityLink = activityLink;
}
/**
* 获取:活动链接
*/
public String getActivityLink() {
return activityLink;
}
/**
* 设置:活动主图
*/
public void setActivityImage(String activityImage) {
this.activityImage = activityImage;
}
/**
* 获取:活动主图
*/
public String getActivityImage() {
return activityImage;
}
/**
* 设置:活动按钮
*/
public void setActivityButton(String activityButton) {
this.activityButton = activityButton;
}
/**
* 获取:活动按钮
*/
public String getActivityButton() {
return activityButton;
}
/**
* 设置:是否置顶 0: 不置顶 1:置顶
*/
public void setIsTop(Integer isTop) {
this.isTop = isTop;
}
/**
* 获取:是否置顶 0: 不置顶 1:置顶
*/
public Integer getIsTop() {
return isTop;
}
/**
* 设置:是否启用 0:不启用 1:启用
*/
public void setIsEnabled(Integer isEnabled) {
this.isEnabled = isEnabled;
}
/**
* 获取:是否启用 0:不启用 1:启用
*/
public Integer getIsEnabled() {
return isEnabled;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
}
package com.platform.service;
import com.platform.entity.TbCfActivityEntity;
import java.util.List;
import java.util.Map;
/**
* 活动Service接口
*
* @author lipengjun
* @date 2020-06-02 16:33:55
*/
public interface TbCfActivityService {
/**
* 根据主键查询实体
*
* @param id 主键
* @return 实体
*/
TbCfActivityEntity queryObject(String id);
/**
* 分页查询
*
* @param map 参数
* @return list
*/
List<TbCfActivityEntity> queryList(Map<String, Object> map);
/**
* 分页统计总数
*
* @param map 参数
* @return 总数
*/
int queryTotal(Map<String, Object> map);
/**
* 保存实体
*
* @param tbCfActivity 实体
* @return 保存条数
*/
int save(TbCfActivityEntity tbCfActivity);
/**
* 根据主键更新实体
*
* @param tbCfActivity 实体
* @return 更新条数
*/
int update(TbCfActivityEntity tbCfActivity);
/**
* 根据主键删除
*
* @param id
* @return 删除条数
*/
int delete(String id);
/**
* 根据主键批量删除
*
* @param ids
* @return 删除条数
*/
int deleteBatch(String[] ids);
}
package com.platform.service.impl;
import com.platform.dao.TbCfActivityDao;
import com.platform.entity.TbCfActivityEntity;
import com.platform.service.TbCfActivityService;
import com.platform.utils.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 活动Service实现类
*
* @author lipengjun
* @date 2020-06-02 16:33:55
*/
@Service("tbCfActivityService")
public class TbCfActivityServiceImpl implements TbCfActivityService {
@Autowired
private TbCfActivityDao tbCfActivityDao;
@Override
public TbCfActivityEntity queryObject(String id) {
return tbCfActivityDao.queryObject(id);
}
@Override
public List<TbCfActivityEntity> queryList(Map<String, Object> map) {
return tbCfActivityDao.queryList(map);
}
@Override
public int queryTotal(Map<String, Object> map) {
return tbCfActivityDao.queryTotal(map);
}
@Override
public int save(TbCfActivityEntity tbCfActivity) {
tbCfActivity.setId(IdUtil.createIdbyUUID());
tbCfActivity.setCreateTime(new Date());
tbCfActivity.setUpdateTime(new Date());
if ("1".equals(String.valueOf(tbCfActivity.getIsTop()))) {
getTopActivity();
}
return tbCfActivityDao.save(tbCfActivity);
}
@Override
public int update(TbCfActivityEntity tbCfActivity) {
tbCfActivity.setUpdateTime(new Date());
if ("1".equals(String.valueOf(tbCfActivity.getIsTop()))) {
getTopActivity();
}
return tbCfActivityDao.update(tbCfActivity);
}
//查询置顶的活动
public void getTopActivity() {
List<TbCfActivityEntity> activityList = tbCfActivityDao.getTopActivity();
if (activityList.size() > 0 && activityList != null) {
for (TbCfActivityEntity activity : activityList) {
activity.setIsTop(0);
tbCfActivityDao.update(activity);
}
}
}
@Override
public int delete(String id) {
return tbCfActivityDao.delete(id);
}
@Override
public int deleteBatch(String[] ids) {
return tbCfActivityDao.deleteBatch(ids);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.TbCfActivityDao">
<resultMap type="com.platform.entity.TbCfActivityEntity" id="tbCfActivityMap">
<result property="id" column="id"/>
<result property="activityType" column="activity_type"/>
<result property="activityTitle" column="activity_title"/>
<result property="activityLink" column="activity_link"/>
<result property="activityImage" column="activity_image"/>
<result property="activityButton" column="activity_button"/>
<result property="isTop" column="is_top"/>
<result property="isEnabled" column="is_enabled"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="queryObject" resultType="com.platform.entity.TbCfActivityEntity">
select
`id`,
`activity_type`,
`activity_title`,
`activity_link`,
`activity_image`,
`activity_button`,
`is_top`,
`is_enabled`,
`create_time`,
`update_time`
from tb_cf_activity
where id = #{id}
</select>
<select id="getTopActivity" resultType="com.platform.entity.TbCfActivityEntity">
select
`id`,
`activity_title`,
`activity_link`,
`activity_image`,
`activity_button`,
`is_top`,
`is_enabled`,
`create_time`,
`update_time`
from tb_cf_activity
where is_top=1
</select>
<select id="queryList" resultType="com.platform.entity.TbCfActivityEntity">
select
`id`,
`activity_type`,
`activity_title`,
`activity_link`,
`activity_image`,
`activity_button`,
`is_top`,
`is_enabled`,
`create_time`,
`update_time`
from tb_cf_activity
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order}
</when>
<otherwise>
order by is_top desc
</otherwise>
</choose>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from tb_cf_activity
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert id="save" parameterType="com.platform.entity.TbCfActivityEntity">
insert into tb_cf_activity(
`id`,
`activity_type`,
`activity_title`,
`activity_link`,
`activity_image`,
`activity_button`,
`is_top`,
`is_enabled`,
`create_time`,
`update_time`)
values(
#{id},
#{activityType},
#{activityTitle},
#{activityLink},
#{activityImage},
#{activityButton},
#{isTop},
#{isEnabled},
#{createTime},
#{updateTime})
</insert>
<update id="update" parameterType="com.platform.entity.TbCfActivityEntity">
update tb_cf_activity
<set>
<if test="activityType != null">`activity_type` = #{activityType},</if>
<if test="activityTitle != null">`activity_title` = #{activityTitle},</if>
<if test="activityLink != null">`activity_link` = #{activityLink},</if>
<if test="activityImage != null">`activity_image` = #{activityImage},</if>
<if test="activityButton != null">`activity_button` = #{activityButton},</if>
<if test="isTop != null">`is_top` = #{isTop},</if>
<if test="isEnabled != null">`is_enabled` = #{isEnabled},</if>
<if test="createTime != null">`create_time` = #{createTime},</if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where id = #{id}
</update>
<delete id="delete">
delete from tb_cf_activity where id = #{value}
</delete>
<delete id="deleteBatch">
delete from tb_cf_activity where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
<title>活动</title>
#parse("sys/header.html")
<style>
.ui-jqgrid .ui-jqgrid-bdiv {
height: auto !important;
}
body {
background: #f9f9f9;
}
ul li {
list-style: none;
text-align: center;
}
#app {
box-sizing: border-box;
min-width: 1200px;
margin: 0 auto;
}
.category-container {
min-height: 600px;
padding-bottom: 80px;
}
.edit-container {
position: relative;
height: 500px;
}
.btn-container {
position: absolute;
bottom: 0;
right: 0;
}
.productList {
padding-bottom: 10px;
}
.productList, .search {
display: flex;
justify-content: start;
}
.productList-style-start {
display: flex;
justify-content: start;
}
.vRadio {
display: inline-block;
width: 20px;
height: 20px;
background: #eeeeee;
border-radius: 4px;
transition: all 0.4s;
}
.vradio-wrapper {
cursor: pointer;
}
.vRadio-active {
background: #000;
opacity: 0.6;
}
.vradio-wrapper > i {
vertical-align: top;
}
#searchjqGrid {
width: 100%;
margin-top: 10px;
}
#showItems {
margin-top: 20px;
}
#app {
height: 820px;
}
.category-container {
height: 800px;
}
</style>
</head>
<body>
<div id="rrapp" v-cloak style="height: calc(100% - 15px);">
<div v-show="showList" style="height: 100%;">
<Row :gutter="16">
<div class="search-group">
<i-col span="4">
<i-input v-model="q.name" @on-enter="query" placeholder="名称"/>
</i-col>
<i-button @click="query">查询</i-button>
<i-button @click="reloadSearch">重置</i-button>
</div>
<div class="buttons-group">
#if($shiro.hasPermission("tbcfactivity:save"))
<i-button type="info" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</i-button>
#end
#if($shiro.hasPermission("tbcfactivity:update"))
<i-button type="warning" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</i-button>
#end
#if($shiro.hasPermission("tbcfactivity:delete"))
<i-button type="error" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</i-button>
#end
</div>
</Row>
<table id="jqGrid"></table>
</div>
<Card v-show="!showList">
<p slot="title">{{title}}</p>
<i-form ref="formValidate" :model="tbCfActivity" :rules="ruleValidate" :label-width="80">
<Form-item label="活动标题" prop="activityTitle">
<i-input v-model="tbCfActivity.activityTitle" placeholder="活动标题" style="width:500px"/>
</Form-item>
<!-- <Form-item label="活动链接" prop="activityLink">-->
<!-- <i-input v-model="tbCfActivity.activityLink" placeholder="活动链接"/>-->
<!-- </Form-item>-->
<div id="app">
<Card class="category-container">
<p slot="title">
<span
v-for="(element,index) in items" :key='index'
@click='vHandleChange(element,index)'
style="margin-left:20px;"
class="vradio-wrapper"
>
<span class="vRadio" :class="[element.isChecked?'vRadio-active':null]"></span>
<i>{{element.name}}</i>
</span>
</p>
<section class="edit-container">
<!-- 链接 -->
<div v-if='typeActive==0'>
<i-Input v-model="link" placeholder="请输入目标链接"/>
</div>
<!-- 分类子页面 -->
<!-- <div v-else-if='typeActive==1'>-->
<!-- <span>一级分类</span>-->
<!-- <i-Select v-model="subcategoryListsActive" style="width:200px" @on-change="changeSubCateType">-->
<!-- <i-Option v-for="item in subCategoryLists" :value="item.value" :key="item.value">{{ item.label }}</i-Option>-->
<!-- </i-Select>-->
<!-- <span style="margin-left:20px;">二级分类</span>-->
<!-- <i-Select v-model="subsubCategoryListsActive" style="width:200px">-->
<!-- <i-Option v-for="item in subsubCategoryLists" :value="item.value" :key="item.value">{{ item.label }}</i-Option>-->
<!-- </i-Select>-->
<!-- </div>-->
<!-- 商品列表页 -->
<div v-else-if='typeActive==1'>
<div class="productList-style-start">
<div>
<span>一级分类</span>
<i-Select v-model.sync="categoryListsActive1" style="width:100px"
@on-change="changeSubCateType">
<i-Option v-for="item in CategoryLists1" :value="item.value" :key="item.value">
{{ item.label }}
</i-Option>
</i-Select>
</div>
<div>
<span style="margin-left:20px;">二级分类</span>
<i-Select v-model.sync="categoryListsActive2" @on-change="queryMiniCatagory(2)"
style="width:100px">
<i-Option v-for="item in CategoryLists2" :value="item.value" :key="item.value">
{{ item.label }}
</i-Option>
</i-Select>
</div>
<div>
<span style="margin-left:20px;">三级分类</span>
<i-Select v-model.sync="categoryListsActive3" style="width:100px">
<i-Option v-for="item in CategoryLists3" :value="item.value" :key="item.value">
{{ item.label }}
</i-Option>
</i-Select>
</div>
</div>
<i-Button type="warning" style="float: right;margin-top:30px;width:100px;"
@click='resetSelectedCategory'>重置
</i-Button>
</div>
<!-- 商品 -->
<div v-else-if="typeActive==2">
<div class="productList-style-start">
<div>
<span>一级分类</span>
<i-Select v-model="commoditycategoryListsActive1" style="width:100px"
@on-change="changeSubCateType">
<i-Option v-for="item in commodityCategoryLists1" :value="item.value"
:key="item.value">{{ item.label }}
</i-Option>
</i-Select>
</div>
<div>
<span style="margin-left:20px;">二级分类</span>
<i-Select v-model="commoditycategoryListsActive2" @on-change="queryMiniCatagory(3)"
style="width:100px">
<i-Option v-for="item in commodityCategoryLists2" :value="item.value"
:key="item.value">{{ item.label }}
</i-Option>
</i-Select>
</div>
<div>
<span style="margin-left:20px;">三级分类</span>
<i-Select v-model="commoditycategoryListsActive3" style="width:100px">
<i-Option v-for="item in commodityCategoryLists3" :value="item.value"
:key="item.value">{{ item.label }}
</i-Option>
</i-Select>
</div>
</div>
<div class="search" style="margin-top:20px;">
<div>
<i-Input v-model="search"
placeholder="请输入搜索内容(可选)"
style="width:500px;"/>
</div>
<i-Button
type="primary"
style="width:100px;"
@click='handleSearch()'
>搜索
</i-Button>
<i-Button style="width:100px;" @click="resetSelectedCategory('commodity')">重置</i-Button>
</div>
<section id="showItems">
<table id="searchjqGrid"></table>
</section>
</div>
<div v-else-if="typeActive==3">
<div>
<span style="margin-left:20px;">商品标签</span>
<i-Select v-model="tagListsActive" style="width:100px">
<i-Option v-for="item in tagLists" :value="item.value" :key="item.value">{{
item.label }}
</i-Option>
</i-Select>
</div>
</div>
</section>
</Card>
</div>
<Form-item label="活动主图" prop="activityImage">
<!-- <i-input v-model="tbCfActivity.activityImage" placeholder="活动主图"/>-->
<img v-bind:src="tbCfActivity.activityImage" v-show="!!tbCfActivity.activityImage"/>
<input type="file" placeholder="活动主图" @change="tirggerFile($event)"/>
</Form-item>
<Form-item label="活动按钮" prop="activityButton">
<!-- <i-input v-model="tbCfActivity.activityButton" placeholder="活动按钮"/>-->
<img v-bind:src="tbCfActivity.activityButton" v-show="!!tbCfActivity.activityButton"/>
<input type="file" placeholder="活动按钮" @change="tirggerFile1($event)"/>
</Form-item>
<Form-item label="是否置顶" >
<i-Switch size="large" v-model="isShow" true-color="#13ce66" false-color="#eeddff">
<span slot="open"></span>
<span slot="close"></span>
</i-Switch>
</Form-item>
<Form-item label="是否启用" prop="isEnabled">
<i-select placeholder="请选择" v-model="tbCfActivity.isEnabled" style="width:500px">
<i-option v-for=" e in chooseOptions1"
:value="e.value">{{e.label}}
</i-option>
</i-select>
</Form-item>
<Form-item>
<i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
<i-button type="warning" @click="reload" style="margin-left: 8px"/>
返回</i-button>
<i-button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
</Form-item>
</i-form>
</Card>
</div>
<script src="${rc.contextPath}/js/sys/tbcfactivity.js?_${date.systemTime}"></script>
</body>
</html>
\ No newline at end of file
$(function () {
$("#jqGrid").Grid({
url: '../tbcfactivity/list',
colModel: [
{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
{label: '活动标题', name: 'activityTitle', index: 'activity_title', width: 80},
{label: '活动链接', name: 'activityLink', index: 'activity_link', width: 80},
{label: '活动主图', name: 'activityImage', index: 'activity_image', width: 80, formatter: imageFormat},
{label: '活动按钮', name: 'activityButton', index: 'activity_button', width: 80, formatter: imageFormat},
{label: '是否置顶 ', name: 'isTop', index: 'is_top', width: 80, formatter: validFormat},
{label: '是否启用 ', name: 'isEnabled', index: 'is_enabled', width: 80, formatter: validFormat},
{label: '创建时间', name: 'createTime', index: 'create_time', width: 80}
]
});
});
let vm = new Vue({
el: '#rrapp',
data: {
chooseOptions: null,
typeActive: 0, //显示索引
items: [
{
name: '链接',
isChecked: true
},
// {
// name: '分类子页面',
// isChecked: false
// },
{
name: '商品列表页',
isChecked: false
}, {
name: '商品',
isChecked: false
}, {
name: '标签',
isChecked: false
},
{
name: '不跳转',
isChecked: false
}
],
/*
--链接方式
*/
link: null,//链接
/*
--分类子页面
*/
// 一级分类
subCategoryLists: [
{
value: 'New',
label: 'New'
}
],
subcategoryListsActive: null,
// 二级分类
subsubCategoryLists: [
{
value: 'York',
label: 'York'
}
],
subsubCategoryListsActive: null,
/*
--商品列表页
*/
//一级
CategoryLists1: [
{
value: '一级',
label: '一级'
}
],
categoryListsActive1: null,
//二级
CategoryLists2: [
{
value: '二级',
label: '二级'
}
],
categoryListsActive2: null,
//三级
CategoryLists3: [
{
value: '三级',
label: '三级'
}
],
categoryListsActive3: null,
// 独立
tagLists: [
{
value: '独立',
label: '独立'
}
],
tagListsActive: null,
/*
--商品
*/
commodityCategoryLists1: [
{
value: '商品一级',
label: '商品一级'
}
],
commoditycategoryListsActive1: null,
//二级
commodityCategoryLists2: [
{
value: '商品二级',
label: '商品二级'
}
],
commoditycategoryListsActive2: null,
//三级
commodityCategoryLists3: [
{
value: '商品三级',
label: '商品三级'
}
],
commoditycategoryListsActive3: null,
// 搜索
search: null,
showList: true,
title: null,
tbCfActivity: {},
ruleValidate: {
name: [
{required: true, message: '名称不能为空', trigger: 'blur'}
]
},
chooseOptions1: [{
value: 0,
label: '不启用'
}, {
value: 1,
label: '启用'
}],
isShow: false,
showList: true,
title: null,
tbCfActivity: {},
ruleValidate: {
name: [
{required: true, message: '名称不能为空', trigger: 'blur'}
]
},
q: {
name: ''
}
},
methods: {
tirggerFile: function (event) {
var file = event.target.files[0];
var formData = new FormData();
formData.append("file", file);
$.ajax({
url: "../api/upload/image/",
type: "POST",
data: formData,
cache: false, //不设置缓存
processData: false, // 不处理数据
contentType: false,// 不设置内容类型
success: function (result) {
result = JSON.parse(result);
//console.log(result)
if (result.errno == 0) {//成功
vm.tbCfActivity.activityImage = result.data;
vm.$forceUpdate();
} else {
iview.Message.error(result.errmsg);
}
}
});
},
tirggerFile1: function (event) {
var file = event.target.files[0];
var formData = new FormData();
formData.append("file", file);
$.ajax({
url: "../api/upload/image/",
type: "POST",
data: formData,
cache: false, //不设置缓存
processData: false, // 不处理数据
contentType: false,// 不设置内容类型
success: function (result) {
result = JSON.parse(result);
//console.log(result)
if (result.errno == 0) {//成功
vm.tbCfActivity.activityButton = result.data;
vm.$forceUpdate();
} else {
iview.Message.error(result.errmsg);
}
}
});
},
query: function () {
vm.reload();
},
add: function () {
vm.resetSelectedCategory();
vm.resetSelectedCategory('commodity');
vm.tbCfActivity.activityImage = null;
vm.tbCfActivity.activityButton = null;
vm.isShow = false;
vm.showList = false;
vm.title = "新增";
vm.tbCfActivity = {};
},
update: function (event) {
let id = getSelectedRow("#jqGrid");
if (id == null) {
return;
}
vm.showList = false;
vm.title = "修改";
vm.getInfo(id);
},
saveOrUpdate: function (event) {
vm.tbCfActivity.activityLink = event;
vm.tbCfActivity.activityType = this.typeActive;
let url = vm.tbCfActivity.id == null ? "../tbcfactivity/save" : "../tbcfactivity/update";
if (!vm.isShow) {
vm.tbCfActivity.isTop = 0
} else {
vm.tbCfActivity.isTop = 1
}
Ajax.request({
url: url,
params: JSON.stringify(vm.tbCfActivity),
type: "POST",
contentType: "application/json",
successCallback: function (r) {
alert('操作成功', function (index) {
vm.reload();
});
}
});
},
del: function (event) {
let ids = getSelectedRows("#jqGrid");
if (ids == null) {
return;
}
confirm('确定要删除选中的记录?', function () {
Ajax.request({
url: "../tbcfactivity/delete",
params: JSON.stringify(ids),
type: "POST",
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.reload();
});
}
});
});
},
getInfo: function (id) {
vm.resetSelectedCategory('commodity');
Ajax.request({
url: "../tbcfactivity/info/" + id,
async: true,
successCallback: function (r) {
vm.tbCfActivity = r.tbCfActivity;
//数据回显
vm.typeActive = vm.tbCfActivity.activityType;
vm.vHandleChange(null, vm.typeActive)
if (vm.typeActive === 0) {
vm.link = vm.tbCfActivity.activityLink;
} else if (vm.typeActive === 1) {
let ARR_ids = vm.tbCfActivity.activityLink.split(',');
vm.CategoryLists1.forEach(item => {
if (item.value === ARR_ids[0]) {
vm.categoryListsActive1 = item.value
}
})
if (ARR_ids[1] != 'null') {
vm.changeSubCateType(() => {
vm.CategoryLists2.forEach(item => {
if (item.value === ARR_ids[1]) {
vm.categoryListsActive2 = item.value
}
})
});
}
if (ARR_ids[2] != 'null') {
vm.queryMiniCatagory(2, () => {
vm.CategoryLists3.forEach(item => {
if (item.value === ARR_ids[2]) {
vm.categoryListsActive3 = item.value
}
})
});
}
} else if (vm.typeActive === 2) {
setTimeout(() => {
vm.handleSearch(vm.tbCfActivity.activityLink);
}, 500)
} else if (vm.typeActive === 3) {
vm.tagListsActive = vm.tbCfActivity.activityLink;
}
}
});
},
reload: function (event) {
vm.showList = true;
let page = $("#jqGrid").jqGrid('getGridParam', 'page');
$("#jqGrid").jqGrid('setGridParam', {
postData: {'name': vm.q.name},
page: page
}).trigger("reloadGrid");
vm.handleReset('formValidate');
},
reloadSearch: function () {
vm.q = {
name: ''
};
vm.reload();
},
handleSubmit: function (name) {
let linkUrl = null;
let activityType = this.typeActive; //海报类型
switch (this.typeActive) {
case 0:
linkUrl = this.link;
linkUrl ? vm.saveOrUpdate(linkUrl) : this.$Message.info('请输入链接')
break;
case 1:
this.categoryListsActive1 ? (() => {
linkUrl = `${this.categoryListsActive1},${this.categoryListsActive2},${this.categoryListsActive3}`;
vm.saveOrUpdate(linkUrl)
})() : this.$Message.info('至少选择一种分类')
break;
case 2:
linkUrl = getSelectedRows("#searchjqGrid")[0];
if (linkUrl) {
vm.saveOrUpdate(linkUrl)
}
break;
case 3:
linkUrl = this.tagListsActive;
if (linkUrl) {
vm.saveOrUpdate(linkUrl)
}
break;
default :
vm.saveOrUpdate('')
break;
}
// handleSubmitValidate(this, name, function () {
// vm.saveOrUpdate()
// });
},
handleReset: function (name) {
handleResetForm(this, name);
},
$(name) {
return document.querySelectorAll(name);
},
//切换海报导航定向方式
vHandleChange(element, _index) {
this.items.forEach((item, index) => {
item.isChecked = false
})
this.typeActive = _index;
this.items[_index].isChecked = true;
},
/* 重置选中的类别 */
resetSelectedCategory(e) {
if (e === 'commodity') {
this.search = this.commoditycategoryListsActive1 = this.commoditycategoryListsActive2 = this.commoditycategoryListsActive3 = null;
} else {
this.categoryListsActive = this.categoryListsActive3 = this.categoryListsActive2 = this.categoryListsActive1 = null;
}
},
/* 搜索 */
handleSearch(e) {
1 == 1 ? (() => {
$('#showItems').children().remove();
$('#showItems').append(`<table id="searchjqGrid"></table>`);
function beforeSelectRow() {
$("#searchjqGrid").jqGrid('resetSelection');
return (true);
}
let _this = this;
$(function () {
$("#searchjqGrid").Grid({
url: `../tbcfstationitem/list?itemCategory=${_this.commoditycategoryListsActive1 || ''}&typeTwo=${_this.commoditycategoryListsActive2 || ''}&typeThree=${_this.commoditycategoryListsActive3 || ''}&name=${vm.search || e || ''}`,
colModel: [
{label: 'itemId', name: 'itemId', index: 'item_id', key: true, hidden: true},
{label: '商品图片', name: 'itemImg', index: 'item_img', width: 50, formatter: imageFormat},
{label: '商品编号', name: 'itemCode', index: 'item_code', width: 160},
{label: '商品名称', name: 'itemName', index: 'item_name', width: 160},
/* {label: '商品标题', name: 'itemBrief', index: 'item_brief', width: 120},*/
/*{label: '商品链接', name: 'itemUrl', index: 'item_url', width: 80,formatter:linkFormat},*/
{label: '商品原价', name: 'itemPrice', index: 'item_price', width: 65},
{label: '商品现价', name: 'discountPrice', index: 'discount_price', width: 55},
{label: '库存', name: 'itemCount', index: 'item_count', width: 55},
{label: '点击量', name: 'itemNum', index: 'item_num', width: 55},
/*{label: '所属平台', name: 'platformCode', index: 'platform_code', width: 80},
{label: '平台名', name: 'platformName', index: 'platform_name', width: 80},*/
{label: '供应商', name: 'supplier', index: 'supplier', width: 80},
{label: '商品一级分类', name: 'goodtype', index: 'goodtype', width: 80},
{label: '商品二级分类', name: 'title', index: 'title', width: 80},
{label: '商品品名', name: 'dname', index: 'itemDescritionId', width: 120},
{
label: '状态',
name: 'enableFlag',
index: 'enable_flag',
width: 120,
formatter: itemStatusFormat
},
{label: '创建日期', name: 'createTime', index: 'create_time', width: 160}
],
multiselect: true,
multiboxonly: true,
beforeSelectRow: beforeSelectRow,
});
});
})() : alert('未输入搜索内容~');
},
//获取分类子页面二级分类数据
changeSubCateType(callback = null) {
let ID = null;
if (this.typeActive === 1000) {
ID = this.subcategoryListsActive
} else if (this.typeActive === 1) {
ID = this.categoryListsActive1
} else {
ID = this.commoditycategoryListsActive1
}
this.subsubCategoryLists = [];
this.CategoryLists2 = [];
this.commodityCategoryLists2 = [];
$.get('../tbcfstationitem/queryByItemType?typeId=' + ID, res => {
let _res = JSON.parse(res);
_res.code === 0 ? (() => {
if (this.typeActive === 1000) {
_res.list.forEach((item) => {
this.subsubCategoryLists.push({
label: item.goodstwotypeTitle,
value: item.goodstwotypeId
})
})
} else if (this.typeActive === 1) {
_res.list.forEach((item) => {
this.CategoryLists2.push({
label: item.goodstwotypeTitle,
value: item.goodstwotypeId
})
})
} else {
_res.list.forEach((item) => {
this.commodityCategoryLists2.push({
label: item.goodstwotypeTitle,
value: item.goodstwotypeId
})
})
}
callback ? callback() : null;
})() : null
})
},
//查询三级分类
queryMiniCatagory(status, callback = null) {
let ID = null
status === 2 ? ID = this.categoryListsActive2 : ID = this.commoditycategoryListsActive2
$.get('../tbcfstationitem/queryByItemTypeTwo?typeTwoId=' + ID, res => {
this.CategoryLists3 = [];
this.commodityCategoryLists3 = [];
let _res = JSON.parse(res);
_res.code === 0 ? (() => {
_res.descripiton.forEach((item) => {
this.CategoryLists3.push({
label: item.descripitionName,
value: item.descripitionId
})
this.commodityCategoryLists3.push({
label: item.descripitionName,
value: item.descripitionId
})
})
callback ? callback() : null;
})() : null
})
}
},
created() {
document.onkeydown = (e) => {
if (this.search && e.keyCode === 13) {
this.handleSearch()
}
}
//获取分类子页面一级分类数据
$.get('../tbcfgoodstype/queryAll', res => {
res.code === 0 ? (() => {
this.subCategoryLists = [];
this.commodityCategoryLists1 = [];
this.CategoryLists1 = [];
res.list.forEach((item) => {
this.subCategoryLists.push({
label: item.goodstypeTitle,
value: item.goodstypeId
});
this.commodityCategoryLists1.push({
label: item.goodstypeTitle,
value: item.goodstypeId
});
this.CategoryLists1.push({
label: item.goodstypeTitle,
value: item.goodstypeId
})
})
})() : null
})
//获取标签
$.get('../tbcflabel/queryAll?timestamp=' + new Date().getTime(), res => {
this.tagLists = [];
let OBJ_res = JSON.parse(res);
OBJ_res.list.forEach((item) => {
console.log('labelName', item.labelName)
this.tagLists.push({
label: item.labelName,
value: item.id
});
})
})
},
mounted() {
}
});
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论