owners_610

This commit is contained in:
dengbw
2022-06-10 09:50:57 +08:00
committed by lccsw
parent 665f0542ba
commit 39fa545ce7
7 changed files with 557 additions and 1 deletions
+202
View File
@@ -0,0 +1,202 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class OwnersTag extends HD_Controller
{
private $tabAry = [1 => ['title' => '客户标签', 'url' => '/receiver/tag'], 2 => ['title' => '车主标签', 'url' => '/receiver/ownersTag']];
public function __construct()
{
parent::__construct();
$this->load->model('receiver/receiver_owners_tag_model', 'mdOwnersTag');
}
//首页信息
public function index()
{
return $this->lists();
}
//数据列表
public function lists()
{
$params = $this->input->get();
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 20;
$params['tab'] = 2;
$statusAry = $this->mdOwnersTag->statusAry();
$typeAry = $this->mdOwnersTag->typeAry();
$lists = array();
$where = ["status<>-1" => null, 'pid' => 0];
if (strlen($params['status'])) {
$where['status'] = $params['status'];
}
if ($params['type']) {
$where['type'] = $params['type'];
}
$count = $this->mdOwnersTag->count($where);
if ($count) {
$res = $this->mdOwnersTag->select($where, "sort desc,id desc", $params['page'], $params['size']);
foreach ($res as $key => $value) {
$setValue = array();
$setValue['id'] = $value['id'];
$setValue['name'] = $value['name'];
$setValue['sort'] = $value['sort'];
$setValue['type_name'] = $typeAry[$value['type']];
$setValue['status'] = $value['status'];
$setValue['status_name'] = $statusAry[$value['status']];
$options = '';
$res_tag = $this->mdOwnersTag->select(["status" => 1, 'pid' => $value['id']], "sort desc,id desc", 0, 0, 'id,name,sort');
$res_tag && $options = implode(',', array_column($res_tag, 'name'));
$setValue['options'] = $options;
$lists[] = $setValue;
}
}
$this->data['lists'] = $lists;
$this->data['params'] = $params;
$this->data['showInfo'] = ['statusAry' => $statusAry, 'typeAry' => $typeAry, 'tabAry' => $this->tabAry];
$this->data['_title'] = '车主标签列表';
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
return $this->show_view('receiver/ownerstag/lists', true);
}
public function get_options()
{
$id = intval($this->input->post('id'));
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$res_tag = $this->mdOwnersTag->select(["status" => 1, 'pid' => $id], "sort desc,id desc", 0, 0, 'id,name,sort,status');
$this->data['lists'] = $res_tag;
return $this->show_json(SYS_CODE_SUCCESS);
}
//展示单条数据
public function get()
{
$id = intval($this->input->get('id'));
if ($id) {
$url = "receiver/ownersTag/edit";
$re = $this->mdOwnersTag->get(['id' => $id]);
if (!$re) {
return $this->show_json(SYS_CODE_FAIL, '车主标签不存在!');
}
$name = $re['name'];
$sort = $re['sort'];
$type = $re['type'];
} else {
$url = "receiver/ownersTag/add";
$name = '';
$sort = 0;
$type = 'checkbox';
}
$this->data['showInfo'] = ['id' => $id, 'name' => $name, 'sort' => $sort, 'type' => $type,
'typeAry' => $this->mdOwnersTag->typeAry(), 'url' => $url];
return $this->show_view('receiver/ownerstag/edit');
}
//添加单条数据
public function add()
{
$params = $this->input->post();
if (!$params['name']) {
return $this->show_json(SYS_CODE_FAIL, '标签名称不能为空!');
}
$re = $this->mdOwnersTag->get(array('name' => $params['name']));
if ($re) {
return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!');
}
$id = $this->mdOwnersTag->add(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']]);
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
//编辑单条数据
public function edit()
{
$params = $this->input->post();
if (!$params['id']) {
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
if (!$params['name']) {
return $this->show_json(SYS_CODE_FAIL, '请输入标签名称');
}
$re = $this->mdOwnersTag->get(array('name' => $params['name'], 'status' => 1));
if ($re && $re['id'] != $params['id']) {
return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!');
}
$this->mdOwnersTag->update(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']],
['id' => $params['id']]);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
//删除单条数据
public function del()
{
$id = $this->input->post('id');
if (!$id) {
$this->show_json(SYS_CODE_FAIL, '参数错误');
}
$re = $this->mdOwnersTag->get(['id' => $id]);
if (!$re) {
return $this->show_json(SYS_CODE_FAIL, '标签不存在!');
}
$this->mdOwnersTag->update(['status' => '-1'], ['id' => $id]);
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
//修改标签选项
function edit_options()
{
$pid = $this->input->post('id');
$options = $this->input->post('options');
if (!$pid || !$options) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$re = $this->mdOwnersTag->get(['id' => $pid]);
if (!$re) {
return $this->show_json(SYS_CODE_FAIL, '车主标签不存在!');
}
$add_tag = $edit_tag = [];
foreach ($options as $key => $value) {
$sort = intval($value['sort']);
$data = ['name' => $value['name'], 'status' => $value['status'], 'sort' => $sort];
if ($value['name']) {
if ($value['id']) {//修改
$this->mdOwnersTag->update($data, ['id' => $value['id']]);
} else {//新增
$add_tag[] = ['name' => $value['name'], 'order' => $sort];
$data['pid'] = $pid;
$this->mdOwnersTag->add($data);
}
}
}
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
function edit_status()
{
$id = $this->input->post('id');
$stauts = intval($this->input->post('status'));
if (!$id) {
$this->show_json(SYS_CODE_FAIL, '参数错误');
}
$this->mdOwnersTag->update(['status' => $stauts], ['id' => $id]);
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
//批量操作(默认修改状态)
public function batch()
{
}
//导出数据列表
public function export()
{
}
}
+3 -1
View File
@@ -4,6 +4,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
class Tag extends HD_Controller
{
private $tabAry = [1 => ['title' => '客户标签', 'url' => '/receiver/tag'], 2 => ['title' => '车主标签', 'url' => '/receiver/ownersTag']];
public function __construct()
{
@@ -23,6 +24,7 @@ class Tag extends HD_Controller
$params = $this->input->get();
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 20;
$params['tab'] = 1;
$statusAry = $this->mdCustomerTag->statusAry();
$typeAry = $this->mdCustomerTag->typeAry();
$showAry = $this->mdCustomerTag->showAry();
@@ -58,7 +60,7 @@ class Tag extends HD_Controller
}
$this->data['lists'] = $lists;
$this->data['params'] = $params;
$this->data['showInfo'] = ['statusAry' => $statusAry, 'typeAry' => $typeAry, 'showAry' => $showAry];
$this->data['showInfo'] = ['statusAry' => $statusAry, 'typeAry' => $typeAry, 'showAry' => $showAry, 'tabAry' => $this->tabAry];
$this->data['_title'] = '客户标签列表';
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
return $this->show_view('/receiver/tag/lists', true);
+31
View File
@@ -0,0 +1,31 @@
<form id="vue-edit" class="am-form am-form-horizontal" action="<?= $showInfo['url'] ?>" data-auto="true"
method="post" style="width: 90%;padding-top: 10px" onsubmit="return false">
<input type="hidden" value="<?= $showInfo['id'] ?>" name="id"/>
<div class="am-form-group">
<label class="am-para-label">名称:</label>
<div class="am-para-input">
<input type="text" placeholder="输入名称" value="<?= $showInfo['name'] ?>" name="name"/>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">选项类型:</label>
<div class="am-para-input" style="width: 30%">
<select name="type">
<? foreach ($showInfo['typeAry'] as $key => $value) { ?>
<option value="<?= $key ?>" <?= $key == $showInfo['type'] ? 'selected' : '' ?>
><?= $value ?></option>
<? } ?>
</select>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">排序:</label>
<div class="am-para-input" style="width: 30%">
<input type="text" placeholder="输入排序" value="<?= $showInfo['sort'] ?>" name="sort"/>
<small class="text-muted">越大越靠前</small>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<button class="am-btn ml20 am-btn-sm am-btn-success w100" style="margin-left: 3.5rem" type="submit">保存</button>
</div>
</form>
+249
View File
@@ -0,0 +1,249 @@
<div class="bs-example bs-example-tabs" data-example-id="togglable-tabs" style="font-size:15px;margin-bottom: 20px;">
<ul class="nav nav-tabs" role="tablist">
<? foreach ($showInfo['tabAry'] as $key => $val) { ?>
<li role="presentation"
class="<?= strlen($params['tab']) && $params['tab'] == $key ? 'active' : '' ?>">
<a href="javascript:void (0);" data-open="<?= $val['url'] ?>">
<?= $val['title'] ?>
</a>
</li>
<? } ?>
</ul>
</div>
<div class="coms-table-wrap mt10">
<form id="vue-app" class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="receiver/ownersTag">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w80">类型:</label>
<div class="am-para-inline w100">
<select name="type">
<option value="">选择类型</option>
<? foreach ($showInfo['typeAry'] as $key => $value) { ?>
<option value="<?= $key ?>" <?= $key == $params['type'] ? 'selected' : '' ?>
><?= $value ?></option>
<? } ?>
</select>
</div>
</div>
<div class="am-form-group fl">
<label class="am-para-label w80">状态:</label>
<div class="am-para-inline w100">
<select name="status">
<option value="">选择状态</option>
<? foreach ($showInfo['statusAry'] as $key => $value) { ?>
<option value="<?= $key ?>" <?= strlen($params['status']) && $key == $params['status'] ? 'selected' : '' ?>
><?= $value ?></option>
<? } ?>
</select>
</div>
</div>
<div class="am-form-group fl ml30">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
<div class="am-form-group fl ml10">
<button data-modal="/receiver/ownersTag/get" type="button" data-title="新增标签"
class="am-btn am-btn-success am-btn-sm w100">
新增
</button>
</div>
</div>
</div>
</form>
<div class="coms-table-bd" id="vue-show">
<div class="fr">共有<?= $pager['totle'] ?>条数据</div>
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="25%"><span>名称</span></th>
<th width="45%"><span>标签选项</span></th>
<th width="7%"><span>类型</span></th>
<th width="5%"><span>排序</span></th>
<th width="5%"><span>状态</span></th>
</tr>
</thead>
<tbody>
<?php if ($lists) {
foreach ($lists as $v) { ?>
<tr>
<td><?= $v['name'] ?></td>
<td><?= $v['options'] ?></td>
<td><?= $v['type_name'] ?></td>
<td><?= $v['sort'] ?></td>
<td><?= $v['status_name'] ?></td>
</tr>
<tr>
<td colspan="5" class="align-r">
<a href="javascript:void(0);" @click="optionsModal(<?= $v['id'] ?>,'<?= $v['name'] ?>')"
class="am-btn am-btn-primary am-btn-xs">编辑选项</a>
<a href="javascript:void(0);" data-modal="/receiver/ownersTag/get?id=<?= $v['id'] ?>"
data-title="编辑标签" class="am-btn am-btn-primary am-btn-xs">编辑标签</a>
<? if ($v['status'] == 1) { ?>
<a data-ajax="post" data-action="/receiver/ownersTag/edit_status"
class="am-btn am-btn-danger am-btn-xs"
data-params-id="<?= $v['id'] ?>" data-params-status="0">关闭</a>
<?
} ?>
<? if ($v['status'] == 0) { ?>
<a data-ajax="post" data-action="/receiver/ownersTag/edit_status"
class="am-btn am-btn-success am-btn-xs"
data-params-id="<?= $v['id'] ?>" data-params-status="1">开启</a>
<? } ?>
<a data-ajax="post" data-action="/receiver/ownersTag/del"
class="am-btn am-btn-danger am-btn-xs"
data-params-id="<?= $v['id'] ?>">删除</a>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
<div id="options-modal" style="display: none;">
<table class="table table-hover table-middle" style="table-layout:fixed">
<colgroup>
<col width="65%">
<col width="15%">
<col width="">
</colgroup>
<thead>
<tr>
<th class="text-center">标题</th>
<th class="text-center">排序</th>
<th class="text-right">
<a href="javascript:" style="margin-top: 2px;" class="btn btn-primary btn-sm"
@click='addOptions()'>添加</a>
</th>
</tr>
</thead>
<tbody>
<template v-for="(item,index) in optionsList">
<tr v-if="item.status==1">
<td class="text-center">
<input :id="'name_'+index" @blur="editName(index)" class="form-control"
v-model="item.name" placeholder="请输入标题"></td>
<td class="text-center">
<input :id="'group_name_'+index" @blur="editGroupName(index)" class="form-control"
v-model="item.sort" type="number" placeholder="请输入排序值">
</td>
<td class="text-right">
<a href="javascript:void(0);" style="margin-top:2px;"
class="btn btn-danger btn-sm" @click='delOptions(index)'>删除</a>
</td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
<div class="coms-table-ft clearfix">
<div class="hander am-form">
</div>
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
var vue_obj;
$(function () {
vue_obj = new Vue({
el: '#vue-show',
data: {
optionsList: [],
},
mounted: function () {
},
methods: {
optionsModal: function (id, name) {
layer.open({
type: 1,
area: ['50%', '50%'], //宽高
content: $('#options-modal'),
title: '编辑【' + name + '】选项',
shade: false,
btn: ['保存', '取消'],
yes: function (index) {
$.ajax({
url: '/receiver/ownersTag/edit_options',
type: 'post',
dataType: 'json',
data: {id: id, options: that.optionsList},
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
$.form.reload();
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
layer.closeAll('loading');
}
});
}
});
var that = this;
$.ajax({
url: '/receiver/ownersTag/get_options',
type: 'post',
dataType: 'json',
data: {id: id},
beforeSend: function () {
},
success: function (re) {
if (re.code) {
that.optionsList = re.data.lists;
} else {
layer.msg(re.msg, {icon: 2});
}
},
complete: function () {
}
});
},
addOptions: function () {
var that = this;
that.optionsList.push({id: 0, name: '', status: 1, qy_id: '', sort: 50});
},
delOptions: function (index) {
var that = this;
if (that.optionsList[index]['id'] > 0) {
that.optionsList[index]['status'] = -1;
} else {
that.optionsList.splice(index, 1);
}
},
editName: function (index) {
var name = $("#name_" + index).val();
if (name == '') {
layer.msg("标题不能为空!", {icon: 2});
return false;
}
},
// 修改排序
editGroupName: function (index) {
var order_view = $("#group_name_" + index).val();
if (order_view == '') {
layer.msg("排序值不能为空!", {icon: 2});
return false;
}
this.optionsList.sort(function (a, b) {
return b.sort - a.sort;
})
},
},
watch: {}
});
<?php page_script($pager) ?>
});
</script>
+12
View File
@@ -1,3 +1,15 @@
<div class="bs-example bs-example-tabs" data-example-id="togglable-tabs" style="font-size:15px;margin-bottom: 20px;">
<ul class="nav nav-tabs" role="tablist">
<? foreach ($showInfo['tabAry'] as $key => $val) { ?>
<li role="presentation"
class="<?= strlen($params['tab']) && $params['tab'] == $key ? 'active' : '' ?>">
<a href="javascript:void (0);" data-open="<?= $val['url'] ?>">
<?= $val['title'] ?>
</a>
</li>
<? } ?>
</ul>
</div>
<div class="coms-table-wrap mt10">
<form id="vue-app" class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="receiver/tag">
@@ -0,0 +1,42 @@
<?php
/**
* Notes:车主标签表
* Created on: 2022/6/09 10:31
* Created by: dengbw
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Receiver_owners_tag_model extends HD_Model
{
private $table_name = 'lc_receiver_owners_tag';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
/**
* Notes:选项类型
* Created on: 2022/3/15 14:07
* Created by: dengbw
* @return array
*/
public function typeAry()
{
return ['checkbox' => '多选', 'radio' => '单选'];
}
/**
* Notes:状态
* Created on: 2021/7/27 10:31
* Created by: dengbw
* @return array
*/
public function statusAry()
{
return [1 => '正常', 0 => '禁用'];
}
}
@@ -0,0 +1,18 @@
<?php
/**
* Notes:车主标签关系表
* Created on: 2022/6/09 10:31
* Created by: dengbw
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Receiver_owners_tagdata_model extends HD_Model
{
private $table_name = 'lc_receiver_owners_tagdata';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
}