importWxUser.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="content">
  3. <view class="customer-list">
  4. <view class="customer-item" v-for="(item,index) in dataList" >
  5. <view class="name-box">
  6. <view class="name">昵称:{{item.nickName}}</view>
  7. <view class="btns">
  8. <view class="btn" @click="delItem(index)" >删除</view>
  9. </view>
  10. </view>
  11. <view class="desc-box">
  12. <view class="label">微信号:</view>
  13. <view class="value">{{item.id}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="bottom-btns">
  18. <view class="btn1" @click="getWxUsers()">获取客户</view>
  19. <view class="btn2" @click="addWxUsers()">导入客户</view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import {addCompanyWxUser} from '@/api/companyWxUser.js'
  25. export default {
  26. data() {
  27. return {
  28. flag:true,
  29. dataList: []
  30. }
  31. },
  32. onLoad() {
  33. var that=this;
  34. uni.$on('getWeixinList', (items) => {
  35. console.log(JSON.parse(items.data))
  36. that.dataList=JSON.parse(items.data);
  37. that.flag=true;
  38. uni.showToast({
  39. icon:'none',
  40. title: "获取微信任务已完成,共获取"+that.dataList.length+"个",
  41. });
  42. })
  43. },
  44. onShow() {
  45. },
  46. methods: {
  47. delItem(index){
  48. this.dataList.splice(index,1);
  49. },
  50. importUsers(){
  51. var that=this;
  52. var index=0;
  53. that.dataList.forEach(item => {
  54. //更新用户昵称
  55. index++;
  56. var data={nickName:item.nickName,weixinId:item.id};
  57. addCompanyWxUser(data).then(res => {
  58. if(index>=that.dataList.length){
  59. that.dataList=[];
  60. uni.showToast({
  61. icon:'none',
  62. title: "导入成功",
  63. });
  64. }
  65. else{
  66. uni.showToast({
  67. icon:'none',
  68. title: "导入"+item.nickName,
  69. });
  70. }
  71. });
  72. });
  73. },
  74. addWxUsers(){
  75. if(!this.flag){
  76. uni.showToast({
  77. icon:'none',
  78. title: "正在同步获取微信用户...",
  79. });
  80. return;
  81. }
  82. if(this.dataList.length==0){
  83. uni.showToast({
  84. icon:'none',
  85. title: "没有可导入的数据",
  86. });
  87. return;
  88. }
  89. var that=this;
  90. uni.showModal({
  91. title:"提示",
  92. content:"确认导入用户列表吗?",
  93. showCancel:true,
  94. cancelText:'取消',
  95. confirmText:'确定',
  96. success:res=>{
  97. if(res.confirm){
  98. that.importUsers();
  99. }else{
  100. }
  101. }
  102. })
  103. },
  104. getWxUsers(){
  105. if(!this.flag){
  106. return;
  107. }
  108. var that=this;
  109. uni.showModal({
  110. title:"提示",
  111. content:"确认开始获取微信用户?",
  112. showCancel:true,
  113. cancelText:'取消',
  114. confirmText:'确定',
  115. success:res=>{
  116. if(res.confirm){
  117. that.flag=false;
  118. var userId=uni.getStorageSync('companyUserId') ;
  119. var data={cmd:"getWeixinList", data:{},userId:"p-"+userId};
  120. uni.$emit('sendMsg',data);
  121. uni.showToast({
  122. icon:'none',
  123. title: "开始获取微信用户...",
  124. });
  125. }else{
  126. }
  127. }
  128. })
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss">
  134. page{
  135. height: 100%;
  136. background: #f6f6f6;
  137. }
  138. </style>
  139. <style scoped lang="scss">
  140. .content{
  141. height: 100%;
  142. padding: 0rpx;
  143. position: relative;
  144. .bottom-btns{
  145. position: fixed;
  146. bottom: 0;
  147. left: 0;
  148. width: 100%;
  149. height: 50px;
  150. display: flex;
  151. align-items: center;
  152. justify-content: center;
  153. .btn1{
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. height: 50px;
  158. flex:1;
  159. background-color: red;
  160. color: #fff;
  161. font-size: 28rpx;
  162. }
  163. .btn2{
  164. display: flex;
  165. align-items: center;
  166. justify-content: center;
  167. height: 50px;
  168. flex:1;
  169. background-color: green;
  170. color: #fff;
  171. font-size: 28rpx;
  172. }
  173. }
  174. .customer-list{
  175. display: flex;
  176. flex-direction: column;
  177. padding: 15rpx 15rpx 100rpx;
  178. .customer-item{
  179. padding: 15rpx;
  180. border-radius: 15rpx;
  181. background-color: #fff;
  182. margin-bottom: 15rpx;
  183. width: 100%;
  184. .name-box{
  185. width: 100%;
  186. display: flex;
  187. align-items: center;
  188. justify-content: flex-start;
  189. .name{
  190. flex: 1;
  191. font-size: 38rpx;
  192. color:#111;
  193. }
  194. .btns{
  195. .btn{
  196. margin-left: 10rpx;
  197. color: #a8a8a8;
  198. font-size: 28rpx;
  199. }
  200. }
  201. }
  202. .desc-box{
  203. margin-top: 15rpx;
  204. width: 100%;
  205. display: flex;
  206. align-items: center;
  207. justify-content: flex-start;
  208. .label{
  209. font-size: 28rpx;
  210. color: #a8a8a8;
  211. }
  212. .value{
  213. font-size: 28rpx;
  214. color: #a8a8a8;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. </style>