123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- const app=getApp();
- const utils = require("../../utils/util.js")
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- noticeList: [],
- imageList: [], // 存储图片路径的数组
- // 添加维修类型映射
- repairTypeMap: [
- {name: '换表', value: '1'},
- {name: '换前阀', value: '2'},
- {name: '换后阀', value: '3'},
- {name: '换前后阀', value: '4'},
- {name: '其他', value: '5'}
- ],
- previewImage: '',
- currentImageIndex: 0,
- showPreview: false,
- previewImages: [],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getNoticeList()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- // 获取列表数据
- getNoticeList() {
- const _this = this;
- wx.showLoading({
- title: '获取中...',
- mask: true,
- });
- // debugger;
- wx.request({
- url: app.globalData.interfaceUrls.mineRepair,
- method: 'POST',
- header: {
- 'content-type': 'application/json', // 默认值
- 'token': app.globalData.userWxInfo.token,
- 'source': "wc",
- '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
- },
- success(res) {
- debugger
- wx.hideLoading();
- let apiReturnData = res.data;
- let listData = apiReturnData.data;
-
- listData.forEach(data => {
- // 处理创建日期
- data.createdate = data.createdate ? data.createdate.slice(0, 10) : '';
-
- // 处理图片数据
- let imgs = [];
- if (data.images && typeof data.images === 'string' && data.images.trim() !== '') {
- imgs = data.images.split(',').filter(img => img).map(img => {
- return app.globalData.weChatImgPreviewUrl + 'REPAIR/' + img;
- });
- }
-
- // 设置附件相关属性
- data.hasAttachment = imgs.length > 0;
- data.attachments = imgs;
-
- // 处理回复状态
- data.isReplied = data.iscompleted === '1';
-
- // 处理恢复日期
- if (data.recoverydate) {
- data.recoverydate = data.recoverydate.slice(0, 10);
- } else {
- data.recoverydate = '';
- }
-
- // 转换维修类型值为名称
- if (data.repairtype) {
- const repairTypeItem = _this.data.repairTypeMap.find(item => item.name === data.repairtype);
- data.repairtype = repairTypeItem ? repairTypeItem.name : '未知类型';
- } else {
- data.repairtype = '未知类型';
- }
- });
- app.globalData.mineRepairList = listData;
- _this.setData({
- noticeList: listData,
- })
- debugger
- },
- fail(error) {
- wx.hideLoading()
- utils.simleInfo('获取报修记录,请稍后再试')
- }
- });
- },
- // 预览图片
- previewImage(e) {
- const { id, index } = e.currentTarget.dataset;
- const { noticeList } = this.data;
-
- // 如果是点击列表项的预览按钮
- if (id) {
- const item = noticeList.find(item => item.id === id);
- if (item && item.attachments && item.attachments.length > 0) {
- wx.previewImage({
- current: item.attachments[0], // 当前显示图片的链接
- urls: item.attachments // 需要预览的图片链接列表
- });
- }
- }
- // 如果是点击图片列表中的图片
- else if (typeof index !== 'undefined') {
- const { imageList } = this.data;
- wx.previewImage({
- current: imageList[index], // 当前显示图片的链接
- urls: imageList // 需要预览的图片链接列表
- });
- }
- },
- // 关闭预览
- closePreview() {
- this.setData({
- showPreview: false,
- currentImageIndex: 0,
- previewImages: []
- });
- },
- // 上一张图片
- prevImage() {
- const { currentImageIndex, previewImages } = this.data;
- if (currentImageIndex > 0) {
- this.setData({
- currentImageIndex: currentImageIndex - 1
- });
- }
- },
- // 下一张图片
- nextImage() {
- const { currentImageIndex, previewImages } = this.data;
- if (currentImageIndex < previewImages.length - 1) {
- this.setData({
- currentImageIndex: currentImageIndex + 1
- });
- }
- },
- // 处理滑动事件
- swiperChange(e) {
- const current = e.detail.current;
- this.setData({
- currentImageIndex: current
- });
- },
- // 防止点击图片内容时关闭预览
- preventBubble() {
- return;
- },
- // 跳转到详情页
- goToDetail(e) {
- const id = e.currentTarget.dataset.id;
- const item = this.data.noticeList.find(item => item.id === id);
- // 统一使用预览模式,传递isReplied参数
- wx.navigateTo({
- url: `/pages/baoxiudj/baoxiudj?id=${id}&mode=preview&isReplied=${item.isReplied ? 'true' : 'false'}`
- });
- },
- // 跳转到表单页
- goToForm() {
- wx.navigateTo({
- url: '/pages/baoxiudj/baoxiudj'
- })
- },
- // 返回上一页
- goBack() {
- wx.navigateBack()
- },
- })
|