chache/pages/sale/index.js
2024-01-22 18:48:00 +08:00

475 lines
14 KiB
JavaScript

var a;
(a = getApp()).util.url("entry/wxapp/Api", {
m: "monai_market",
uid: wx.getStorageSync("uid"),
r: "Upimg",
}),
Page({
data: {
upcarindex: 0,
date: "2017-01",
carsimgs: [{ img: "", intro: "", imgshort: "" }],
exhaust: "",
brandid: "",
newm: "",
brandname: "",
classid: "",
classes: [],
brands: [],
selectclass: "请选择分类",
selectbrand: "请选择品牌",
selecttime: " 请选择上牌日期",
selecttime1: "",
mapname: "请选择看车地区",
vehicletime: "请选择上牌日期",
vehicletime1: "",
insurance: "请选择保险到期时间",
insurance1: "",
gearboxes: "",
gearboxname: "请选择变速箱类型",
gearboxindex: 0,
userphone: "",
mapname: "",
mapx: "",
mapy: "",
carimgs: [],
buttscan: !1,
notice: [],
noticeindex: 0,
textareatype: !1,
textareaname: "请输入车辆信息介绍",
textareainput: "",
isShow: !1,
showtextarea: !1,
status: "",
},
bindRegionChange: function (a) {
this.setData({ region: a.detail.value, mapname: a.detail.value });
},
intextarea: function () {
this.setData({ textareatype: !0, textareaname: this.data.textareainput });
},
toSelectCar: function () {
wx.navigateTo({ url: "/packageA/pages/caresgz/selectCar/selectCar" });
},
bindblur: function (a) {
console.log(a.detail.value);
var e = a.detail.value,
t = e;
e || ((e = "请输入车辆信息介绍"), (t = "")),
this.setData({ textareatype: !1, textareaname: e, textareainput: t });
},
bindconfirm: function () {
var a = new Date();
console.log(a.getMilliseconds());
},
hideDialog: function () {
this.setData({ isShow: !this.data.isShow });
},
updateUserInfo: function (e) {
var t = this;
a.util.getUserInfo(function (a) {
wx.setStorageSync("uid", a.memberInfo.uid), t.hideDialog();
}, e.detail);
},
showtextarea: function () {
var a = this;
console.log(!a.data.showtextarea),
a.setData({ showtextarea: !a.data.showtextarea });
},
textareashow: function (a) {
this.setData({ mapname: a.detail.value });
},
onShow: function () {
"" != (a = this).data.brandid &&
"" != a.data.brandname &&
a.setData({ selectbrand: a.data.brandname });
var a = wx.getStorageSync("carvehicle"),
e = wx.getStorageSync("carprov"),
t = wx.getStorageSync("carcity"),
i = wx.getStorageSync("cartime"),
s = "";
"" != t && null != t && (s = e.name + "-" + t.name),
console.log("" == a),
"" != a &&
"" != i &&
parseInt(i.split("-")[0]) < parseInt(a.makeyear) &&
(i = ""),
this.setData({
cardata: a,
carname: a.fullname,
exhaust: a.c_displacement,
newm: a.g_price,
gearbox: a.c_bsxlx,
cityName: s,
regdate: i,
cityid: t.id,
provid: e.id,
carId: a.id,
});
},
firstin: function (e) {
var t = wx.getSystemInfoSync();
e.setData({ maxwidth: t.windowWidth, maxheight: t.windowHeight }),
a.util.request({
url: "entry/wxapp/Api",
data: {
m: "monai_market",
uid: a.getuid(),
r: "sale.index.saleindex",
},
cachetime: "0",
success: function (a) {
var t = { classes: a.data.data.class, userphone: "", mapname: "" };
a.data.data.user && (t.userphone = a.data.data.user.phone),
e.setData(t);
},
});
},
onLoad: function (e) {
var t = this;
wx.setStorageSync("carvehicle", ""),
a.util.getUserInfo(function (e) {
e.memberInfo || t.setData({ isShow: !0 }),
a.util.request({
url: "entry/wxapp/Api",
data: {
m: "monai_market",
r: "me.info",
uid: wx.getStorageSync("uid"),
},
success: function (a) {
console.log(a),
1 == a.data.data.status &&
wx.showModal({
title: "提示",
content: "您的用户已经禁止发布车辆信息,请联系管理员处理",
showCancel: !1,
success: function (a) {},
}),
t.setData({ status: a.data.data.status });
},
});
}),
t.firstin(t);
},
selectclass: function (a) {
var e = this.data.classes[a.detail.value];
e && this.setData({ selectclass: e.name, classid: e.id });
},
gearbox: function (a) {
var e = this.data.gearboxes[a.detail.value];
e && this.setData({ gearboxname: e.name, gearboxindex: a.detail.value });
},
selectbrand: function (a) {
wx.navigateTo({ url: "/pages/selectscards/index" });
},
bindDateChange: function (a) {
console.log(a.detail.value);
var e = a.detail.value.split("-");
this.setData({
selecttime: e[0] + "年" + e[1] + "月",
selecttime1: a.detail.value,
});
},
insurance: function (a) {
console.log(a.detail.value);
var e = a.detail.value.split("-");
this.setData({
insurance: e[0] + "年" + e[1] + "月" + e[2] + "日",
insurance1: a.detail.value,
});
},
vehicletime: function (a) {
console.log(a.detail.value);
var e = a.detail.value.split("-");
this.setData({
vehicletime: e[0] + "年" + e[1] + "月" + e[2] + "日",
vehicletime1: a.detail.value,
});
},
getPhoneNumber: function (e) {
console.log(e);
var t = this;
a.util.request({
url: "entry/wxapp/Api",
data: {
r: "sale.index.userphone",
m: "monai_market",
iv: e.detail.iv,
encryptedData: e.detail.encryptedData,
},
cachetime: "0",
success: function (a) {
t.setData({ userphone: a.data.data });
},
});
},
tomap: function () {},
release: function (e) {
var t = this,
i = wx.getStorageSync("uid");
if ((console.log(e.detail.value.address), i)) {
t.setData({ buttscan: !0 });
var s = t.data.classid;
if ("" == s || "undefined" == s || "请选择车辆类型" == s)
return (
a.util.message({ title: "请选择车辆类型", type: "error" }),
void t.setData({ buttscan: !1 })
);
var n = t.data.brandid;
if ("" == n || "undefined" == n || "请选择车辆品牌" == n)
return (
a.util.message({ title: "请选择车辆品牌", type: "error" }),
void t.setData({ buttscan: !1 })
);
var r = t.data.selecttime;
if (
"请选择上牌日期" == r ||
"undefined" == r ||
"" == t.data.selecttime1
)
return (
a.util.message({ title: "请选择上牌日期", type: "error" }),
void t.setData({ buttscan: !1 })
);
var c = e.detail.value.carname;
if ("" == c || "undefined" == c)
return (
a.util.message({ title: "请填写卖车标题", type: "error" }),
void t.setData({ buttscan: !1 })
);
var d = e.detail.value.kilometre;
if ("" == d || "undefined" == d)
return (
a.util.message({ title: "请填写公里数", type: "error" }),
void t.setData({ buttscan: !1 })
);
var l = e.detail.value.price;
if ("" == l || "undefined" == l)
return (
a.util.message({ title: "请填写价格", type: "error" }),
void t.setData({ buttscan: !1 })
);
e.detail.value.exhaust, t.data.gearboxindex;
var o = e.detail.value.phone;
if ("" == o || "undefined" == o)
return (
a.util.message({
title: "请填写联系电话,或点击电话授权",
type: "error",
}),
void t.setData({ buttscan: !1 })
);
var u = e.detail.value.address,
m = t.data.carsimgs;
if (m.length < 3)
return (
a.util.message({ title: "请至少添加3个车辆图文", type: "error" }),
void t.setData({ buttscan: !1 })
);
var g = [];
for (var h in m)
"" != m[h].imgshort &&
"" != m[h].img &&
(console.log(m[h]), console.log(m[h].imgshort), g.push(m[h]));
var p = {
r: "sale.index.insale",
m: "monai_market",
fomid: e.detail.formId,
uid: i,
classid: s,
brand: n,
exhaust: t.data.exhaust,
times: r,
times1: t.data.selecttime1,
kilometre: d,
price: l,
gearbox: t.data.gearbox,
newm: t.data.newm,
phone: o,
carname: c,
address: u,
watchcar: t.data.region,
carimgs: g,
mapx: t.data.mapx,
mapy: t.data.mapy,
};
a.util.request({
url: "entry/wxapp/Api",
data: p,
cachetime: "0",
success: function (a) {
a && a.data && 405 == a.data.message
? t.setData({ isShow: !0, buttscan: !1 })
: a &&
a.data &&
a.data.data &&
wx.showModal({
content: "提交成功,快去上架吧",
cancelText: "继续添加",
confirmText: "去上架",
success: function (a) {
a.confirm
? (t.cleardetail(),
wx.navigateTo({ url: "/pages/salelist/index" }))
: a.cancel &&
(t.setData({ buttscan: !1 }),
wx.reLaunch({ url: "/pages/sale/index" }));
},
});
},
fail: function (a) {
t.setData({ buttscan: !1 });
},
});
} else t.setData({ isShow: !0 });
},
cleardetail: function () {
this.setData({
selectclass: "请选择分类",
selectbrand: "请选择品牌",
selecttime: " 请选择上牌日期",
selecttime1: "",
vehicletime1: "",
insurance1: "",
gearboxname: "请选择变速箱类型",
gearboxindex: 0,
mapx: "",
mapy: "",
carimgs: [],
textareaname: "请输入车辆信息介绍",
textareainput: "",
carsimgs: [{ img: "", intro: "", imgshort: "" }],
brandid: "",
brandname: "",
classid: "",
defult_value: "",
});
},
upnotice: function (a) {
this.data.noticeindex = a.detail.current;
},
retonotice: function () {
var a = this.data.notice[this.data.noticeindex];
a && a.id && wx.navigateTo({ url: "/pages/index/index?id=" + a.id });
},
delcarsimgs: function (e) {
var t = this,
i = e.currentTarget.dataset.index,
s = t.data.carsimgs;
if (0 == i && s.length > 1 && ("" != s[i].img || "" != s[i].intro))
return (
"" != s[i].img &&
a.util.request({
url: "entry/wxapp/Api",
data: {
m: "monai_market",
uid: a.getuid(),
imgurl: s[i].img,
r: "Upimg.delImg",
},
}),
s.splice(i, 1),
void t.setData({ carsimgs: s })
);
0 != i &&
("" != s[i].img &&
a.util.request({
url: "entry/wxapp/Api",
data: {
m: "monai_market",
uid: a.getuid(),
imgurl: s[i].img,
r: "Upimg.delImg",
},
}),
s.splice(i, 1),
t.setData({ carsimgs: s }));
},
upcarsimgs: function (e) {
var t = this;
t.data.carsimgs.length >= 9
? a.util.message({ title: "您添加的图片已经很多了", type: "error" })
: a.upimgs({
scannums: 9,
filename: "cars",
success: function (a) {
for (var e in a) t.addinimgs(a[e]);
},
});
},
addinimgs: function (a) {
var e = this.data.carsimgs,
t = { img: a.all, imgshort: a.short };
e.push(t), this.setData({ carsimgs: e });
},
showimgs: function (a) {
var e = a.currentTarget.dataset.index,
t = this.data.carsimgs;
wx.previewImage({ current: t[e].img, urls: [t[e].img] });
},
upthiscarsimgs: function (e) {
var t = e.currentTarget.dataset.index,
i = this.data.carsimgs;
a.util.request({
url: "entry/wxapp/Api",
data: {
m: "monai_market",
uid: a.getuid(),
imgurl: i[t].img,
r: "Upimg.delImg",
},
}),
(i[t].img = ""),
this.setData({ carsimgs: i });
},
setthisintro: function (a) {
var e = a.currentTarget.dataset.index;
this.data.carsimgs[e].intro = a.detail.value;
},
addcarsimgs: function () {
var a = this.data.carsimgs;
a.push({ img: "", intro: "", imgshort: "" }),
this.setData({ carsimgs: a });
},
upimg: function () {
var e = this,
t = e.data.carimgs;
t.length >= 9
? a.util.message({ title: "您上传的图片已经很多了", type: "error" })
: (t.length,
a.upimgs({
scannums: 1,
filename: "cars",
success: function (a) {
var i = t.concat(a);
e.setData({ carimgs: i });
},
}));
},
delimg: function (e) {
console.log(e.currentTarget.dataset.index);
var t = e.currentTarget.dataset.index,
i = this.data.carimgs,
s = i[t].all;
a.util.request({
url: "entry/wxapp/Api",
data: {
m: "monai_market",
uid: a.getuid(),
imgurl: s,
r: "Upimg.delImg",
},
}),
i.splice(t, 1),
this.setData({ carimgs: i });
},
onReady: function () {},
onHide: function () {},
onUnload: function () {},
onPullDownRefresh: function () {},
onReachBottom: function () {},
onShareAppMessage: function () {},
});