// pages/my/postJob/postJob.js const App = getApp(); const util = require("../../utils/tool"); var utils = require("../../utils/util.js"); let CityArray0 = []; let CityArray1 = []; let CityArray2 = []; Page({ /** * 页面的初始数据 */ data: { appAssetsUrl2: App.appAssetsUrl2, user: wx.getStorageSync("USER"), lng: null, lat: null, // 活动地址 address: null, // 坐标 coordinate: null, multiArray: [], multiIndex: [], // 省 province: null, // 市 city: null, // 区 area: null, // 标题 title: null, // 所属客户 clientId: null, clientList: [], clientIndex: 0, // 兼职分类 category: null, // 兼职类型 type: null, categoryList: [], categoryIndex: 0, typeList: [], typeIndex: 0, // 工作兼职时间 // worktimeStart: null, // worktimeEnd: null, workdateStart: null, workdateEnd: null, worktimeStart: null, worktimeEnd: null, // workStartTimeDate: null, // workStartTimeHS: null, // workEndTimeDate: null, // workEndTimeHS: null, // 报名截止 registrationTime: null, registrationDate: null, registrationHS: null, // 集合时间 meetingTime: null, // 集合日期 meetingTimeDate: null, // 集合日期时间 meetingTimeHS: null, // 是否推荐至首页 isTop: null, arrayPrice: [], priceIndex: 0, // 工资价格 price: null, // 结算方式 cashMethod: null, cashMethodList: [], cashMethodIndex: 0, // 工资单位 unit: null, // 性别要求 sexlimit: null, // 是否需要会员 isNeedVip: 0, heightList: [], heightIndex: 0, // 身高要求 heightlimit: null, // 面试时间 interviewTime: null, // 面试时间 hs interviewTimeHS: null, // 培训时间 trainingTime: null, // 培训时间 hs trainingTimeHS: null, // 报名人数限制 willnum: null, principal: null, activityjs: null, activityyq: null, activitysx: null, // 兼职banner图 indexImg: null, // 联系二维码 qrCodePicture: null, contactInstructions: null, // 注意事项 attention: null, againType: null, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options && options.againType == 1 && options.jobId) { this.setData({ againType: options.againType, }); this.getAgainJobInfo(options.jobId); } else { this.init(); } }, init() { this.getProvince(); this.getCoord(); this.getWorkCategory(); this.getType(); this.getUnit(); this.getHeightList(); this.getclient(); this.getCashMethod(); }, getAgainJobInfo(id) { let user = utils.getUser(); let obj = { id: id, type: 1, //类型(1兼职 2活动) stuId: user ? user.id : "", }; App._post_form("work/one", "", obj, (res) => { if (res.code === 0) { this.setData({ title: res.data.title, address: res.data.address, clientId: res.data.clientId, category: res.data.category, type: res.data.type, province: res.data.province, city: res.data.city, area: res.data.area, coordinate: res.data.coordinate, workdateStart: res.data.workdateStart, workdateEnd: res.data.workdateEnd, worktimeStart: res.data.worktimeStart, worktimeEnd: res.data.worktimeEnd, registrationDate: res.data.registrationTime.split(' ')[0], registrationHS: res.data.registrationTime.split(' ')[1], meetingTimeDate: res.data.meetingTime.split(' ')[0], meetingTimeHS: res.data.meetingTime.split(' ')[1], isTop: res.data.isTop, price: res.data.price, cashMethod: res.data.cashMethod, unit: res.data.unit, sexlimit: res.data.sexlimit, isNeedVip: res.data.isNeedVip, heightlimit: res.data.heightlimit, interviewTime: res.data.interviewTime.split(' ')[0], interviewTimeHS: res.data.interviewTime.split(' ')[1], trainingTime: res.data.trainingTime.split(' ')[0], trainingTimeHS: res.data.trainingTime.split(' ')[1], willnum: res.data.willnum, principal: res.data.principal, activityjs: res.data.workAppletsDetailsList[0], activityyq: res.data.workAppletsDetailsList[1], activitysx: res.data.workAppletsDetailsList[2], indexImg: res.data.indexImg, qrCodePicture: res.data.qrCodePicture, contactInstructions: res.data.contactInstructions, attention: res.data.attention, }); this.init(); } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() {}, // 获取兼职分类 getWorkCategory() { App._post_form("work/category", "", {}, (res) => { if (res.code === 0) { const arr = res.data; this.setData({ categoryList: res.data, }); if (this.data.againType == 1 && this.data.category) { this.getShow(arr, "itemcode", this.data.category, "categoryIndex"); } } }); }, // 获取兼职类型 getType() { App._post_form("bizlibrary/infoList/workType", "", {}, (res) => { if (res.code === 0) { const arr = res.dictList; this.setData({ typeList: res.dictList, }); if (this.data.againType == 1 && this.data.type) { this.getShow(arr, "itemcode", this.data.type, "typeIndex"); } } }); }, // 获取结算方式 getCashMethod() { App._post_form("work/cashMethod", "", {}, (res) => { if (res.code === 0) { const arr = res.data; this.setData({ cashMethodList: res.data, }); if (this.data.againType == 1 && this.data.cashMethod) { this.getShow( arr, "itemcode", this.data.cashMethod, "cashMethodIndex" ); } } }); }, getUnit() { App._post_form("bizlibrary/infoList/workUnit", "", {}, (res) => { if (res.code === 0) { const arr = res.dictList; this.setData({ arrayPrice: res.dictList, }); if (this.data.againType == 1 && this.data.unit) { this.getShow( arr, "itemcode", this.data.unit, "priceIndex" ); } } }); }, getHeightList() { App._post_form("bizlibrary/infoList/workHeightLimit", "", {}, (res) => { if (res.code === 0) { const arr = res.dictList; this.setData({ heightList: res.dictList, }); if (this.data.againType == 1 && this.data.heightlimit) { this.getShow( arr, "itemcode", this.data.heightlimit, "heightIndex" ); } } }); }, getclient() { App._post_form("wgclientinfo/selectCiList", "", {}, (res) => { if (res.code === 0) { const arr = res.list; this.setData({ clientList: res.list, }); if (this.data.againType == 1 && this.data.clientId) { this.getShow(arr, "id", this.data.clientId, "clientIndex"); } } }); }, getShow(arr, key, value, index) { console.log(arr, key, value, index, 22222); for (let i = 0; i < arr.length; i++) { if (arr[i][key] == value) { this.setData({ [index]: i, }); return false; } } }, // 获取经纬度 getCoord() { wx.getLocation({ type: "gcj02", success: (res) => { const latitude = res.latitude; const longitude = res.longitude; this.setData({ lng: Number(longitude), lat: Number(latitude), }); }, fail: (e) => {}, }); }, // 获取省 getProvince() { App._get("region/provinceList", {}, (res) => { let pId = ""; let prov = ""; if (res.code === 0) { let provice = res.data; this.data.multiArray[0] = provice; CityArray0 = provice; if (CityArray0.length) { for (let i = 0; i < CityArray0.length; i++) { if (CityArray0[i].id == this.data.province) { this.data.multiIndex[0] = i; break; } else { this.data.multiIndex[0] = 0; // break; } } } if (this.data.province) { pId = this.data.province; } else { //根据默认省,获取默认市 if (this.data.multiArray[0].length) { pId = this.data.multiArray[0][0].id; } } this.getCity(pId); } }); }, getCity(pId) { App._get(`region/urbanDistrictList?id=${pId}`, {}, (res) => { // App._get(`region/urbanDistrictList?id=420000`, {}, res => { if (res.code === 0) { let city = res.data; this.data.multiArray[1] = city; CityArray1 = city; if (CityArray1.length) { for (let i = 0; i < CityArray1.length; i++) { // console.log(CityArray1[i].id, pId, 222) if (CityArray1[i].pid === pId) { this.data.multiIndex[1] = i; break; } } } let cityId = ""; if (this.data.city) { cityId = this.data.city; } else { if (this.data.multiArray[1].length) { cityId = this.data.multiArray[1][0].id; } } this.getArea(cityId); this.setData({ multiArray: this.data.multiArray, multiIndex: this.data.multiIndex, }); } }); }, // 获取区 getArea(cityId) { for (let i = 0; i < this.data.multiArray[1].length; i++) { console.log(this.data.multiArray[1], cityId, "area"); if (this.data.multiArray[1][i].id === cityId) { CityArray2 = this.data.multiArray[1][i].childRegionList; this.data.multiArray[2] = this.data.multiArray[1][i].childRegionList; this.data.multiIndex[2] = i; break; } } if (this.data.area) { for (let j = 0; j < this.data.multiArray[2].length; j++) { if (this.data.multiArray[2][j].id === this.data.area) { this.data.multiIndex[2] = j; break; } } } this.setData({ multiArray: this.data.multiArray, multiIndex: this.data.multiIndex, }); console.log(this.data.multiArray, this.data.multiIndex, 1111); }, // 兼职分类 categoryChange(e) { console.log(e); let category = this.data.categoryList[e.detail.value].itemcode; this.setData({ category: category, categoryIndex: e.detail.value, }); }, // 兼职类型 typeChange(e) { let type = this.data.typeList[e.detail.value].itemcode; this.setData({ type: type, typeIndex: e.detail.value, }); }, // 结算方式 cashMethodChange(e) { console.log(e); let cashMethod = this.data.cashMethodList[e.detail.value].itemcode; this.setData({ cashMethod: cashMethod, cashMethodIndex: e.detail.value, }); }, // 工资选择 priceChange(e) { console.log(e, 111); let unit = this.data.arrayPrice[e.detail.value].itemcode; this.setData({ unit: unit, priceIndex: e.detail.value, }); }, heightChange(e) { let heightlimit = this.data.heightList[e.detail.value].itemcode; this.setData({ heightlimit: heightlimit, heightIndex: e.detail.value, }); }, clientChange(e) { let clientId = this.data.clientList[e.detail.value].id; this.setData({ clientId: clientId, clientIndex: e.detail.value, }); }, areaChange(e) { this.data.multiIndex[0] = e.detail.value[0]; this.data.multiIndex[1] = e.detail.value[1]; this.data.multiIndex[2] = e.detail.value[2]; let province = CityArray0[e.detail.value[0]].id; let city = CityArray1[e.detail.value[1]].id; let area = CityArray2[e.detail.value[2]].id; this.setData({ multiIndex: this.data.multiIndex, province: province, city: city, area: area, }); }, MultiPickerAreaChange(e) { if (e.detail.column == 0) { let pid = CityArray0[e.detail.value].id; this.data.multiIndex[0] = e.detail.value; this.getCity(pid); } else if (e.detail.column == 1) { let pid = CityArray1[e.detail.value].id; this.data.multiIndex[1] = e.detail.value; this.getArea(pid); } else { this.data.multiIndex[2] = e.detail.value; } this.setData({ multiIndex: this.data.multiIndex, }); }, // 工作日期 workStartTimeBindDateChange(e) { this.setData({ workdateStart: e.detail.value, }); }, workStartTimeBindTimeChange(e) { this.setData({ worktimeStart: e.detail.value, }); }, workEndTimeBindDateChange(e) { this.setData({ workdateEnd: e.detail.value, }); }, workEndTimeBindTimeChange(e) { this.setData({ worktimeEnd: e.detail.value, }); }, // 报名截止 registrationBindDateChange(e) { this.setData({ registrationDate: e.detail.value, }); }, registrationBindTimeChange(e) { this.setData({ registrationHS: e.detail.value, }); }, // 集合时间 meetingBindDateChange(e) { this.setData({ meetingTimeDate: e.detail.value, }); }, meetingBindTimeChange(e) { this.setData({ meetingTimeHS: e.detail.value, }); }, // 面试时间 interviewTimeDateChange(e) { this.setData({ interviewTime: e.detail.value, }); }, interviewTimeChange(e) { this.setData({ interviewTimeHS: e.detail.value, }); }, // 培训时间 trainingTimeDateChange(e) { this.setData({ trainingTime: e.detail.value, }); }, trainingTimeChange(e) { this.setData({ trainingTimeHS: e.detail.value, }); }, // 是否需要会员 freeRadioChange(e) { this.setData({ isNeedVip: e.detail.value, }); }, // 推荐首页 recommendRadioChange(e) { this.setData({ isTop: e.detail.value, }); }, // 性别要求 sexRadioChange(e) { this.setData({ sexlimit: e.detail.value, }); }, changeAddress() { wx.chooseLocation({ success: (res) => { console.log(res, 1111); wx.showLoading({ title: "获取位置中...", }); App._get( "store/getDetailsAddress", { lon: res.longitude, lat: res.latitude, }, (result) => { if (result.code === 0) { wx.hideLoading(); this.setData({ address: result.data.street_number, coordinate: res.longitude + "," + res.latitude, }); } } ); }, }); // wx.navigateTo({ // url: `/activity/map/map?lng=${this.data.lng}&lat=${this.data.lat}`, // }) }, uploadHandle(e) { let currentIndex = e.currentTarget.dataset.index; // if (this.data.list.length == 3) { // return false // } let _this = this; var tempFile; wx.showActionSheet({ itemList: ["拍照上传", "从相册中选择"], success(res) { if (res.tapIndex === 0) { wx.chooseImage({ count: 1, sizeType: ["original", "compressed"], sourceType: ["camera"], success(res) { wx.showLoading({ title: "上传中...", }); const tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: App.apiRoot + "file/upload", filePath: tempFilePaths[0], name: "file", success: function (res) { if (res.errMsg === "uploadFile:ok") { wx.hideLoading(); wx.showToast({ title: "上传成功", image: "", duration: 1500, mask: false, }); let data = JSON.parse(res.data); if (currentIndex == 1) { _this.data.indexImg = data.data; _this.setData({ indexImg: _this.data.indexImg, }); } else { _this.data.qrCodePicture = data.data; _this.setData({ qrCodePicture: _this.data.qrCodePicture, }); } } }, function() { wx.hideLoading(); wx.showToast({ title: "上传失败", icon: "none", image: "", duration: 1500, mask: false, }); }, }); }, }); } else if (res.tapIndex === 1) { wx.chooseImage({ count: 1, sizeType: ["original", "compressed"], sourceType: ["album"], success(res) { wx.showLoading({ title: "上传中...", }); const tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: App.apiRoot + "file/upload", filePath: tempFilePaths[0], name: "file", success: function (res) { if (res.errMsg === "uploadFile:ok") { wx.hideLoading(); wx.showToast({ title: "上传成功", image: "", duration: 1500, mask: false, }); let data = JSON.parse(res.data); if (currentIndex == 1) { _this.data.indexImg = data.data; _this.setData({ indexImg: _this.data.indexImg, }); } else { _this.data.qrCodePicture = data.data; _this.setData({ qrCodePicture: _this.data.qrCodePicture, }); } } }, function() { wx.hideLoading(); wx.showToast({ title: "上传失败", icon: "none", image: "", duration: 1500, mask: false, success: (result) => {}, fail: () => {}, complete: () => {}, }); }, }); }, }); } }, fail(res) {}, }); }, submit() { if (!this.data.clientId) { return util.alert("请先选择所属客户"); } if (!this.data.title) { return util.alert("请先填写兼职标题"); } if (!this.data.category) { return util.alert("请先选择兼职分类"); } if (!this.data.type) { return util.alert("请先选择兼职类型"); } if (!this.data.city || !this.data.area) { return util.alert("请先选择所属区域"); } if (!this.data.address) { return util.alert("请先选择兼职地址"); } if (!this.data.workdateStart || !this.data.workdateEnd) { return util.alert("请先选择工作日期"); } if (!this.data.worktimeStart || !this.data.worktimeEnd) { return util.alert("请先选择工作时间"); } if (!this.data.registrationDate || !this.data.registrationHS) { return util.alert("请先选择报名截止时间"); } // if (this.data.registrationDate && this.data.workdateStart) { // let endTime = new Date( // this.data.registrationDate + " " + this.data.registrationHS // ).getTime(); // let workTime = new Date( // this.data.workdateStart + " " + this.data.worktimeStart // ).getTime(); // if (endTime >= workTime) { // return util.alert("报名截止时间不得大于工作时间"); // } // } if (!this.data.meetingTimeDate || !this.data.meetingTimeHS) { return util.alert("请先选择集合时间"); } if (!this.data.price) { return util.alert("请先填写工资价格"); } if (!this.data.unit) { return util.alert("请先选择工资单位"); } if (!this.data.heightlimit) { return util.alert("请先选择身高要求"); } if (!this.data.willnum) { return util.alert("请先填写报名人数限制"); } if (!this.data.indexImg) { return util.alert("请先上传兼职详情banner图"); } if (!this.data.activityjs) { return util.alert("请先填写兼职介绍"); } if (!this.data.activityyq) { return util.alert("请先填写兼职要求"); } if (!this.data.activitysx) { return util.alert("请先填写注意事项"); } if (!this.data.attention) { return util.alert("请先填写注意事项"); } if (!this.data.qrCodePicture) { return util.alert("请先上传联系二维码图"); } if (!this.data.contactInstructions) { return util.alert("请先填写联系说明"); } wx.showLoading({ title: "提交中,请稍后", }); let list = [ this.data.activityjs, this.data.activityyq, this.data.activitysx, ]; let obj = { category: this.data.category, type: this.data.type, address: this.data.address, area: this.data.area, indexImg: this.data.indexImg, city: this.data.city, workAppletsDetailsList: list, coordinate: this.data.coordinate, workdateEnd: this.data.workdateEnd, worktimeEnd: this.data.worktimeEnd, isNeedVip: this.data.isNeedVip == 1 ? true : false, isTop: this.data.isTop, meetingTime: this.data.meetingTimeDate + " " + this.data.meetingTimeHS, price: this.data.price, unit: this.data.unit, cashMethod: this.data.cashMethod, sexlimit: this.data.sexlimit, province: this.data.province, registrationTime: this.data.registrationDate + " " + this.data.registrationHS, clientId: this.data.clientId, heightlimit: this.data.heightlimit, interviewTime: this.data.interviewTime + " " + this.data.interviewTimeHS, trainingTime: this.data.trainingTime + " " + this.data.trainingTimeHS, workdateStart: this.data.workdateStart, worktimeStart: this.data.worktimeStart, qrCodePicture: this.data.qrCodePicture, contactInstructions: this.data.contactInstructions, title: this.data.title, willnum: this.data.willnum, principal: this.data.principal, attention: this.data.attention, memberId: this.data.user.id, // is_applets_release 是否是小程序发布 1是 0否 isAppletsRelease: 1, }; wx.setStorageSync("workDetail", obj); wx.navigateTo({ url: "/job/postJob/detail", }); return false; // App._post_form('work/saveWork', '', obj, res => { // if (res.code === 0) { // wx.showToast({ // title: '添加成功', // }) // wx.removeStorageSync('workDetail') // } // }, err => {}, complete => { // setTimeout(() => { // wx.hideLoading() // }, 300) // }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom() {}, /** * 用户点击右上角分享 */ onShareAppMessage() {}, });