You've already forked qlg.frontend
Init Repo
This commit is contained in:
125
js/addproperties.js
Normal file
125
js/addproperties.js
Normal file
@ -0,0 +1,125 @@
|
||||
mui.plusReady(function() {
|
||||
mui.init({
|
||||
beforeback: function() { //获得父页面的webview
|
||||
var list = plus.webview.currentWebview().opener(); //触发父页面的自定义事件(refresh),从而进行刷新
|
||||
mui.fire(list, 'reload');
|
||||
//返回true,继续页面关闭逻辑
|
||||
return true;
|
||||
}
|
||||
});
|
||||
var self = plus.webview.currentWebview();
|
||||
//console.log(self);
|
||||
var shopId = self.id;
|
||||
var specCatsId = self.specCatsId ? self.specCatsId : 0;
|
||||
var setName = self.setName ? self.setName : 0;
|
||||
var index = 0;
|
||||
//console.log(shopId,specCatsId,setName);
|
||||
if (specCatsId > 0) {
|
||||
$(".title").html("编辑产品规格属性")
|
||||
JZL.ajax(qlgUrl("app/shops/getSpecCats"), {
|
||||
id: specCatsId,
|
||||
shopId: shopId
|
||||
}, function(data) {
|
||||
//console.log(data);
|
||||
if (1 == data.status) {
|
||||
$("#setName").val(setName)
|
||||
//var specNames = $('input[name="specNames[]"]');
|
||||
//var specItems = $('input[name="specItems[]"]');//
|
||||
var html = '';
|
||||
$.each(data.data, function(i, v) {
|
||||
|
||||
html +=
|
||||
'<div class="row shadown_wai "><label>属性名称</label><input type="text" name="specNames[]" id="specNames[' + i +
|
||||
']" class="inp" value="' + this.catName +
|
||||
'" /></div><div class="row shadown_wai "><label>可选值列表</label><input type="text" name="specItems[]" id="specItems[' +
|
||||
i + ']" class="inp" value="' + this.itemNames +
|
||||
'" placeholder="输入多项请用英文逗号分隔" /></div><input type="hidden" id="specNamesId[' + i + ']" class="inp" value="' +
|
||||
this.catId + '" /><input type="hidden" id="specItemsId[' + i + ']" class="inp" value="' + this.itemId +
|
||||
'" />'
|
||||
})
|
||||
|
||||
$('.con_con').append(html);
|
||||
|
||||
// $(specNames[i]).val(data.data[i].catName)
|
||||
// $(specItems[i]).val(data.data[i].itemNames)
|
||||
// }
|
||||
} else {
|
||||
mui.alert(data.msg)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
$(".title").html("添加产品规格属性")
|
||||
|
||||
var html = '';
|
||||
html = '<div class="row shadown_wai "><label>属性名称</label><input type="text" name="specNames[]" id="specNames[' +
|
||||
index +
|
||||
']" class="inp" value="" /></div><div class="row shadown_wai "><label>可选值列表</label><input type="text" name="specItems[]" id="specItems[' +
|
||||
index +
|
||||
']" class="inp" value="" placeholder="输入多项请用英文逗号分隔" /></div><input type="hidden" id="specNamesId[0]" class="inp" value="0" /><input type="hidden" id="specItemsId[0]" class="inp" value="0" />'
|
||||
index++
|
||||
$('.con_con').append(html);
|
||||
|
||||
}
|
||||
|
||||
mui('body').on('tap', '.add1', function() {
|
||||
var html = '';
|
||||
html += '<div class="row shadown_wai "><label>属性名称</label><input type="text" name="specNames[]" id="specNames[' + index +
|
||||
']" class="inp" value="" /></div><div class="row shadown_wai "><label>可选值列表</label><input type="text" name="specItems[]" id="specItems[' +
|
||||
index + ']" class="inp" value="" /></div><input type="hidden" id="specNamesId[' + index +
|
||||
']" class="inp" value="0" /><input type="hidden" id="specItemsId[' + index + ']" class="inp" value="0" />'
|
||||
$('.con_con').append(html);
|
||||
index++;
|
||||
})
|
||||
var click = false;
|
||||
mui('body').on('tap', '.bc_btn', function() {
|
||||
//if (true == click) return;
|
||||
click = true;
|
||||
var length = $('input[name="specNames[]"]').length;
|
||||
var specName,specItem;
|
||||
for (var i = 0; i < length; i++) {
|
||||
specName = document.getElementById('specNames[' + +i + ']');
|
||||
specItem = document.getElementById('specItems[' + +i + ']');
|
||||
if ('' == specItem.value && '' == specItem.value) {
|
||||
if (specCatsId == 0) {
|
||||
specName.classList.remove("inp");
|
||||
specItem.classList.remove("inp");
|
||||
document.getElementById('specNamesId[' + +i + ']').classList.remove("inp");
|
||||
document.getElementById('specItemsId[' + +i + ']').classList.remove("inp");
|
||||
}
|
||||
} else {
|
||||
if ('' == specName.value) {
|
||||
mui.alert('请输入属性名');
|
||||
specName.focus();
|
||||
return;
|
||||
}
|
||||
if ('' == specItem.value) {
|
||||
specItem.focus();
|
||||
mui.alert('请输入属性值');
|
||||
return;
|
||||
}
|
||||
specItem.value = specItem.value.replace(/,/g, ',');
|
||||
}
|
||||
}
|
||||
var params = JZL.getParams(".inp");
|
||||
// $.each(params,function(i,v){
|
||||
// params[i] = v.replace(/,/g, ',');
|
||||
// })
|
||||
params.shopId = shopId;
|
||||
if (specCatsId > 0) {
|
||||
params.id = specCatsId;
|
||||
}
|
||||
JZL.ajax(qlgUrl("app/shops/setSpecs"), params, function(data) {
|
||||
//console.log(data);
|
||||
if (data.status == 1) {
|
||||
mui.toast('添加规格成功');
|
||||
mui.back();
|
||||
} else {
|
||||
mui.alert(data.msg);
|
||||
//location.reload();
|
||||
}
|
||||
click = false;
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user