|
@@ -9,11 +9,14 @@ Page({
|
|
|
data: {
|
|
data: {
|
|
|
isEdit: false,
|
|
isEdit: false,
|
|
|
storeList: [],
|
|
storeList: [],
|
|
|
|
|
+ agentList:[],
|
|
|
|
|
+ userInfo: {},
|
|
|
values: {
|
|
values: {
|
|
|
storeId: '',
|
|
storeId: '',
|
|
|
storeName: '',
|
|
storeName: '',
|
|
|
schemeName: '',
|
|
schemeName: '',
|
|
|
- schemeProductList: []
|
|
|
|
|
|
|
+ schemeBillEntryList: []
|
|
|
|
|
+
|
|
|
},
|
|
},
|
|
|
id:''
|
|
id:''
|
|
|
},
|
|
},
|
|
@@ -29,33 +32,20 @@ Page({
|
|
|
id:options.id
|
|
id:options.id
|
|
|
})
|
|
})
|
|
|
that.bindScheme()
|
|
that.bindScheme()
|
|
|
- } else {
|
|
|
|
|
- if (!that.data.isEdit) {
|
|
|
|
|
-
|
|
|
|
|
- var schemeProductList = []
|
|
|
|
|
- for (var i = 1; i <= 22; i++) {
|
|
|
|
|
- var item = {
|
|
|
|
|
- schemeId: '',
|
|
|
|
|
- productId: '',
|
|
|
|
|
- productName: '请选择商品',
|
|
|
|
|
- productImg: '',
|
|
|
|
|
- productSchemePrice: 0,
|
|
|
|
|
- storeDivide: 0,
|
|
|
|
|
- gridNum:i
|
|
|
|
|
- }
|
|
|
|
|
- schemeProductList.push(item)
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- this.setData({
|
|
|
|
|
- ["values.schemeProductList"]: schemeProductList
|
|
|
|
|
- })
|
|
|
|
|
- console.log("---------------------------------------")
|
|
|
|
|
- console.log(this.data.values.schemeProductList)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
wx.setNavigationBarTitle({
|
|
wx.setNavigationBarTitle({
|
|
|
title: that.data.isEdit ? '方案编辑' : '新增方案'
|
|
title: that.data.isEdit ? '方案编辑' : '新增方案'
|
|
|
})
|
|
})
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ userInfo: app.globalData.userInfo
|
|
|
|
|
+ })
|
|
|
|
|
+ this.getAllAgentList();
|
|
|
|
|
+ if(this.data.userInfo.mgvmRole==3){
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ ['values.agentId']: this.data.userInfo.id,
|
|
|
|
|
+ ['values.agentName']: this.data.userInfo.username,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
this.bindStoreList()
|
|
this.bindStoreList()
|
|
|
},
|
|
},
|
|
|
bindStorePickerChange: function (e) {
|
|
bindStorePickerChange: function (e) {
|
|
@@ -65,34 +55,66 @@ Page({
|
|
|
['values.storeName']: item.storeName
|
|
['values.storeName']: item.storeName
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
+ bindAgentPickerChange: function (e) {
|
|
|
|
|
+ var item = this.data.agentList[e.detail.value]
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ ['values.agentId']: item.id,
|
|
|
|
|
+ ['values.agentName']: item.username
|
|
|
|
|
+ })
|
|
|
|
|
+ this.bindStoreList()
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
formSubmit: function (e) {
|
|
formSubmit: function (e) {
|
|
|
|
|
+ console.log(this.data.values.schemeBillEntryList)
|
|
|
var that = this
|
|
var that = this
|
|
|
//表单规则
|
|
//表单规则
|
|
|
let rules = [{
|
|
let rules = [{
|
|
|
name: "schemeName",
|
|
name: "schemeName",
|
|
|
rule: ["required"], //可使用区间,此处主要测试功能
|
|
rule: ["required"], //可使用区间,此处主要测试功能
|
|
|
msg: ["请输入方案名称"]
|
|
msg: ["请输入方案名称"]
|
|
|
|
|
+ },{
|
|
|
|
|
+ name: "storeName",
|
|
|
|
|
+ rule: ["required"], //可使用区间,此处主要测试功能
|
|
|
|
|
+ msg: ["请输入门店"]
|
|
|
}];
|
|
}];
|
|
|
|
|
+ if(this.data.userInfo.mgvmRole!=3){
|
|
|
|
|
+ var agentRule = {
|
|
|
|
|
+ name: "agentName",
|
|
|
|
|
+ rule: ["required"],
|
|
|
|
|
+ msg: ["请输入代理商"]
|
|
|
|
|
+ }
|
|
|
|
|
+ rules.push(agentRule)
|
|
|
|
|
+ }else{
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ ['values.agentId']: this.data.userInfo.id,
|
|
|
|
|
+ ['values.agentName']: this.data.userInfo.username,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//进行表单检查
|
|
//进行表单检查
|
|
|
let formData = e.detail.value;
|
|
let formData = e.detail.value;
|
|
|
let checkRes = form.validation(formData, rules);
|
|
let checkRes = form.validation(formData, rules);
|
|
|
- let schemeProductList = this.data.values.schemeProductList;
|
|
|
|
|
|
|
+ let schemeBillEntryList = this.data.values.schemeBillEntryList;
|
|
|
var schemeProduct = [];
|
|
var schemeProduct = [];
|
|
|
var productCount = 0;
|
|
var productCount = 0;
|
|
|
- for (let i = 0; i < schemeProductList.length; i++) {
|
|
|
|
|
- if(schemeProductList[i].productId!=null&&schemeProductList[i].productId!=""){
|
|
|
|
|
- schemeProduct.push(schemeProductList[i])
|
|
|
|
|
|
|
+ for (let i = 0; i < schemeBillEntryList.length; i++) {
|
|
|
|
|
+ if(schemeBillEntryList[i].productId!=null&&schemeBillEntryList[i].productId!=""){
|
|
|
|
|
+ schemeProduct.push(schemeBillEntryList[i])
|
|
|
productCount+=1;
|
|
productCount+=1;
|
|
|
- if(schemeProductList[i].productSchemePrice==0){
|
|
|
|
|
- util.toast("请输入商品价格")
|
|
|
|
|
|
|
+ if(schemeBillEntryList[i].areaDivide==""||schemeBillEntryList[i].areaDivide==null){
|
|
|
|
|
+ util.toast('请输入代理分成')
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(schemeBillEntryList[i].areaDivide<0||schemeBillEntryList[i].areaDivide>100){
|
|
|
|
|
+ util.toast('门店分成必须是0-100的分成')
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if(schemeProductList[i].storeDivide==0){
|
|
|
|
|
|
|
+ if(schemeBillEntryList[i].storeDivide==""||schemeBillEntryList[i].storeDivide==null){
|
|
|
util.toast('请输入门店分成')
|
|
util.toast('请输入门店分成')
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if(schemeProductList[i].storeDivide<1||schemeProductList[i].storeDivide>100){
|
|
|
|
|
- util.toast('门店分成必须是1-100的分成')
|
|
|
|
|
|
|
+ if(schemeBillEntryList[i].storeDivide<0||schemeBillEntryList[i].storeDivide>100){
|
|
|
|
|
+ util.toast('门店分成必须是0-100的分成')
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -104,7 +126,7 @@ Page({
|
|
|
if (!checkRes) {
|
|
if (!checkRes) {
|
|
|
if(!that.data.isEdit){
|
|
if(!that.data.isEdit){
|
|
|
this.setData({
|
|
this.setData({
|
|
|
- ["values.schemeProductList"]: schemeProduct
|
|
|
|
|
|
|
+ ["values.schemeBillEntryList"]: schemeProduct
|
|
|
})
|
|
})
|
|
|
util.request(util.api.addScheme, that.data.values, "POST", false, true, app.globalData.token).then((res) => {
|
|
util.request(util.api.addScheme, that.data.values, "POST", false, true, app.globalData.token).then((res) => {
|
|
|
if (res.code == 200) {
|
|
if (res.code == 200) {
|
|
@@ -153,7 +175,7 @@ Page({
|
|
|
let dataset = e.currentTarget.dataset;
|
|
let dataset = e.currentTarget.dataset;
|
|
|
let value = e.detail.value;
|
|
let value = e.detail.value;
|
|
|
let name = dataset.name;
|
|
let name = dataset.name;
|
|
|
- var list = that.data.values.schemeProductList
|
|
|
|
|
|
|
+ var list = that.data.values.schemeBillEntryList
|
|
|
var index = dataset.index;
|
|
var index = dataset.index;
|
|
|
var itemProduct = dataset.item
|
|
var itemProduct = dataset.item
|
|
|
|
|
|
|
@@ -162,24 +184,22 @@ Page({
|
|
|
if(!value){
|
|
if(!value){
|
|
|
value = 0.00;
|
|
value = 0.00;
|
|
|
}
|
|
}
|
|
|
- switch(name){
|
|
|
|
|
- case "productSchemePrice":
|
|
|
|
|
- value = parseInt(parseFloat(value));
|
|
|
|
|
- itemProduct.productSchemePrice = value
|
|
|
|
|
- break;
|
|
|
|
|
- case "storeDivide":
|
|
|
|
|
- itemProduct.storeDivide = value
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ console.log(name)
|
|
|
|
|
+ if(name=="storeDivide"){
|
|
|
|
|
+ itemProduct.storeDivide = value
|
|
|
|
|
+ }else if(name=="areaDivide"){
|
|
|
|
|
+ itemProduct.areaDivide = value
|
|
|
}
|
|
}
|
|
|
list.splice(index,1,itemProduct)
|
|
list.splice(index,1,itemProduct)
|
|
|
that.setData({
|
|
that.setData({
|
|
|
- ["values.schemeProductList"]:list
|
|
|
|
|
|
|
+ ["values.schemeBillEntryList"]:list
|
|
|
})
|
|
})
|
|
|
|
|
+ console.log(this.data.values.schemeBillEntryList)
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
bindStoreList() {
|
|
bindStoreList() {
|
|
|
var that = this
|
|
var that = this
|
|
|
- util.request(util.api.storeList, {}, "GET", false, true, app.globalData.token).then((res) => {
|
|
|
|
|
|
|
+ util.request(util.api.storeList, {agentId:that.data.values.agentId}, "GET", false, true, app.globalData.token).then((res) => {
|
|
|
if (res.code == 200) {
|
|
if (res.code == 200) {
|
|
|
that.setData({
|
|
that.setData({
|
|
|
storeList: res.result
|
|
storeList: res.result
|
|
@@ -187,6 +207,17 @@ Page({
|
|
|
}
|
|
}
|
|
|
}).catch((res) => {})
|
|
}).catch((res) => {})
|
|
|
},
|
|
},
|
|
|
|
|
+ //代理商
|
|
|
|
|
+ getAllAgentList() {
|
|
|
|
|
+ var that = this
|
|
|
|
|
+ util.request(util.api.allAgentList, {}, "GET", false, true,app.globalData.token).then((res) => {
|
|
|
|
|
+ if (res.code == 200) {
|
|
|
|
|
+ that.setData({
|
|
|
|
|
+ agentList: res.result
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch((res) => {})
|
|
|
|
|
+ },
|
|
|
toSelect(e) {
|
|
toSelect(e) {
|
|
|
wx.navigateTo({
|
|
wx.navigateTo({
|
|
|
url: '/pages/scheme/select?index=' + e.currentTarget.dataset.index,
|
|
url: '/pages/scheme/select?index=' + e.currentTarget.dataset.index,
|
|
@@ -198,29 +229,6 @@ Page({
|
|
|
id: that.data.id
|
|
id: that.data.id
|
|
|
}, "GET", true, true, app.globalData.token).then((res) => {
|
|
}, "GET", true, true, app.globalData.token).then((res) => {
|
|
|
|
|
|
|
|
- let schemeProductLists = res.result.schemeProductList;
|
|
|
|
|
- console.log(schemeProductLists)
|
|
|
|
|
- console.log("==================================")
|
|
|
|
|
- var schemeProductList = []
|
|
|
|
|
- for (var i = 1; i <= 22; i++) {
|
|
|
|
|
- var item = {
|
|
|
|
|
- schemeId: '',
|
|
|
|
|
- productId: '',
|
|
|
|
|
- productName: '请选择商品',
|
|
|
|
|
- productImg: '',
|
|
|
|
|
- productSchemePrice: 0,
|
|
|
|
|
- storeDivide: 0,
|
|
|
|
|
- gridNum:i
|
|
|
|
|
- }
|
|
|
|
|
- for (let k = 0; k < schemeProductLists.length; k++) {
|
|
|
|
|
- if(schemeProductLists[k].gridNum == i){
|
|
|
|
|
- item = schemeProductLists[k];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- schemeProductList.push(item)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- res.result.schemeProductList = schemeProductList;
|
|
|
|
|
if (res.code == 200) {
|
|
if (res.code == 200) {
|
|
|
that.setData({
|
|
that.setData({
|
|
|
values: res.result,
|
|
values: res.result,
|
|
@@ -238,6 +246,15 @@ Page({
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}).catch((res) => {})
|
|
}).catch((res) => {})
|
|
|
|
|
+ },
|
|
|
|
|
+ //添加格子
|
|
|
|
|
+ addGrid(){
|
|
|
|
|
+ var schemeBillEntryList =this.data.values.schemeBillEntryList;
|
|
|
|
|
+ var product = {productName:'请选择商品',gridNum:schemeBillEntryList.length+1};
|
|
|
|
|
+ schemeBillEntryList.push(product)
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ ["values.schemeBillEntryList"]: schemeBillEntryList
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
})
|
|
})
|