- @if (PS.Config.Company == CompanyEnum.广发商贸)
- {
-
diff --git a/YLErpWeb/wwwroot/Scripts/app/client/clientMarginTemplateEdit.js b/YLErpWeb/wwwroot/Scripts/app/client/clientMarginTemplateEdit.js
index 39826f00..357c5756 100644
--- a/YLErpWeb/wwwroot/Scripts/app/client/clientMarginTemplateEdit.js
+++ b/YLErpWeb/wwwroot/Scripts/app/client/clientMarginTemplateEdit.js
@@ -1,6 +1,4 @@
-const consClients = ylotc.clients;
-
-//定价格式化(来自配置)
+//定价格式化(来自配置)
const inputFormatPercent = Object.freeze({ precision: 2, append: '%' });
const inputFormatPercentNegative = Object.freeze({ precision: 2, append: '%', negative: true });
const inputFormatNegative = Object.freeze({ precision: 2, negative: true });
@@ -11,20 +9,15 @@ const vue = new Vue({
clientMarginTemplate: page.clientMarginTemplate,
marginTemplates: page.marginTemplates,
marginTemplate: page.marginTemplate,
- clientLevels: [],
clientNames: [],
- isClientLevelDisabled: false,
- isClientNameDisabled: false,
+ //新增模式的客户多选(编辑模式仍为单条绑定,走 clientMarginTemplate.ClientId)
+ selectedClientIds: [],
isAdd: page.isAdd
},
created: function () {
this.clientMarginTemplate.ValueDate = new moment(this.clientMarginTemplate.ValueDate).format("YYYY-MM-DD");
},
methods: {
- //changeClient(yldata) {
- // let client = yldata || { id: 0 };
- // this.clientMarginTemplate.ClientId = client.id;
- //},
changeMarginTemplate() {
this.marginTemplates.forEach(x => {
if (this.clientMarginTemplate.MarginTemplateId === x.id) {
@@ -32,15 +25,54 @@ const vue = new Vue({
$('#suitableType').prop('title', this.marginTemplate.TradeTypes);
}
});
-
+
},
+ //新增=多选:按选中客户逐条调用原有单条保存接口(后端不变,每条走完整互斥校验);
+ //编辑=单条,保持原行为。逐条收集成败,结束统一汇总——部分失败时列表刷新已成功部分,弹窗留在
+ //当前内容上供修正重试(已成功的客户重试会因同天同结构互斥校验失败,不会重复入库)
saveMarginTemplateV2() {
var thisObj = this;
- main.post("/client_margin_template/saveClientMarginTemplate", { clientMarginTemplate: thisObj.clientMarginTemplate }).done(function (resp) {
- try {
- window.parent.reloadmargin_template();
- (parent || window).layer.closeAll();
- } catch (e) { }
+ var ids = this.isAdd ? (this.selectedClientIds || []) : [this.clientMarginTemplate.ClientId];
+ if (!ids.length) {
+ main.message("请至少选择一个客户");
+ return;
+ }
+ if (!this.clientMarginTemplate.MarginTemplateId) {
+ main.message("请选择有效的预付金模板");
+ return;
+ }
+ var okCount = 0;
+ var fails = [];
+ var chain = Promise.resolve();
+ ids.forEach(function (clientId) {
+ chain = chain.then(function () {
+ //深拷贝:逐条改写 ClientId/id,绝不污染 Vue 表单对象(部分失败时弹窗保持打开)
+ var payload = _.cloneDeep(thisObj.clientMarginTemplate);
+ payload.ClientId = clientId;
+ payload.id = thisObj.isAdd ? 0 : thisObj.clientMarginTemplate.id;
+ //alertFn 置空:单条失败不逐个弹窗,由循环结束后统一汇总
+ return main.post("/client_margin_template/saveClientMarginTemplate",
+ { clientMarginTemplate: payload },
+ { alertFn: function () { }, suppressError: true }
+ ).then(function () {
+ okCount++;
+ }, function (resp) {
+ fails.push({ id: clientId, msg: (resp && (resp.msg || resp.errmsg)) || "保存失败" });
+ });
+ });
+ });
+ chain.then(function () {
+ try { window.parent.reloadmargin_template(); } catch (e) { }
+ if (!fails.length) {
+ try { (parent || window).layer.closeAll(); } catch (e) { }
+ return;
+ }
+ var nameOf = function (cid) {
+ var c = thisObj.clientNames.find(function (x) { return String(x.Value) === String(cid); });
+ return c ? c.Text : cid;
+ };
+ var detail = fails.map(function (f) { return nameOf(f.id) + ":" + f.msg; }).join("
");
+ main.alert("成功 " + okCount + " 条,失败 " + fails.length + " 条:
" + detail);
});
},
showTemplateDetail(detail) {
@@ -51,28 +83,6 @@ const vue = new Vue({
vueDetail.ruleType = vue.marginTemplate.RuleType;
$("#myModal").modal("show");
},
- SetClientLevelDropDown() {
- $.ajax({
- type: "get",
- url: "/client_margin_template/GetAllClientLevels",
- success: function (data) {
- if (data.obj) {
- for (var i = 0; i < data.obj.length; i++) {
- vue.clientLevels.push(data.obj[i]);
- }
-
- if (vue.isAdd) {
- vue.clientMarginTemplate.ClientLevel = data.obj[0].Value;
- }
-
-
- }
- },
- error: function (msg) {
- alert("error:" + msg);
- }
- });
- },
SetClientNameDropDown() {
$.ajax({
type: "get",
@@ -84,6 +94,14 @@ const vue = new Vue({
vue.clientNames.push(data.obj[i]);
}
}
+ //选项就位后再初始化/刷新 chosen(多选客户),并同步"有选中即隐藏搜索框"行为
+ Vue.nextTick(function () {
+ SetAceDropDown();
+ $('.chosen-select').trigger('chosen:updated');
+ $('select.chosen-select[multiple]').each(function () {
+ refreshChosenSearchField(this);
+ });
+ });
},
error: function (msg) {
alert("error:" + msg);
@@ -92,58 +110,11 @@ const vue = new Vue({
}
},
mounted() {
- if (page.isGFSM) {
- if (this.isAdd) {
- this.isClientNameDisabled = true;
- }
- else {
- if (this.clientMarginTemplate.ClientId == "0") this.isClientNameDisabled = true;
- if (this.clientMarginTemplate.ClientLevel == "") this.isClientLevelDisabled = true;
- }
-
- this.SetClientLevelDropDown();
-
- }
this.SetClientNameDropDown();
if (this.marginTemplate.TradeTypes != null && this.marginTemplate.TradeTypes != 'undefined') {
$('#suitableType').prop('title', this.marginTemplate.TradeTypes);
}
-
- },
- watch: {
- 'clientMarginTemplate.ClientLevel': {
- handler(newVal, oldVal) {
- if (newVal == '') {
- this.isClientLevelDisabled = true;
- this.isClientNameDisabled = false;
- if (this.clientMarginTemplate.ClientId == '0') {
- if (this.clientNames.length > 0) {
- this.clientMarginTemplate.ClientId = this.clientNames[0].Value;
- }
- }
-
- }
-
- },
- immediate: false
- },
- 'clientMarginTemplate.ClientId': {
- handler(newVal, oldVal) {
- if (newVal == '0') {
- this.isClientNameDisabled = true;
- this.isClientLevelDisabled = false;
- if (this.clientMarginTemplate.ClientLevel == '') {
- if (this.clientLevels.length > 0) {
- this.clientMarginTemplate.ClientLevel = this.clientLevels[0].Value;
- }
- }
-
- }
-
- },
- immediate: false
- }
},
components: {
'vue-datepicker': FastVue.vueDatePicker(),
@@ -151,6 +122,17 @@ const vue = new Vue({
}
});
+//多选 chosen:已有选中项后隐藏搜索框(与 marginTemplateV2*Edit.js 同款行为)——
+//空框没有输入内容却占一行,放不下时还会换行留白;全部取消后恢复占位提示。
+//须为顶层函数:SetClientNameDropDown 的 nextTick 回调也会调用
+function refreshChosenSearchField(select) {
+ var $sel = $(select);
+ var $container = $sel.next('.chosen-container-multi');
+ if ($container.length === 0) return;
+ var noneSelected = $sel.find('option:selected').length === 0;
+ $container.find('li.search-field').toggle(noneSelected);
+}
+
$(function () {
$(".datepicker").change(function () {
var dateVal = $(this).val();
@@ -174,33 +156,15 @@ $(function () {
$(this).datepicker("setDate", dateVal);
});
+ //勾选变化走原 select 的 jQuery change 委托(chosen trigger_form_field_change),在此统一刷新搜索框
+ $(document).on('change chosen:updated', 'select.chosen-select[multiple]', function () {
+ refreshChosenSearchField(this);
+ });
+
SetAceDropDown();
-
- var width = 152;
- for (var i = 0; i < consClients.length; i++) {
- let ele = document.createElement('span')
- ele.innerText = consClients[i].Name;
- ele.style.fontSize = '14px';
- document.documentElement.append(ele);
- var charLength = ele.offsetWidth + 28;//滚动条
- document.documentElement.removeChild(ele);
- if (charLength > width) {
- width = charLength
- }
- }
-
- //if (!page.isGFSM) {
- // let autoClient = FastVue.autocomplete(document.getElementById('ClientId'), {
- // nameField: 'Name', valueField: 'id', searchField: ['Name', 'PinYin'], width: width,
- // lookup: consClients, onSelect: vue.changeClient
- // });
- // let clientId = page.clientMarginTemplate.ClientId;
- // let client = clientId ? consClients.find(x => x.id === clientId) : null;
- // !client && page.isAdd && (client = consClients[0]);
- // autoClient.setData(client);
- // vue.changeClient(client);
- //}
-
+ $('select.chosen-select[multiple]').each(function () {
+ refreshChosenSearchField(this);
+ });
});
var vueDetail = new Vue({