123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779 |
- // index.js
- // 获取应用实例
- const app = getApp();
- const util = require('../../../utils/jmsUtil.js');
- const api = require('../../../api/jms.js');
- import moment from 'moment'
- Page({
- data: {
- fullWorkers: [],
- failworker: '', //校验失败提升
- workerScheduleList: [], //被选全职的档期
- workerDayTimeRange: { //被选某天的档期
- workerTimeRangeList: [],
- },
- showFullworker: false,
- currmonth: '',
- monthArray: [],
- showMonth: false,
- showquanzhi: false,
- chooseRow: null, //{},改全职当前行
- skillVisible: false,
- tempIndex: '',
- gomaps: false, //点击地图
- closecusType: false, //点击客户信息
- closeWorker: false,
- serviceId: '',
- keywords: '',
- wholeList: [],
- workerList: [],
- scrollShow: false,
- orderInfo: { //上个页面参数
- fraId: '',
- serviceId: ''
- },
- bookDetailInfo: { //工单人员详情
- detailId: '',
- skillWorkerTotalList: [],
- workers: []
- },
- selectValue: '',
- selectVisible: false,
- selectKey: '',
- skillTimerange: [], //每个节能时长的时段
- timeList: [],
- currentDate: new Date().getTime(),
- },
- // 事件处理函数
- setThreeMonth() {
- let currmonth = moment(new Date()).format('YYYY-MM');
- let temparr = [];
- temparr.push(currmonth);
- for (var i = 0; i < 2; i++) {
- currmonth = util.getYearMonth(currmonth, '+');
- temparr.push(currmonth);
- }
- this.setData({
- currmonth: temparr[0],
- monthArray: temparr
- })
- },
- onLoad(options) {
- let orderInfo = app.globalData.orderInfo;
- console.log(orderInfo);
- let time = (orderInfo.bookStartTime ? (orderInfo.bookStartTime + '-' + orderInfo.bookEndTime) : '');
- orderInfo.time = time;
- this.setData({
- orderInfo: orderInfo
- });
- this.getBookDetail(); //工单详情
- this.getWorkerList(); //兼职人员
- this.getTimeList(); //服务时段
- this.setThreeMonth(); //未来3月
- },
- onshow() {
- // 页面显示
- // const location = chooseLocation.getLocation();
- // console.log(location);
- // if(location!=null){
- },
- getBookDetail() {
- //查询工单详情
- util.request(api.getDetailWorker, {
- detailId: this.data.orderInfo.serviceId
- }, 'GET').then(res => {
- if (res.errno == 0) {
- let tempData = res.data;
- tempData.workers2 = tempData.workers; //构造未修改信息
- // res.data.data.workers.forEach(p => {
- // if (p.bookStartTime != null && p.bookStartTime != '' && p.bookStartTime != 'null') {
- // }
- // })
- this.setData({
- bookDetailInfo: tempData
- })
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- });
- },
- getWorkerList() {
- util.request(api.ServiceOrderPerson, {
- pageNo: 1,
- pageSize: 1000
- }, 'POST').then(res => {
- if (res.errno == 0) {
- this.setData({
- wholeList: res.data.list,
- workerList: res.data.list,
- });
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- });
- },
- getTimeList() {
- util.request(api.GetGoodsTimeRange, {
- orderId: this.data.orderInfo.orderId
- }, 'GET').then(res => {
- if (res.errno == 0) {
- this.setData({
- skillTimerange: res.data,
- });
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- });
- },
- inputClue(e) {
- let obj = e.currentTarget.dataset.obj;
- let item = `clueInfo.${obj}`;
- this.setData({
- [item]: e.detail.value
- });
- // console.log(this.data.clueInfo);
- },
- selectClue(e) {
- let obj = e.currentTarget.dataset.obj;
- this.setData({
- selectKey: obj,
- selectVisible: true
- });
- console.log(this.data.selectKey);
- },
- onPickerConfirm(e) {
- console.log(e);
- let obj = {
- label: e.detail.value.text,
- value: e.detail.value.value
- }
- if( e.detail.value.length==0){
- return;
- }
- let tempdata = this.data.bookDetailInfo.workers[this.data.tempIndex];
- tempdata.bookStartTime = e.detail.value.split('-')[0];
- tempdata.bookEndTime = e.detail.value.split('-')[1];
- this.setData({
- selectVisible: false,
- 'bookDetailInfo.workers': this.data.bookDetailInfo.workers,
- });
- },
- onPickerCancel() {
- this.setData({
- selectVisible: true
- });
- },
- inputWorker(e) {
- // console.log(e);
- let keywords = e.detail.value;
- let list = this.data.wholeList;
- let newList = [];
- if (keywords == '') {
- newList = this.data.wholeList;
- this.setData({
- 'orderInfo.workerId': ''
- });
- } else {
- list.forEach(item => {
- if (item.name.indexOf(keywords) > -1) {
- newList.push(item);
- }
- });
- }
- this.setData({
- workerList: newList
- });
- },
- selectWorker(e) {
- let tempIndex = e.target.dataset.index;
- let tempdata = this.data.bookDetailInfo.workers[tempIndex];
- if (tempdata.type == null || tempdata.type == 0) {
- //全职
- tempdata.workerName = '';
- tempdata.timeRange = '';
- let tempsklist = this.data.bookDetailInfo.skillWorkerTotalList;
- if (tempsklist != null && tempsklist.length == 1) { //单人服务设置默认技能
- tempdata.workerSkillId = tempsklist[0].skillId;
- tempdata.skillName = tempsklist[0].skillName;
- }
- this.setData({
- showquanzhi: true,
- chooseRow: tempdata,
- tempIndex: e.target.dataset.index,
- fullWorkers: [],
- workerScheduleList: [],
- workerDayTimeRange: {},
- });
- //加载全职人员信息
- this.getFullWorker();
- return;
- }
- this.setData({
- scrollShow: true,
- tempIndex: e.target.dataset.index,
- });
- },
- getFullWorker() {
- let r = this.data.chooseRow;
- if (r.workerSkillId == null || r.workerSkillId == '') { //等选择技能后再查询
- return;
- }
- let params = {
- serviceId: this.data.bookDetailInfo.detailId,
- month: this.data.currmonth,
- skillId: r.workerSkillId
- };
- util.request(api.getWorkersByServiceId,
- params, 'GET').then(res => {
- if (res.errno == 0) {
- this.setData({
- fullWorkers: res.data.workers,
- workerScheduleList: [],
- workerDayTimeRange: {}
- })
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- }).catch(err => {
- console.log(err);
- });
- },
- closesCrollShow() {
- this.setData({
- scrollShow: false
- });
- },
- workerTap(e) {
- let id = e.currentTarget.dataset.id;
- let name = e.currentTarget.dataset.name;
- let workerTel = e.currentTarget.dataset.tel;
- let tempdata = this.data.bookDetailInfo.workers[this.data.tempIndex];
- tempdata.type = 1;
- tempdata.workerId = id;
- tempdata.workerName = name;
- tempdata.workerTel = workerTel;
- this.setData({
- scrollShow: false,
- 'bookDetailInfo.workers': this.data.bookDetailInfo.workers
- })
- },
- selectDateTime(e) {
- let tempdata = this.data.bookDetailInfo.workers[e.target.dataset.index];
- if (tempdata.type == null || tempdata.type == 0) {
- wx.showToast({
- title: '全职类型请选择改派操作',
- icon: 'none'
- })
- return
- }
- this.setData({
- dateTimeVisible: true,
- tempIndex: e.target.dataset.index,
- });
- },
- hidePicker() {
- this.setData({
- dateTimeVisible: false
- });
- },
- onDateTimeConfirm(e) {
- console.log(e);
- let tempdata = this.data.bookDetailInfo.workers[this.data.tempIndex];
- tempdata.bookDate = util.formetdate(new Date(e.detail));
- this.setData({
- currentDate: e.detail,
- 'bookDetailInfo.workers': this.data.bookDetailInfo.workers,
- dateTimeVisible: false
- });
- },
- selectDate(e) {
- let tempdata = this.data.bookDetailInfo.workers[e.target.dataset.index];
- if (tempdata.type == null || tempdata.type == 0) {
- wx.showToast({
- title: '全职类型请选择改派操作',
- icon: 'none'
- })
- return
- }
- let range = [];
- this.data.skillTimerange.forEach(e => {
- if (e.serviceLength == tempdata.serviceLength) {
- range = e.timeRange;
- }
- })
- this.setData({
- selectVisible: true,
- tempIndex: e.target.dataset.index,
- timeList: range
- });
- },
- onPickerCancel() {
- this.setData({
- selectVisible: false
- });
- },
- inputAddress(e) {
- this.setData({
- 'bookDetailInfo.bookAddress': e.detail.value,
- gomaps: true
- });
- },
- goMap() {
- this.setData({
- gomaps: true
- })
- // const key = "JA2BZ-XGOEU-UNZVD-46G64-S6MYJ-6BBF4";
- //使用在腾讯位置服务申请的key
- // const key = '6TRBZ-XXC6F-BWWJB-N75ME-BQNOF-YKFQY';
- // const referer = '鲸致生活'; //调用插件的app的名称
- // const category = '小区,生活服务,娱乐休闲';
- // wx.navigateTo({
- // url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&category=' + category
- // });
- let that = this;
- let lng = this.data.bookDetailInfo.lng;
- let lat = this.data.bookDetailInfo.lat;
- // if (lnglat.length > 0) {
- // lng = Number(lnglat[0]);
- // lat = Number(lnglat[1]);
- // }
- console.log(lng, lat);
- wx.chooseLocation({
- longitude: lng,
- latitude: lat,
- success: function (location) {
- console.log(location);
- if (location != null && location.address != '' && location.name != '') {
- that.setData({
- 'bookDetailInfo.bookAddress': location.address + location.name,
- 'bookDetailInfo.lng': location.longitude,
- 'bookDetailInfo.lat': location.latitude,
- });
- } else {
- wx.showToast({
- title: '请选择地图下方地址',
- icon: 'none'
- })
- }
- },
- fail: function () {
- console.log();
- }
- })
- },
- saveAddress() {
- if (this.data.bookDetailInfo.bookAddress == '' || this.data.bookDetailInfo.bookAddress.length < 12) {
- wx.showToast({
- title: '请选择或输入详细地址后再提交',
- icon: 'none'
- })
- this.setData({
- gomaps: false
- })
- return;
- }
- let lat = this.data.bookDetailInfo.lat + '';
- let lng = this.data.bookDetailInfo.lng + '';
- if (lat != null && lat.length > 9) {
- lat = lat.substring(0, 9)
- }
- if (lng != null && lng.length > 9) {
- lng = lng.substring(0, 9)
- }
- let params = {
- detailId: this.data.bookDetailInfo.detailId,
- bookName: this.data.bookDetailInfo.bookName,
- bookTel: this.data.bookDetailInfo.bookTel,
- bookAddress: this.data.bookDetailInfo.bookAddress,
- lat: lat,
- lng: lng
- };
- wx.showLoading({
- title: '加载中',
- })
- util.request(api.modifyBookAddress,
- params, 'POST').then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- this.getBookDetail();
- wx.showModal({
- title: '提示',
- content: '操作成功',
- showCancel: false,
- complete: (res) => {}
- })
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- }).catch(err => {
- wx.hideLoading();
- });
- },
- validChooseWorker() {
- //如果条件任意一个没选,丢弃结果
- //校验预约时间不能小于当天,且预约日期要统一
- console.log(this.data.bookDetailInfo.workers);
- let validWorker = [];
- let failworker = '';
- let ss=this.data.bookDetailInfo.workers.filter(e=>{
- return e.bookDate!=null&&e.bookDate!=''&&e.bookStartTime!=null&&e.bookStartTime!='';
- })
- if(ss==null||ss.length==0){
- failworker = "至少选择一个预约日期;";
- return [];
- }
- this.data.bookDetailInfo.workers.forEach(e => {
- if (e.workerId != null && e.workerId != '' && e.workerName != null && e.workerName != '' &&
- (e.type == null || e.workerSkillId == null || e.workerSkillId == '' || e.workerName == null || e.workerName == ''
- )
- ) {
- failworker = failworker + e.workerName + " 服务技能未选;"
- }
-
- if(e.bookDate!=null&&e.bookDate!=''&&e.bookStartTime!=null&&e.bookStartTime!=''){
- validWorker.push(e);
- }
- // if (e.type != null && e.workerSkillId != null && e.workerSkillId != '' &&
- // e.workerId != null && e.workerId != '' && e.workerName != null && e.workerName != ''
- // ) {
- // validWorker.push(e);
- // // if (e.type == 0 && e.scheduleId != null && e.scheduleId != '') {
- // // } else {
- // // validWorker.push(e);
- // // }
- // }
- })
- this.setData({
- failworker: failworker
- })
- if (validWorker.length > 1) {
- //校验相同日期
- for (var i = 0; i < validWorker.length; i++) {
- let tm = validWorker[i].bookDate + validWorker[i].bookEndTime;
- let wk = validWorker[i].workerId;
- for (var k = 0; k < validWorker.length; k++) {
- let tm2 = validWorker[k].bookDate + validWorker[k].bookEndTime;
- let wk2 = validWorker[k].workerId;
- if (validWorker[i].bookDate != validWorker[k].bookDate) {
- this.setData({
- failworker: this.data.failworker + '多人服务时,日期不可跨天;'
- })
- return [];
- }
- if (validWorker[i].workerSkillId == validWorker[k].workerSkillId && tm != tm2) {
- this.setData({
- failworker: this.data.failworker + '相同技能,服务时间必须一致;'
- })
- return [];
- }
- }
- }
- }
- return validWorker;
- },
- confTap() {
- let worker = this.validChooseWorker();
- if (this.data.failworker != '') {
- wx.showToast({
- title: this.data.failworker,
- icon: 'none'
- });
- return;
- }
- wx.showLoading({
- title: '加载中',
- })
- let params = {
- detailId: this.data.bookDetailInfo.detailId,
- fraId: this.data.orderInfo.fraId,
- // bookDate: worker.length == 0 ? this.data.bookDetailInfo.bookDate : worker[0].bookDate,
- // bookStartTime: worker.length == 0 ? this.data.bookDetailInfo.bookStartTime : worker[0].bookStartTime,
- // bookEndTime: worker.length == 0 ? this.data.bookDetailInfo.bookEndTime : worker[0].bookEndTime,
- workerInfoList: worker.length==0?this.data.bookDetailInfo.workers2:worker
- }
- util.request(api.changeWorker,
- params, 'POST').then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- this.getBookDetail();
- wx.showModal({
- title: '提示',
- content: '操作成功',
- showCancel: false,
- complete: (res) => {
- if (res.cancel) {}
- if (res.confirm) {
- wx.navigateBack({
- delta: 1
- });
- }
- }
- })
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- }).catch(err => {
- wx.hideLoading();
- });
- },
- closecus(e) {
- console.log(e);
- this.setData({
- closecusType: !this.data.closecusType
- })
- },
- closeWorker() {
- this.setData({
- closeWorker: !this.data.closeWorker
- })
- },
- workerTypeTab(e) {
- console.log(e);
- let index = e.target.dataset.index;
- let type = e.target.dataset.type;
- let tempdata = this.data.bookDetailInfo.workers[index];
- //兼职切全职,清除人员信息
- if (tempdata.type != null && ((tempdata.type == 0 && type == 1) || (tempdata.type == 1 && type == 0))) {
- tempdata.workerId = '';
- tempdata.workerName = '';
- tempdata.workerTel = '';
- }
- tempdata.type = type;
- this.setData({
- 'bookDetailInfo.workers': this.data.bookDetailInfo.workers
- })
- },
- skillTap(e) {
- let tempdata = this.data.bookDetailInfo.workers[e.target.dataset.index];
- if (tempdata.type == null || tempdata.type == 0) {
- wx.showToast({
- title: '全职类型请选择改派操作',
- icon: 'none'
- })
- return
- }
- this.setData({
- tempIndex: e.target.dataset.index,
- skillVisible: true,
- });
- },
- skillTapfullworker(e) {
- this.setData({
- tempIndex: e.target.dataset.index,
- skillVisible: true,
- });
- },
- skillTapCancel() {
- this.setData({
- skillVisible: false,
- });
- },
- skillTapConfirm(e) {
- console.log(e);
- let tempdata = this.data.bookDetailInfo.workers[this.data.tempIndex];
- tempdata.workerSkillId = e.detail.value.skillId;
- tempdata.skillName = e.detail.value.skillName;
- if (this.data.chooseRow != null) { //选择全职时,
- console.log('选了全职chooseRow', this.data.chooseRow);
- //修改技能要清除已选的人员
- let chooseRow = this.data.chooseRow;
- chooseRow.workerId = '';
- chooseRow.workerName = '';
- chooseRow.workerTel = '';
- chooseRow.scheduleId = '',
- this.setData({
- chooseRow: chooseRow,
- skillVisible: false,
- });
- this.getFullWorker();
- return; //最后确认再改派再更新值
- }
- this.setData({
- skillVisible: false,
- 'bookDetailInfo.workers': this.data.bookDetailInfo.workers
- });
- },
- showMonthTap() {
- this.setData({
- showMonth: true
- })
- },
- monthCancel() {
- this.setData({
- showMonth: false,
- })
- },
- monthConfirm(e) {
- this.data.chooseRow.workerId = '';
- this.data.chooseRow.workerName = '';
- this.data.chooseRow.workerTel = '';
- this.setData({
- showMonth: false,
- chooseRow: this.data.chooseRow,
- currmonth: e.detail.value
- })
- this.getFullWorker();
- },
- closesQuanzhi() {
- this.setData({
- showquanzhi: false,
- chooseRow: null
- })
- },
- confirmQuanzhi() {
- let tempdata = this.data.chooseRow;
- if (tempdata.workerId == '' || tempdata.workerTel == '' || tempdata.bookDate == '' || tempdata.timeRange == '' || tempdata.workerSkillId == '' ||
- tempdata.workerId == null || tempdata.workerTel == null || tempdata.bookDate == null || tempdata.timeRange == null || tempdata.workerSkillId == null) {
- wx.showToast({
- title: '请选择月份、人员,日期,时段后再确认操作',
- icon: 'none'
- })
- return;
- }
- tempdata = this.chooseRow;
- this.setData({
- showquanzhi: false,
- 'bookDetailInfo.workers': this.data.bookDetailInfo.workers,
- chooseRow: null
- })
- },
- selectFullWorker() {
- this.setData({
- showFullworker: true
- })
- },
- fullWorkerCancel() {
- this.setData({
- showFullworker: false
- })
- },
- fullWorkerConfirm(e) { //选择全职人员时
- let dt = e.detail.value;
- if (dt.length == 0) {
- this.setData({
- showFullworker: false
- })
- return;
- }
- let tempdata = this.data.bookDetailInfo.workers[this.data.tempIndex];
- tempdata.workerId = dt.workerId;
- tempdata.workerName = dt.workerName;
- tempdata.workerTel = dt.workerTel;
- // tempdata.scheduleId = '',
- this.setData({
- showFullworker: false,
- chooseRow: tempdata,
- workerScheduleList: dt.workerScheduleList,
- workerDayTimeRange: {}
- })
- if (dt.workerScheduleList.length > 0) {
- this.setData({
- workerDayTimeRange: dt.workerScheduleList[0]
- })
- }
- },
- chooseScheDay(e) {
- //点击某日档期
- console.log(e.currentTarget.dataset.index);
- let dayrange = this.data.workerScheduleList[e.currentTarget.dataset.index];
- this.data.chooseRow.scheduleId = '';
- this.data.chooseRow.timeRange = '';
- this.setData({
- workerDayTimeRange: dayrange,
- chooseRow: this.data.chooseRow
- })
- },
- chooseOccpy(e) {
- console.log(e.currentTarget.dataset.index);
- let chooseTime = this.data.workerDayTimeRange.workerTimeRangeList[e.currentTarget.dataset.index];
- let tm = chooseTime.timeRange.split('-');
- let row = this.data.chooseRow;
- row.type = 0;
- row.bookDate = this.data.workerDayTimeRange.formatDay;
- row.scheduleId = this.data.workerDayTimeRange.scheduleId;
- row.bookStartTime = tm[0];
- row.bookEndTime = tm[1];
- row.timeRange = chooseTime.timeRange;
- this.setData({
- chooseRow: this.data.chooseRow
- })
- }
- })
|