ll
liukangdong
2024-09-27 0805d05b705633c7d2d55b6f3e92278b65acc426
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import moment from "moment";
import { getContentShareImg } from '../../api/index'
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    bottomLift: 0,
    checkAll: false,
    enjoyList: [],
    leftIcon: '<<',
    rightIcon: '>>',
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onShow(options) {
    var app = getApp().globalData
    this.setData({
      bottomLift: app.bottomLift
    })
    let enjoyList = wx.getStorageSync('enjoyList') || []
    enjoyList.forEach(item => {
      item.checked = false
    })
    wx.setStorageSync('enjoyList', enjoyList)
    console.log(this.data.enjoyList)
    this.initData()
  },
 
  initData() {
    let temp = []
    let enjoyList = wx.getStorageSync('enjoyList') || []
    enjoyList = enjoyList.sort((a,b)=>{
      return b.timestamp - a.timestamp
    })
    let count = 0
    enjoyList.forEach(item  => {
      if(item.checked){
        count++
      }
      item.joinDate = moment(item.timestamp).format('YYYY年MM月DD日')
      item.joinTime = moment(item.timestamp).format('HH:mm')
      const index = temp.findIndex( i => i.joinDate === item.joinDate )
      if(index === -1){
        temp.push({
          joinDate: item.joinDate,
          list: [item]
        })
      }else{
        temp[index].list.push(item)
      }
    })
    this.setData({ checkAll: count === enjoyList.length })
    this.setData({ enjoyList: temp })
    console.log('enjoyList', temp);
 
  },
  itemCheck(e){
    const enjoyList = wx.getStorageSync('enjoyList') || []
    const { id } = e.currentTarget.dataset
    console.log(id);
    enjoyList.forEach(item => {
      if(item.id === id){
        item.checked = !item.checked
      }
    })
    wx.setStorageSync('enjoyList', enjoyList)
   
    this.initData()
  },
  itemClick(e) {
    let map = [
      '/pages/detailDis/product',
      '/pages/detailDis/case',
      '/pages/detailDis/realpic',
      '/pages/consult/detail',
    ]
    const { id, type } = e.currentTarget.dataset
    wx.navigateTo({
      url: map[type] + '?id=' + id,
    })
  },
  bind() {
    const enjoyList = wx.getStorageSync('enjoyList') || []
    const temp = enjoyList.filter(i => i.checked)
    if(temp.length == 0) return wx.showToast({
      title: '请先选择要关联的商品',icon:'none'
    })
    wx.navigateTo({
      url: '/pages/kefu/select',
    })
  },
  handleShare() {
    const { enjoyList } = this.data
    let info = {}
    enjoyList.forEach(item => {
      item.list.forEach(ite => {
        if(ite.checked){
          info = ite
        }
      })
    })
    let map = [
      '/pages/detailDis/product',
      '/pages/detailDis/case',
      '/pages/detailDis/realpic'
    ] 
    console.log(info.id)
    wx.navigateToMiniProgram({
      appId: 'wx208dd1edc0be24ee',
      path: `${map[info.joinType]}?origin=b&id=${info.id}&userId=${wx.getStorageSync('member').id}`,
      envVersion: 'release'
    })
  },
  handleDown() {
    const { enjoyList } = this.data
    let obj = {}
    enjoyList.forEach(item => {
      item.list.forEach(ite => {
        if(ite.checked){
          obj = ite
        }
      })
    })
    console.log('obj', obj);
    let that = this
    getContentShareImg({
      articleId: obj.id + '_' + obj.joinType,
      type: '0',
      // pageUrl: path,
      imgurl: obj.coverImage,
    }).then(res => {
      this.setData({
        isShowPoster: true,
        showShare: false,
        posterUrl: res.data
      })
    })
  },
  saveCard() {
    let that = this
    const posterUrl = this.data.posterUrl
    wx.downloadFile({
      url: posterUrl,
      success: function (res) {
        console.log('下载成功', res);
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success(result) {
            console.log(result)
            that.setData({
              isShowPoster: false
            })
            wx.showToast({
              title: '保存成功',
              icon: 'success',
              duration: 2000
            })
          }
        })
 
      }
    })
  },
  closeCard() {
    this.setData({ isShowPoster: false })
  },
  itemDel() {
    let that = this
    let ids = []
    let { enjoyList } = this.data
    enjoyList.forEach(item => {
      item.list.forEach(ite => {
        if(ite.checked){
          ids.push(ite.id)
        }
      })
    })
    if(ids.length === 0) return wx.showToast({
      title: '请先选择要删除的产品',icon: 'none'
    })
    wx.showModal({
      title: '提示',
      content: '你确认要删除该产品吗',
      success (res) {
        if (res.confirm) {
          let enjoyListTemp = wx.getStorageSync('enjoyList') || []
          ids.forEach(item => {
            const index = enjoyListTemp.findIndex(i => i.id == item)
            console.log('index', index);
            if(index > -1){
              enjoyListTemp.splice(index, 1)
            }
          })
          wx.setStorageSync('enjoyList', enjoyListTemp)
          
          that.initData()
        }
      }
    })
    
  },
  checkAll() {
    this.setData({checkAll:!this.data.checkAll})
    let enjoyList = wx.getStorageSync('enjoyList') || []
    enjoyList.forEach(item => {
      item.checked = this.data.checkAll
    })
    wx.setStorageSync('enjoyList', enjoyList)
    
    this.initData()
  },
  openShare() {
    let count = 0
    const { enjoyList } = this.data
    enjoyList.forEach(item => {
      item.list.forEach(ite => {
        if(ite.checked){
          count ++ 
        }
      })
    })
    if(count != 1) return wx.showToast({
      title: '有且只能选择一个产品',icon: 'none'
    })
    this.setData({
      showShare: true
    })
  },
  onClose() {
    console.log('点击关闭');
    this.setData({
      showShare: false
    })
  },
})