|
@@ -18,11 +18,12 @@
|
|
|
<switch color="#EA5A49" @change="getPhone" :checked="phone"/>
|
|
|
<span class="text-primary">{{phone}}</span>
|
|
|
</div>
|
|
|
+ <button class="btn" @click="addComment">评论</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import {get} from '@/util'
|
|
|
+import {get, post, showModal} from '@/util'
|
|
|
import BookInfo from '@/components/BookInfo'
|
|
|
export default {
|
|
|
components: {
|
|
@@ -30,6 +31,7 @@ export default {
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
+ userinfo: {},
|
|
|
bookid: '',
|
|
|
info: {},
|
|
|
comment: '',
|
|
@@ -38,8 +40,58 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- getGeo () {
|
|
|
-
|
|
|
+ async addComment () {
|
|
|
+ if (!this.comment) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 评论内容 手机型号 地理位置 图书id 用户openid
|
|
|
+ const data = {
|
|
|
+ openid: this.userinfo.openId,
|
|
|
+ bookid: this.bookid,
|
|
|
+ comment: this.comment,
|
|
|
+ phone: this.phone,
|
|
|
+ location: this.location
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ console.log(data)
|
|
|
+ await post('/weapp/addcomment', data);
|
|
|
+ this.comment = '';
|
|
|
+ } catch (e) {
|
|
|
+ showModal('失败', e.msg)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getGeo (e) {
|
|
|
+ // NVYWM4sZYGjaHPpO6vwVk0j1v4ijBBKB
|
|
|
+ const ak = 'NVYWM4sZYGjaHPpO6vwVk0j1v4ijBBKB';
|
|
|
+ let url = 'http://api.map.baidu.com/geocoder/v2/';
|
|
|
+
|
|
|
+ if(e.target.value) {
|
|
|
+ wx.getLocation({
|
|
|
+ type: 'wgs84',
|
|
|
+ success: geo => {
|
|
|
+ console.log('地理数据', geo);
|
|
|
+ wx.request({
|
|
|
+ url,
|
|
|
+ data: {
|
|
|
+ ak,
|
|
|
+ location: `${geo.latitude},${geo.longitude}`,
|
|
|
+ output: 'json'
|
|
|
+ },
|
|
|
+ success: res => {
|
|
|
+ console.log('百度api返回', res)
|
|
|
+ if (res.data.status === 0) {
|
|
|
+ this.location = res.data.result.addressComponent.city;
|
|
|
+ } else {
|
|
|
+ this.location = '未知地点';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.location = '';
|
|
|
+ }
|
|
|
},
|
|
|
getPhone(e) {
|
|
|
if(e.target.value) {
|
|
@@ -82,6 +134,11 @@ export default {
|
|
|
mounted () {
|
|
|
this.bookid = this.$root.$mp.query.id; // 跳转页面使用this.$root.$mp.query获取参数
|
|
|
this.getDetail();
|
|
|
+ const userinfo = wx.getStorageSync('userInfo')
|
|
|
+ console.log('userInfo', userinfo);
|
|
|
+ if (userinfo) {
|
|
|
+ this.userinfo = userinfo;
|
|
|
+ }
|
|
|
// wx.showShareMenu({
|
|
|
// withShareTicket: true
|
|
|
// });
|
|
@@ -92,7 +149,7 @@ export default {
|
|
|
.comment {
|
|
|
margin-top: 10px;
|
|
|
.textarea {
|
|
|
- width: 730px;
|
|
|
+ width: 730rpx;
|
|
|
background-color: #eee;
|
|
|
padding: 10px;
|
|
|
}
|
|
@@ -104,5 +161,8 @@ export default {
|
|
|
margin-top: 10px;
|
|
|
padding: 5px 10px;
|
|
|
}
|
|
|
+ .btn {
|
|
|
+ margin: 10px 0;
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|