group-edit.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template id="group-edit">
  2. <el-dialog :visible.sync="edit.visible" width="20%" title="添加团长">
  3. <div>
  4. <el-form @submit.native.prevent size="small" label-width="150px">
  5. <el-form-item label="用户昵称">
  6. <el-autocomplete size="small" v-model="edit.nickname" value-key="nickname"
  7. @keyup.enter.native="keyUp"
  8. :fetch-suggestions="querySearchAsync" placeholder="请输入用户昵称/id/手机号"
  9. @select="agentClick"></el-autocomplete>
  10. </el-form-item>
  11. </el-form>
  12. </div>
  13. <span slot="footer" class="dialog-footer">
  14. <el-button @click="editCancel" type="default" size="small">取消</el-button>
  15. <el-button type="primary" :loading="edit.btnLoading" style="margin-bottom: 10px;" size="small"
  16. @click="editSave">保存</el-button>
  17. </span>
  18. </el-dialog>
  19. </template>
  20. <script>
  21. Vue.component('group-edit', {
  22. template: '#group-edit',
  23. props: {
  24. value: {
  25. type: Boolean,
  26. default: false
  27. }
  28. },
  29. data() {
  30. return {
  31. edit: {
  32. visible: false,
  33. keyword: '',
  34. nickname: '',
  35. user_id: '',
  36. btnLoading: false,
  37. },
  38. level_list: [],
  39. level: 0
  40. }
  41. },
  42. watch: {
  43. value() {
  44. if (this.value) {
  45. this.edit.visible = true;
  46. } else {
  47. this.edit.user_id = '';
  48. this.edit.nickname = '';
  49. this.edit.keyword = '';
  50. this.edit.visible = false;
  51. }
  52. }
  53. ,
  54. 'edit.visible'() {
  55. if (!this.edit.visible) {
  56. this.editCancel();
  57. }
  58. }
  59. },
  60. created() {
  61. },
  62. methods: {
  63. querySearchAsync(queryString, cb) {
  64. this.edit.keyword = queryString;
  65. this.get_user(cb);
  66. },
  67. get_user(cb) {
  68. request({
  69. params: {
  70. r: 'lucky-group/group-team/search-user',
  71. keyword: this.edit.keyword
  72. }
  73. }).then(res => {
  74. if (res.data.code == 0) {
  75. cb(res.data.data.list)
  76. } else {
  77. this.$message.error(res.data.msg);
  78. }
  79. });
  80. },
  81. agentClick(row) {
  82. this.edit.user_id = row.id
  83. },
  84. editCancel() {
  85. this.$emit('input', false);
  86. navigateTo({
  87. r: 'lucky-group/group-team/index',
  88. })
  89. },
  90. editSave() {
  91. this.edit.btnLoading = true;
  92. request({
  93. params: {
  94. r: 'lucky-group/group-team/add-group-user',
  95. },
  96. method: 'post',
  97. data: {
  98. user_id: this.edit.user_id,
  99. level: this.level
  100. }
  101. }).then(response => {
  102. this.edit.btnLoading = false;
  103. if (response.data.code == 0) {
  104. this.$message.success('添加成功');
  105. this.editCancel();
  106. } else {
  107. this.$message.error(response.data.msg);
  108. }
  109. }).catch(response => {
  110. this.edit.btnLoading = false;
  111. });
  112. },
  113. keyUp() {
  114. console.log('key up')
  115. }
  116. }
  117. });
  118. </script>