city_card/pages/serve/settle.js
2023-07-15 14:25:28 +08:00

351 lines
13 KiB
JavaScript

var e = getApp();
Page({
data: {
token: e.globalData.token,
sourceUrl: e.baseUrls.sourceUrl,
pageType: "1",
areaList: [],
areaIndex: 0,
areaAll: [],
areaSelected: "",
streetList: [],
streetIndex: 0,
streetAll: [],
streetSelected: "",
communityList: [],
communityIndex: 0,
communityAll: [],
communitySelected: "",
xqList: [],
xqIndex: 0,
xqAll: [],
xqSelected: "",
officeAddress: "",
orgIntro: "",
imageList: [],
serviceUrl: e.baseUrls.serviceUrl,
baseImgUrl: e.baseUrls.baseImgUrl,
locationCode: "",
unitName: "",
serviceMode: "",
shopType: "",
phone: "",
chargePerson: "",
residential: "",
curType: [],
typeIndex: 0,
typeAll: [],
typeSelected: "",
typeSelectedName: "",
isLoading: !1
},
bindTypePickerChange: function(e) {
this.setData({
typeIndex: e.detail.value,
typeSelected: this.data.typeAll[e.detail.value].dataId,
typeSelectedName: this.data.typeAll[e.detail.value].dataName,
pageType: this.data.typeAll[e.detail.value].dataId
});
},
getArea: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getArea, [ e.baseUrls.serviceUrl, "110889" ]), {}, {
headers: {
token: t.data.token
}
}, function(e, a) {
for (var i = [ "请选择区县" ], o = 0; o < a.length; o++) i.push(a[o].areaName);
t.setData({
areaList: i,
areaAll: a
});
}, function(e, t) {
console.log(t);
});
},
bindAreaPickerChange: function(e) {
this.setData({
areaIndex: e.detail.value,
areaSelected: this.data.areaAll[e.detail.value - 1].areaId
}), this.getStreet();
},
getStreet: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getArea, [ e.baseUrls.serviceUrl, t.data.areaSelected ]), {}, {
headers: {
token: t.data.token
}
}, function(e, a) {
for (var i = [ "请选择街道" ], o = 0; o < a.length; o++) i.push(a[o].areaName);
t.setData({
streetList: i,
streetAll: a
});
}, function(e, t) {
console.log(t);
});
},
bindStreetPickerChange: function(e) {
this.setData({
streetIndex: e.detail.value,
streetSelected: this.data.streetAll[e.detail.value - 1].areaId
}), this.getCommunity();
},
getCommunity: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getCommunityList, [ e.baseUrls.communityUrl ]), {
parentCode: t.data.streetSelected
}, {
headers: {
token: t.data.token
}
}, function(e, a) {
for (var i = [ "请选择社区" ], o = 0; o < a.length; o++) i.push(a[o].communityName);
t.setData({
communityList: i,
communityAll: a
}), console.log(a);
}, function(e, t) {
console.log(t);
});
},
bindCommunityPickerChange: function(e) {
this.setData({
communityIndex: e.detail.value,
communitySelected: this.data.communityAll[e.detail.value - 1].communityId,
locationCode: this.data.communityAll[e.detail.value - 1].locationCode
}), this.getHouseList();
},
uploadImage: function() {
var t = this;
t.data.isLoading || wx.chooseImage({
count: 9 - t.data.imageList.length,
sourceType: [ "album", "camera" ],
success: function(a) {
wx.showToast({
title: "上传中",
icon: "loading"
}), t.setData({
isLoading: !0
});
for (var i = function(i) {
s = a.tempFiles[i].path, e.restAjax.file(e.restAjax.path(e.apis.uploadImg, [ e.baseUrls.serviceUrl ]), s, "image", {
headers: {
token: e.globalData.token
}
}, function(e, o) {
if ("200" == e) {
var s = JSON.parse(o).data, n = t.data.imageList;
n.push(s), t.setData({
imageList: n
}), i == a.tempFiles.length - 1 && t.setData({
isLoading: !1
}), wx.hideToast();
}
}, function(e, t) {
console.log(t);
});
}, o = 0; o < a.tempFiles.length; o++) {
var s;
i(o);
}
}
});
},
getHouseList: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getHouse, [ e.baseUrls.communityUrl ]), {
areaCode: t.data.locationCode
}, {
headers: {
token: t.data.token
}
}, function(e, a) {
console.log(a);
for (var i = [ "请选择小区" ], o = 0; o < a.length; o++) i.push(a[o].residentialName);
t.setData({
xqList: i,
xqAll: a
});
}, function(e, t) {
console.log(t);
});
},
bindXqPickerChange: function(e) {
this.setData({
xqIndex: e.detail.value,
xqSelected: this.data.xqAll[e.detail.value - 1].residentialId
});
},
submitSettle: function() {
var t = this;
if (!t.data.isLoading) {
if ("0" == t.data.areaIndex) return void wx.showToast({
title: "请选择区县",
icon: "error"
});
if ("0" == t.data.streetIndex && t.data.streetAll.length > 1) return void wx.showToast({
title: "请选择街道",
icon: "error"
});
if ("0" == t.data.communityIndex && t.data.communityAll.length > 1) return void wx.showToast({
title: "请选择社区",
icon: "error"
});
if (!t.data.unitName) return void wx.showToast({
title: "请填写单位名称",
icon: "error"
});
if (!t.data.officeAddress && "612be328-bb06-48b7-877c-7d816012f273" == t.data.pageType) return void wx.showToast({
title: "请填写办公地址",
icon: "error"
});
if (!t.data.officeAddress && "3c97be91-b7e5-498f-b0dd-cd097521549f" == t.data.pageType) return void wx.showToast({
title: "请填写营业地址",
icon: "error"
});
if (!t.data.unitName && "612be328-bb06-48b7-877c-7d816012f273" == t.data.pageType) return void wx.showToast({
title: "请填写单位名称",
icon: "error"
});
if (!t.data.unitName && "3c97be91-b7e5-498f-b0dd-cd097521549f" == t.data.pageType) return void wx.showToast({
title: "请填写店铺名称",
icon: "error"
});
if (!t.data.shopType && "3c97be91-b7e5-498f-b0dd-cd097521549f" == t.data.pageType) return void wx.showToast({
title: "请填写店铺品类",
icon: "error"
});
if (!t.data.orgIntro) return void wx.showToast({
title: "请填写机构简介",
icon: "error"
});
if (!t.data.phone) return void wx.showToast({
title: "请填写联系电话",
icon: "error"
});
if (!t.data.chargePerson) return void wx.showToast({
title: "请填写负责人姓名",
icon: "error"
});
for (var a = "", i = 0; i < t.data.imageList.length; i++) a += t.data.imageList[i],
i != t.data.imageList.length - 1 && (a += ",");
"3c97be91-b7e5-498f-b0dd-cd097521549f" != t.data.pageType || t.data.shopType || wx.showToast({
title: "请填写品类"
});
var o = "", s = "非ID";
if ("6c290901-39dd-4b69-a7aa-c27d253ab152" == t.data.pageType || "45ad4873-af80-4d03-973d-3b746a889948" == t.data.pageType) if ("0" == t.data.xqIndex) {
if (!t.data.residential) return void wx.showToast({
title: "请选择或填写您的小区名称",
icon: "error"
});
s = t.data.residential;
} else o = t.data.xqSelected, s = "ID";
var n = {
organizationTypeId: t.data.pageType,
organizationTypeName: t.data.pageName,
cityId: t.data.areaSelected,
cityCode: t.data.areaAll[t.data.areaIndex - 1].areaCode,
cityName: t.data.areaAll[t.data.areaIndex - 1].areaName,
streetId: t.data.streetSelected,
streetCode: t.data.streetAll[t.data.streetIndex - 1].areaCode,
streetName: t.data.streetAll[t.data.streetIndex - 1].areaName,
communityId: t.data.communitySelected,
communityCode: t.data.communityAll[t.data.communityIndex - 1].locationCode,
communityName: t.data.communityAll[t.data.communityIndex - 1].communityName,
address: t.data.officeAddress,
introduction: t.data.orgIntro,
fileIds: a,
residential: o,
serviceMode: t.data.serviceMode,
unitName: t.data.unitName,
shopType: t.data.shopType,
shopTypeName: t.data.shopType,
phone: t.data.phone,
chargePerson: t.data.chargePerson,
residentialValue: s
};
t.setData({
isLoading: !0
}), e.restAjax.post(e.restAjax.path(e.apis.submitSettle, [ e.baseUrls.requestUrl ]), n, {
headers: {
token: t.data.token
}
}, function(e, a) {
wx.showToast({
title: "入驻成功",
icon: "success"
}), setTimeout(function() {
t.setData({
isLoading: !1
}), wx.redirectTo({
url: "/packagecard/cardList/cardList?type=org&id=" + a.data
});
}, 300);
}, function(e, a) {
console.log(a), t.setData({
isLoading: !1
});
});
}
},
deleteImg: function(e) {
var t = e.currentTarget.dataset.cur, a = this.data.imageList;
a.splice(t, 1), this.setData({
imageList: a
});
},
getOrgList: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getDictionary, [ e.baseUrls.serviceUrl, "8e981a56-afa1-4934-9d90-16aa1b8113ca" ]), {}, {
headers: {
token: t.data.token
}
}, function(e, a) {
for (var i = [], o = 0; o < a.length; o++) i.push(a[o].dataName);
t.setData({
curType: i,
typeAll: a,
typeSelected: a[0].dataId,
typeSelectedName: a[0].dataName,
pageType: a[0].dataId
});
}, function(e, t) {
console.log(t);
});
},
getStoreList: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getDictionary, [ e.baseUrls.serviceUrl, "4a44a891-8a0c-4cad-ada6-09ce99118e27" ]), {}, {
headers: {
token: t.data.token
}
}, function(e, a) {
for (var i = [], o = 0; o < a.length; o++) i.push(a[o].dataName);
t.setData({
curType: i,
typeAll: a,
typeSelected: a[0].dataId,
typeSelectedName: a[0].dataName,
pageType: a[0].dataId
});
}, function(e, t) {
console.log(t);
});
},
onLoad: function(t) {
this.setData({
token: e.globalData.token
}), "1" == t.type ? this.getOrgList() : this.getStoreList();
},
onReady: function() {
this.getArea();
},
onShow: function() {},
onHide: function() {},
onUnload: function() {},
onPullDownRefresh: function() {},
onReachBottom: function() {},
onShareAppMessage: function() {}
});