userset.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <view class="page">
  3. <view class="usertop" v-if="from!='detail'">
  4. <view @tap='openinfo()'>
  5. <view class="avatar">
  6. <image :src="image_cache(userinfo.avatar)"></image>
  7. </view>
  8. <view class="nickname">
  9. {{userinfo.showname}}
  10. </view>
  11. <view class="icon">
  12. <uni-icons type='arrowright'></uni-icons>
  13. </view>
  14. </view>
  15. <view @tap="addgroup()">
  16. <view class="avatar">
  17. <image src="../../static/img/icon-plus.png"></image>
  18. </view>
  19. <view class="nickname">
  20. 发起群聊
  21. </view>
  22. <view class="icon">
  23. </view>
  24. </view>
  25. </view>
  26. <ul class="profile" @click="search()" style="height: 40px;line-height: 40px;">
  27. <li>聊天记录</li>
  28. <li>
  29. <div class="tagshow" style="width: 100%;">
  30. </div>
  31. </li>
  32. <li>
  33. <uni-icons type='arrowright'></uni-icons>
  34. </li>
  35. </ul>
  36. <ul class="profile" style="height: 40px;line-height: 40px;">
  37. <li>备注名:</li>
  38. <li>
  39. <button class="btn" @tap="sub_rename()">修改</button>
  40. <input type="text" class="input1" id="nickname" placeholder="请输入备注名"
  41. style="width: 100px;text-align:left;float: right;" v-model="markname" maxlength="10" />
  42. </li>
  43. </ul>
  44. <ul class="profile" style="height: 40px;line-height: 40px;">
  45. <li>设为置顶:</li>
  46. <li>
  47. <switch :checked="istop" @change="user_setmenu('top')" style="vertical-align: middle;" />
  48. </li>
  49. </ul>
  50. <ul class="profile" style="height: 40px;line-height: 40px;">
  51. <li>消息免打扰:</li>
  52. <li>
  53. <switch :checked="no_tip" @change="user_setmenu('tip')" style="vertical-align: middle;" />
  54. </li>
  55. </ul>
  56. <ul class="profile" style="height: 40px;line-height: 40px;">
  57. <li>加入黑名单:</li>
  58. <li>
  59. <switch :checked="backlist" @change="user_setmenu('backlist')" style="vertical-align: middle;" />
  60. </li>
  61. </ul>
  62. <ul v-if="userinfo.from!='system'" class="profile" @tap="deleteFriend()"
  63. style="height: 40px;line-height: 40px;text-align: center;color: #007AFF;">
  64. 删除好友
  65. </ul>
  66. <ul v-if="userinfo.from!='system'" class="profile" @tap="jbFriend()"
  67. style="height: 40px;line-height: 40px;text-align: center;color: #007AFF;">
  68. 举报
  69. </ul>
  70. </view>
  71. </template>
  72. <script>
  73. import {
  74. mapState
  75. } from 'vuex';
  76. import api from '../../library/index.js'
  77. import http from '../../library/http.js'
  78. import uniIcons from '../../components/uni-icons/uni-icons.vue'
  79. export default {
  80. components: {
  81. uniIcons
  82. },
  83. data() {
  84. return {
  85. system: uni.getStorageSync('system'),
  86. userinfo: [],
  87. group_id: 0,
  88. userid: 0,
  89. myid: uni.getStorageSync('access_token'),
  90. group_users: [],
  91. group_user: [],
  92. thistype: '',
  93. usertype: '',
  94. markname: '',
  95. istop: false,
  96. no_tip: false,
  97. backlist: false,
  98. myuser: uni.getStorageSync('userInfo'),
  99. from: ''
  100. }
  101. },
  102. computed: {
  103. },
  104. methods: {
  105. search() {
  106. console.log('查找聊天记录');
  107. uni.navigateTo({
  108. url: '/pages/index/record?group_id=' + this.userid + '&isgroup=0'
  109. })
  110. },
  111. user_setmenu(type) {
  112. if (type == 'top') {
  113. this.istop = !this.istop;
  114. var msgtop = uni.getStorageSync('msgtop') ? uni.getStorageSync('msgtop') : [];
  115. if (this.istop) {
  116. msgtop.push('U' + this.userid)
  117. } else {
  118. for (var i = 0; i < msgtop.length; i++) {
  119. if (msgtop[i] == 'U' + this.userid) {
  120. msgtop.splice(i, 1)
  121. }
  122. }
  123. }
  124. uni.setStorageSync('msgtop', msgtop);
  125. this.$store.commit('chat/set_istop');
  126. var data = {
  127. cache_key: 'U' + this.userid,
  128. userid: this.myid,
  129. istop: this.istop
  130. };
  131. http.setWait(false).get('group.php?act=set_msgtop', data).then(res => {
  132. })
  133. }
  134. if (type == 'tip') {
  135. this.no_tip = !this.no_tip;
  136. var msgtop = uni.getStorageSync('msgnotip') ? uni.getStorageSync('msgnotip') : [];
  137. if (this.no_tip) {
  138. msgtop.push('U' + this.userid)
  139. } else {
  140. for (var i = 0; i < msgtop.length; i++) {
  141. if (msgtop[i] == 'U' + this.userid) {
  142. msgtop.splice(i, 1)
  143. }
  144. }
  145. }
  146. uni.setStorageSync('msgnotip', msgtop);
  147. var data = {
  148. cache_key: 'U' + this.userid,
  149. userid: this.myid,
  150. notip: this.no_tip
  151. };
  152. http.setWait(false).get('group.php?act=set_msgnotip', data).then(res => {
  153. })
  154. }
  155. if (type == 'backlist') {
  156. this.backlist = !this.backlist;
  157. if (this.backlist == true) {
  158. uni.showModal({
  159. title: '提示',
  160. content: '加入黑名单后将无法收到对方的消息\n确认要把' + this.userinfo.nickname + '加入名单?',
  161. showCancel: true,
  162. cancelText: '取消',
  163. confirmText: '确认',
  164. success: res => {
  165. if (res.confirm) {
  166. this.addbacklist();
  167. } else {
  168. this.backlist = false;
  169. }
  170. }
  171. });
  172. } else {
  173. this.addbacklist();
  174. }
  175. }
  176. },
  177. addbacklist() {
  178. http.setWait(false).get('user.php?act=backlist', {
  179. id: this.userid,
  180. userid: this.myid
  181. }).then(res => {
  182. this.getmyinfo();
  183. if (this.backlist == true) this.delete_msg('U' + this.userid);
  184. })
  185. },
  186. sub_rename() {
  187. var data = {
  188. friend_uid: this.userid,
  189. userid: this.myid,
  190. mark: this.markname
  191. };
  192. http.setWait(false).get('user.php?act=setmark', data).then(res => {
  193. uni.showToast({
  194. title: "备注成功",
  195. icon: 'none'
  196. })
  197. this.getuserinfo(this.userid);
  198. })
  199. },
  200. deleteFriend() {
  201. var that = this;
  202. uni.showModal({
  203. title: '提示',
  204. content: '确定要删除好友吗?',
  205. showCancel: true,
  206. cancelText: '取消',
  207. confirmText: '删除',
  208. success: res => {
  209. if (res.confirm) {
  210. api.deleteFriend({
  211. friendid: that.userid,
  212. userid: that.myid
  213. }).then(res => {
  214. this.$toast('删除成功').then(() => {
  215. this.delete_msg('U' + that.userid);
  216. uni.reLaunch({
  217. url: '../index/index'
  218. });
  219. });
  220. });
  221. }
  222. }
  223. });
  224. },
  225. getmyinfo() {
  226. var postdata = {
  227. id: uni.getStorageSync('access_token')
  228. };
  229. http.setWait(false).post('user.php?act=userinfo', postdata).then(res => {
  230. this.myuser = res.data;
  231. uni.setStorageSync('userInfo', this.myuser)
  232. var backlist = this.myuser.backlist.toString();
  233. if (backlist.indexOf(this.userid) > -1) this.backlist = true;
  234. else this.backlist = false;
  235. })
  236. },
  237. getuserinfo(userid) {
  238. if (uni.getStorageSync('members_' + userid)) this.userinfo = uni.getStorageSync('members_' + userid);
  239. http.setWait(false).get('user.php?act=userdetail', {
  240. id: userid,
  241. group_id: 0,
  242. userid: this.myid
  243. }).then(res => {
  244. if (res.code == 200) {
  245. this.isloading = false;
  246. this.userinfo = res.data;
  247. this.markname = this.userinfo.nickname;
  248. uni.setStorageSync('members_' + userid, res.data)
  249. } else {
  250. uni.showToast({
  251. title: '网络错误,请稍后再试',
  252. icon: 'none'
  253. })
  254. }
  255. })
  256. },
  257. openinfo() {
  258. uni.redirectTo({
  259. url: 'detail?id=' + this.userid + '&from=chat'
  260. })
  261. },
  262. addgroup() {
  263. uni.navigateTo({
  264. url: 'userlist?disabled_id=' + this.userid + '&next=group/create&subtitle=立即创建'
  265. })
  266. },
  267. init() {
  268. var msgtop = uni.getStorageSync('msgtop');
  269. var istop = 0;
  270. for (var i = 0; i < msgtop.length; i++) {
  271. if (msgtop[i] == 'U' + this.userid) {
  272. this.istop = true;
  273. break;
  274. }
  275. }
  276. var msgnotip = uni.getStorageSync('msgnotip');
  277. for (var i = 0; i < msgnotip.length; i++) {
  278. if (msgnotip[i] == 'U' + this.userid) {
  279. this.no_tip = true;
  280. break;
  281. }
  282. }
  283. var backlist = this.myuser.backlist;
  284. if (backlist.indexOf(this.userid) > -1) this.backlist = true;
  285. else this.backlist = false;
  286. },
  287. jbFriend() {
  288. uni.showActionSheet({
  289. itemList: ['发布不适当内容', '存在欺诈骗钱行为','此账号可能被盗用了','存在侵权行为','冒充他人'],
  290. success: function(res) {
  291. console.log(res, '上传')
  292. uni.showModal({
  293. content:'提交成功,请等待平台审核。',
  294. showCancel:false
  295. })
  296. },
  297. fail: function(res) {
  298. erro(res)
  299. console.log(res.errMsg);
  300. }
  301. });
  302. }
  303. },
  304. onShow() {
  305. },
  306. onLoad(opts) {
  307. this.userid = opts.id;
  308. if (opts.from) this.from = opts.from;
  309. if (uni.getStorageSync('members_' + this.userid)) {
  310. this.userinfo = uni.getStorageSync('members_' + this.userid);
  311. this.markname = this.userinfo.nickname;
  312. }
  313. this.getuserinfo(this.userid);
  314. this.init();
  315. }
  316. }
  317. </script>
  318. <style lang="scss" scoped>
  319. @import "@/static/css/user.css";
  320. .page {
  321. background-color: #fafafa;
  322. }
  323. .usertop {
  324. background-color: #fff;
  325. line-height: 40px;
  326. width: 100%;
  327. min-height: 40px;
  328. }
  329. .usertop>view {
  330. width: 100%;
  331. display: table;
  332. table-layout: fixed;
  333. padding: 5px 0px;
  334. border-top: 1px solid #eee;
  335. }
  336. .usertop>view>view {
  337. display: table-cell;
  338. vertical-align: middle;
  339. }
  340. .usertop>view>view.avatar {
  341. width: 60px;
  342. text-align: center;
  343. }
  344. .usertop>view>view.avatar image {
  345. height: 40px;
  346. width: 40px;
  347. border-radius: 5px;
  348. vertical-align: middle;
  349. }
  350. .usertop>view>view.nickname {
  351. font-size: 16px;
  352. color: #222;
  353. line-height: 40px;
  354. }
  355. .usertop>view>view.icon {
  356. width: 30px;
  357. text-align: center;
  358. }
  359. .profile {
  360. background-color: #fff;
  361. margin: 10px auto;
  362. width: 100%;
  363. }
  364. .profile li {
  365. vertical-align: middle;
  366. }
  367. .profile li:first-child {
  368. padding-left: 10px;
  369. width: 150px;
  370. text-align: left;
  371. }
  372. .profile li:last-child {
  373. padding-right: 10px;
  374. text-align: right;
  375. width: calc(100% - 180px);
  376. vertical-align: middle;
  377. }
  378. .btn {
  379. height: 30px;
  380. line-height: 30px;
  381. background-color: #3388ff;
  382. float: right;
  383. color: #fff;
  384. padding: 0px 15px;
  385. margin-left: 5px;
  386. cursor: pointer;
  387. vertical-align: middle;
  388. }
  389. </style>