// pages/mine/mineAccount/mineOrder/mineOrder.js import UserApi from '../../../../net/api/userApi' const { isValidPhone, isValidEmail } = require('../../../../utils/validator') const app = getApp() const Cache = require('../../../../utils/storage') Page({ /** * 页面的初始数据 */ data: { slideBtns: app.globalData.slideBtns, contactList: [], //联系人列表 pageData: { page: 1, rows: 10, keywords: '' }, //检索参数 loadingState: 'loading', //加载状态 listRefreshTrig: false, //list刷新状态 isLoadMore: false, //加载更多的状态 hasMore: true, //是否有更多数据 keywords: '', //搜索关键字 showCreateContact: false, //创建联系人 contactCompany: '', //公司名称 contactEmail: '', //联系邮箱 contactName: '', //名字 contactPhone: '', //联系电话 showError: false, errorHint: '', showSuccess: false, successHint: '', csaNo: '', //客服号 title: '创建联系人', btnTxt: '保存', isCreate: true, //创建还是编辑 tempContact: null, //修改的联系人 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.setNavigationBarTitle({ title: '产权联系人', }) wx.setNavigationBarColor({ frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000 backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色 animation: { // 可选项 duration: 500, timingFunc: 'easeIn' } }) this.doGetCsaNo() this.doRefreshList() }, inputKeywords(e) { this.setData({ keywords: e.detail.value }) }, inputContactName(e) { console.log(e) this.setData({ contactName: e.detail.value }) }, inputContactPhone(e) { this.setData({ contactPhone: e.detail.value }) }, inputContactEmail(e) { this.setData({ contactEmail: e.detail.value }) }, inputContactCompany(e) { this.setData({ contactCompany: e.detail.value }) }, //显示创建联系人弹窗 showCreateDialog() { this.setData({ title: '创建', showCreateContact: true, contactName: '', contactCompany: '', contactEmail: '', contactPhone: '', isCreate: true }) }, //显示编辑弹窗 showEditDialog(item) { const _self = this _self.setData({ title: '编辑', showCreateContact: true, contactName: item.name, contactPhone: item.phone, contactEmail: item.email, contactCompany: item.company, isCreate: false, tempContact: item }) }, //获取客服NO doGetCsaNo(isShow) { const _self = this UserApi.doGetCsaNo() .then(res => { console.log(res) _self.setData({ csaNo: res.csaNo }) if (isShow) { _self.setData({ isShowContact: true }) } }, err => { console.log(err) }) }, showDelDialog(item) { const _self = this wx.showModal({ title: '警告', content: '一旦删除,该联系人信息将无法恢复,你仍要删除吗?', complete: (res) => { if (res.confirm) { _self.doDelContact(item.projContactId) } } }) }, //删除联系人 doDelContact(id) { const _self = this wx.showLoading({ title: '删除中...', }) UserApi.doDelContact(id) .then(res => { wx.hideLoading() _self.setData({ showSuccess: true, successHint: '删除成功' }) _self.doRefreshList() }, err => { wx.hideLoading() _self.setData({ showError: true, errorHint: err.msg ? err.msg : '删除失败,请稍后重试' }) }) }, //保存修改联系人 doEditContact() { //校验参数 const _self = this if (_self.data.contactName == '') { _self.setData({ showError: true, errorHint: '请输入联系人姓名' }) return } if (_self.data.contactPhone == '' || !isValidPhone(_self.data.contactPhone)) { _self.setData({ showError: true, errorHint: '请输入正确的联系电话' }) return } if (_self.data.contactEmail != '') { if (!isValidEmail(_self.data.contactEmail)) { _self.setData({ showError: true, errorHint: '请输入正确的邮箱' }) return } } wx.showLoading({ title: '保存中...', }) const data = { "company": _self.data.contactCompany, "csaNo": _self.data.tempContact.csaNo, "name": _self.data.contactName, "phone": _self.data.contactPhone, "email": _self.data.contactEmail, } UserApi.doUpdateContactList(_self.data.tempContact.projContactId, data) .then(res => { wx.hideLoading() _self.setData({ showSuccess: true, successHint: '修改成功', showCreateContact: false, contactEmail: '', contactPhone: '', contactName: '', contactCompany: '', tempContact: null, }) //获取一遍联系人 _self.doRefreshList() }, err => { wx.hideLoading() _self.setData({ showError: true, errorHint: err.msg ? err.msg : '新建失败,请稍后重试', showCreateContact: false }) }) }, //创建联系人 doSaveContact() { //校验参数 const _self = this if (_self.data.contactName == '') { _self.setData({ showError: true, errorHint: '请输入联系人姓名' }) return } if (_self.data.contactPhone == '' || !isValidPhone(_self.data.contactPhone)) { _self.setData({ showError: true, errorHint: '请输入正确的联系电话' }) return } if (_self.data.contactEmail != '') { if (!isValidEmail(_self.data.contactEmail)) { _self.setData({ showError: true, errorHint: '请输入正确的邮箱' }) return } } wx.showLoading({ title: '创建中...', }) const data = { "company": _self.data.contactCompany, "csaNo": _self.data.csaNo, "name": _self.data.contactName, "phone": _self.data.contactPhone, "email": _self.data.contactEmail, } UserApi.doCreateContact(data) .then(res => { wx.hideLoading() _self.setData({ showSuccess: true, successHint: '新建成功', showCreateContact: false, contactEmail: '', contactPhone: '', contactName: '', contactCompany: '', }) //获取一遍联系人 _self.doRefreshList() }, err => { wx.hideLoading() _self.setData({ showError: true, errorHint: err.msg ? err.msg : '新建失败,请稍后重试', showCreateContact: false }) }) }, //刷新列表 doRefreshList() { console.log('正在刷新...') const _self = this _self.setData({ listRefreshTrig: true, loadingState: 'loading', hasMore: true, 'pageData.page': 1, 'pageData.keywords': _self.data.keywords, isLoadMore: false }) _self.doGetMineContactList(true) }, //加载更多 doLoadMore() { //判断是否正在加载中 与是否存在更多数据 const _self = this if (_self.data.isLoadMore || !_self.data.hasMore) { return } _self.setData({ isLoadMore: true, 'pageData.page': ++_self.data.pageData.page, 'pageData.keywords': _self.data.keywords }) _self.doGetMineContactList(false) }, //获取我的联系人列表 isRefresh false 加载更多 true 刷新 doGetMineContactList(isRefresh) { const _self = this _self.setData({ contactList: isRefresh ? [] : _self.data.contactList, loadingState: isRefresh ? 'loading' : '' }) UserApi.doGetMineContactList(_self.data.pageData) .then(res => { console.log(res) var status = 'success' status = res.rows && res.rows.length > 0 ? 'success' : 'empty' _self.setData({ loadingState: isRefresh ? status : '', contactList: _self.data.contactList.concat(res.rows), listRefreshTrig: false, isLoadMore: false }) _self.setData({ hasMore: _self.data.contactList.length < res.total }) //首次提示滑动删除和编辑 _self.showEditDel() }, err => { _self.setData({ loadingState: 'error', listRefreshTrig: false, isLoadMore: false, hasMore: true }) }) }, //首次提示滑动删除和编辑 showEditDel() { const _self = this const isFirst = Cache.get('contactFirst', '0') if (isFirst == '0') { const item = _self.selectComponent('#mp-slide-0') if (item) { item.setData({ show: true }) Cache.set('contactFirst', '1') } } }, //清除搜索内容 clearSearch() { const _self = this _self.setData({ keywords: '' }) _self.doRefreshList() }, //发起搜索 doSearchKeyWord() { const _self = this _self.doRefreshList() }, hide(e) { }, show(e) { }, //滑动条目 slideButtonTap(e) { const item = e.currentTarget.dataset.value const index = e.detail.index console.log(index) if (index == 0) { this.showEditDialog(item) } else { this.showDelDialog(item) } }, closeDialog(e) { this.setData({ showCreateContact: false }) } })