|
@@ -7,15 +7,15 @@
|
|
* @date 2018/9/26
|
|
* @date 2018/9/26
|
|
* @version
|
|
* @version
|
|
*/
|
|
*/
|
|
-
|
|
|
|
|
|
+let editCate;
|
|
|
|
+// 初始化分类数据
|
|
function InitCategoryData(category) {
|
|
function InitCategoryData(category) {
|
|
const data = category instanceof Array ? category : [category];
|
|
const data = category instanceof Array ? category : [category];
|
|
for (const d of data) {
|
|
for (const d of data) {
|
|
- // d.valueArr = d.value && d.value !== '' ? JSON.parse(d.value) : [];
|
|
|
|
d.typeStr = cType.text[d.type];
|
|
d.typeStr = cType.text[d.type];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+// 获取自定义分类可选类型Html(下拉、单选)
|
|
function getTypeHtml() {
|
|
function getTypeHtml() {
|
|
const html = [];
|
|
const html = [];
|
|
for (const k in cType.key) {
|
|
for (const k in cType.key) {
|
|
@@ -27,7 +27,7 @@ function getTypeHtml() {
|
|
}
|
|
}
|
|
return html.join('');
|
|
return html.join('');
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+// 获取自定义分类html
|
|
function getCategoryHtml(category) {
|
|
function getCategoryHtml(category) {
|
|
const data = category instanceof Array ? category : [category];
|
|
const data = category instanceof Array ? category : [category];
|
|
const html = [];
|
|
const html = [];
|
|
@@ -53,36 +53,19 @@ function getCategoryHtml(category) {
|
|
}
|
|
}
|
|
return html.join('');
|
|
return html.join('');
|
|
}
|
|
}
|
|
-
|
|
|
|
-function getValueTenderCount(value) {
|
|
|
|
- function findTenderCate(tender) {
|
|
|
|
- for (const c of tender.category) {
|
|
|
|
- if (c.cid == value.cid) {
|
|
|
|
- return c;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- const valueTender = tenders.filter(function (t) {
|
|
|
|
- const cate = findTenderCate(t);
|
|
|
|
- console.log(cate);
|
|
|
|
- return cate ? cate.value == value.id : false;
|
|
|
|
- });
|
|
|
|
- return valueTender ? valueTender.length : 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
|
|
+// 获取分类值html
|
|
function getValueHtml(value) {
|
|
function getValueHtml(value) {
|
|
const html = [];
|
|
const html = [];
|
|
for (const v of value) {
|
|
for (const v of value) {
|
|
- html.push('<tr name="value">');
|
|
|
|
|
|
+ html.push('<tr name="value" vid="' + v.id + '">');
|
|
html.push('<td><input class="form-control form-control-sm" name="value" placeholder="请输入值" value="' + v.value + '" vid ="' + v.id + '"></td>');
|
|
html.push('<td><input class="form-control form-control-sm" name="value" placeholder="请输入值" value="' + v.value + '" vid ="' + v.id + '"></td>');
|
|
- console.log(v);
|
|
|
|
- html.push('<td>', getValueTenderCount(v) ,'</td>');
|
|
|
|
- html.push('<td><a href="javasrcipt: void(0);" class="text-danger">删除</a></td>');
|
|
|
|
|
|
+ html.push('<td>', v.relaTenders.length + v.newTenders.length ,'</td>');
|
|
|
|
+ html.push('<td><a href="javasrcipt: void(0);" class="text-danger" name="del-value" vid="' + v.id + '">删除</a></td>');
|
|
html.push('</tr>');
|
|
html.push('</tr>');
|
|
}
|
|
}
|
|
return html.join('');
|
|
return html.join('');
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+// 根据分类id查找分类
|
|
function findCategory(cid) {
|
|
function findCategory(cid) {
|
|
for (const c of cData) {
|
|
for (const c of cData) {
|
|
if (c.id === cid) {
|
|
if (c.id === cid) {
|
|
@@ -90,19 +73,107 @@ function findCategory(cid) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+// 删除值 获取其他可用值的html
|
|
|
|
+function getValidValueHtml(vid) {
|
|
|
|
+ const html = [];
|
|
|
|
+ const values = $('tr:not(.table-danger)[name=value]', '#value-list');
|
|
|
|
+ for (const value of values) {
|
|
|
|
+ const v = $(value);
|
|
|
|
+ if (v.attr('vid') === vid || $('input', v).val() === '') { continue }
|
|
|
|
+ html.push('<div class="form-check form-check-inline">');
|
|
|
|
+ html.push('<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio' + v.attr('vid') + '" value="' + v.attr('vid') +'">');
|
|
|
|
+ html.push('<label class="form-check-label" for="inlineRadio' + v.attr('vid') + '">' + $('input', v).val() + '</label>');
|
|
|
|
+ html.push('</div>');
|
|
|
|
+ }
|
|
|
|
+ return html.join('');
|
|
|
|
+}
|
|
|
|
+// 初始化 添加值 编辑数据
|
|
|
|
+function getEditCate(category) {
|
|
|
|
+ function findTenderCate(tender, value) {
|
|
|
|
+ for (const c of tender.category) {
|
|
|
|
+ if (c.cid == value.cid) {
|
|
|
|
+ return c;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ editCate = JSON.parse(JSON.stringify(category));
|
|
|
|
+ for (const v of editCate.value) {
|
|
|
|
+ v.relaTenders = tenders.filter(function (t) {
|
|
|
|
+ const cate = findTenderCate(t, v);
|
|
|
|
+ return cate ? cate.value == v.id : false;
|
|
|
|
+ });
|
|
|
|
+ v.newTenders = [];
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+// 绑定编辑值、删除值
|
|
|
|
+function bindCategoryValueControl() {
|
|
|
|
+ $('a[name="del-value"]').click(function () {
|
|
|
|
+ const vid = $(this).attr('vid');
|
|
|
|
+ const value = _.find(editCate.value, function (v) {
|
|
|
|
+ return v.id == vid;
|
|
|
|
+ });
|
|
|
|
+ if (value.delete) { return; }
|
|
|
|
|
|
|
|
+ if (value.relaTenders.length > 0) {
|
|
|
|
+ // 提示用户转移标段
|
|
|
|
+ $('#tender-count').text(value.relaTenders.length).attr('vid', vid);
|
|
|
|
+ $('#tender-target').html(getValidValueHtml(vid));
|
|
|
|
+ $('input[type=radio]', '#tender-target')[0].checked = true;
|
|
|
|
+ $('#del-cate-value-ok').click(function () {
|
|
|
|
+ const delVid = $('#tender-count').attr('vid');
|
|
|
|
+ const tarVid = $('input:checked', '#tender-target').val();
|
|
|
|
+ const delValue = _.find(editCate.value, function (v) {
|
|
|
|
+ return v.id == delVid;
|
|
|
|
+ });
|
|
|
|
+ const tarValue = _.find(editCate.value, function (v) {
|
|
|
|
+ return v.id == tarVid;
|
|
|
|
+ });
|
|
|
|
+ tarValue.newTenders = tarValue.newTenders.concat(delValue.relaTenders, delValue.newTenders);
|
|
|
|
+ delValue.relaTenders = [];
|
|
|
|
+ delValue.newTenders = [];
|
|
|
|
+ delValue.delete = true;
|
|
|
|
+ const delTr = $('tr[vid=' + delVid + ']');
|
|
|
|
+ delTr.addClass('table-danger');
|
|
|
|
+ $('input', delTr).attr('disabled', '');
|
|
|
|
+ delTr.children()[1].innerText = '移动到其他项';
|
|
|
|
+ $('tr[vid=' + tarVid + ']').children()[1].innerText = tarValue.relaTenders.length + tarValue.newTenders.length;
|
|
|
|
+ $('#del-cate-value').modal('hide');
|
|
|
|
+ });
|
|
|
|
+ $('#del-cate-value').modal('show');
|
|
|
|
+ } else {
|
|
|
|
+ value.delete = true;
|
|
|
|
+ const tr = $('tr[vid=' + vid + ']');
|
|
|
|
+ tr.addClass('table-danger');
|
|
|
|
+ $('input', tr).attr('disabled', '');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+// 绑定分类控制等(添加值、编辑、删除)
|
|
function bindCategoryControl() {
|
|
function bindCategoryControl() {
|
|
// 弹出添加值
|
|
// 弹出添加值
|
|
$('a[name=add]').bind('click', function () {
|
|
$('a[name=add]').bind('click', function () {
|
|
const id = parseInt($(this).attr('cid'));
|
|
const id = parseInt($(this).attr('cid'));
|
|
const category = findCategory(id);
|
|
const category = findCategory(id);
|
|
|
|
+ getEditCate(category);
|
|
$('#add-ok').attr('cid', id);
|
|
$('#add-ok').attr('cid', id);
|
|
- if (category) {
|
|
|
|
|
|
+ if (editCate) {
|
|
const list = $('#value-list');
|
|
const list = $('#value-list');
|
|
- list.html(getValueHtml(category.value) + '<tr id="add-value-row"><td colspan="3"><a href="javascript: void(0);">添加新值</a></td></tr>');
|
|
|
|
|
|
+ list.html(getValueHtml(editCate.value) + '<tr id="add-value-row"><td colspan="3"><a href="javascript: void(0);">添加新值</a></td></tr>');
|
|
$('#add-value-row').click(function () {
|
|
$('#add-value-row').click(function () {
|
|
- $(this).before('<tr><td><input class="form-control form-control-sm" name="value" placeholder="请输入值"></td><td>0</td><td><a href="javasrcipt: void(0);" class="text-danger">删除</a></td></tr>');
|
|
|
|
|
|
+ const newID = _.maxBy(editCate.value, function (v) { return v.id; }).id + 1;
|
|
|
|
+ const newValue = {
|
|
|
|
+ isNew: true,
|
|
|
|
+ id: newID,
|
|
|
|
+ value: '',
|
|
|
|
+ relaTenders: [],
|
|
|
|
+ newTenders: [],
|
|
|
|
+ };
|
|
|
|
+ editCate.value.push(newValue);
|
|
|
|
+ $(this).before(getValueHtml([newValue]));
|
|
|
|
+ bindCategoryValueControl();
|
|
});
|
|
});
|
|
|
|
+ bindCategoryValueControl();
|
|
$('#add').modal('show');
|
|
$('#add').modal('show');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -154,16 +225,28 @@ $(document).ready(() => {
|
|
const value = $('input[name=value]');
|
|
const value = $('input[name=value]');
|
|
for (const v of value) {
|
|
for (const v of value) {
|
|
if (v.value !== '') {
|
|
if (v.value !== '') {
|
|
- valueArr.push({
|
|
|
|
- id: $(v).attr('id'),
|
|
|
|
- value: $(v).val(),
|
|
|
|
|
|
+ const cateValue = _.find(editCate.value, function (ec) {
|
|
|
|
+ return $(v).attr('vid') == ec.id;
|
|
});
|
|
});
|
|
|
|
+ let newValue = {};
|
|
|
|
+ if (cateValue.delete) {
|
|
|
|
+ newValue = { id: cateValue.id, delete: true, };
|
|
|
|
+ } else if (cateValue.isNew) {
|
|
|
|
+ newValue = { value: $(v).val(), new: true, };
|
|
|
|
+ } else {
|
|
|
|
+ newValue = { id: cateValue.id, value: $(v).val()};
|
|
|
|
+ }
|
|
|
|
+ if (!cateValue.delete && cateValue.newTenders.length > 0) {
|
|
|
|
+ newValue.newTenders = _.map(cateValue.newTenders, 'id');
|
|
|
|
+ }
|
|
|
|
+ valueArr.push(newValue);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const data = {
|
|
const data = {
|
|
id: parseInt($(this).attr('cid')),
|
|
id: parseInt($(this).attr('cid')),
|
|
- value: valueArr,
|
|
|
|
|
|
+ updateValue: valueArr,
|
|
};
|
|
};
|
|
|
|
+ console.log(data);
|
|
postData('/setting/category/value', data, function (data) {
|
|
postData('/setting/category/value', data, function (data) {
|
|
tenders = data.tenders;
|
|
tenders = data.tenders;
|
|
const category = findCategory(data.category.id);
|
|
const category = findCategory(data.category.id);
|