zhongshujie
2024-12-12 09e445694a7360893a17152252f2dc5c1b77b2cf
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
// components/popup/index.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
 
  },
  ready() {
    var that = this;
    // 动态获取屏幕高度
    wx.getSystemInfo({
      success: (result) => {
        that.setData({
          height: result.windowHeight
        });
      },
    })
  },
  properties: {
    showIndex: {
      type: String
    },
    bookIcon: {
      type: String,
      value: ''
    },
    bookName: {
      type: String,
      value: ''
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    inputStyle: 'border: 2rpx solid rgba(220,220,220,1);border-radius: 12rpx; padding: 0 0 0 16rpx;',
    showIndex: null, //打开弹窗的对应下标
    height: '', //屏幕高度
    inputvalue: '',
    textvalue: '',
    ratevalue: 0,
    textError: false,
  },
 
  /**
   * 组件的方法列表
   */
  methods: {
    openPopup(e) {
      var index = e.currentTarget.dataset.index;
      this.setData({
        showIndex: index
      })
    },
    //关闭弹窗
    closePopup() {
      this.setData({
        showIndex: null,
        ratevalue: 0,
        inputvalue: '',
        textvalue: ''
      })
    },
    // 评分改变
    onChangeRate(e) {
      console.log(e.detail);
      this.setData({
        ratevalue: e.detail.value
      });
    },
    // 输入框改变
    inputChange(e) {
      this.setData({
        inputvalue: e.detail.value
      })
    },
    // 文本框改变
    textareaChange(e) {
      this.setData({
        textvalue: e.detail.value
      })
    },
    async feedBack() {
      let content = {
        source: this.data.ratevalue,
        phone: this.data.inputvalue,
        content: this.data.textvalue,
        icon: this.properties.bookIcon
      }
      let query = {
        topicIdOrRefCode: 'bookOpinion',
        name: this.properties.bookName,
        content: JSON.stringify(content),
        type: 'ProductComment',
        cmsTypeRefCode: '',
        newDataListRequest: []
      }
 
      await app.MG.ugc.newTopicMessage(query).then((res) => {
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        })
        this.closePopup()
      })
    },
    // 确定
    async confirmSuggest() {
      const telephoneCheck = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
      const istelePhone = telephoneCheck.test(this.data.inputvalue)
      const textvalue = this.data.textvalue.trim()
      if (!this.data.ratevalue) {
        return wx.showToast({
          icon: "error",
          title: '请选择评分',
        })
      } else if (!this.data.inputvalue.length) {
        return wx.showToast({
          icon: "error",
          title: '请填写联系方式',
        })
      } else if (!istelePhone) {
        return wx.showToast({
          icon: "error",
          title: '请输入正确联系方式',
        })
      } else if (!textvalue.length) {
        return wx.showToast({
          icon: 'error',
          title: '请输入反馈内容',
        })
      }
      await this.feedBack()
    }
  }
})