agent-edit.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template id="agent-edit">
  2. <el-dialog :visible.sync="showEdit.visible" width="50%" style="margin-top: 50px;" title="添加代理商" center append-to-body="true">
  3. <el-form @submit.native.prevent size="small" label-width="80px">
  4. <el-form-item label="用户昵称" required>
  5. <el-autocomplete size="small" v-model="showEdit.nickname" value-key="nickname" @keyup.enter.native="keyUp"
  6. :fetch-suggestions="querySearchAsync" placeholder="请输入用户昵称/id/手机号"
  7. @select="shareClick"></el-autocomplete>
  8. </el-form-item>
  9. </el-form>
  10. <span slot="footer" class="dialog-footer">
  11. <el-button @click="editCancel" type="default" size="small">取消</el-button>
  12. <el-button type="primary" :loading="showEdit.btnLoading" style="margin-bottom: 10px;" size="small"
  13. @click="editSave">保存</el-button>
  14. </span>
  15. </el-dialog>
  16. </template>
  17. <script>
  18. Vue.component('agent-edit', {
  19. template: '#agent-edit',
  20. props: {
  21. value: {
  22. type: Boolean,
  23. default: false
  24. },
  25. company_id:{
  26. type:Number,
  27. default:0,
  28. }
  29. },
  30. data() {
  31. return {
  32. showEdit: {
  33. visible: false,
  34. keyword: '',
  35. nickname: '',
  36. id: '',
  37. user_id:"",
  38. btnLoading: false,
  39. name:'',
  40. },
  41. listLoading:false,
  42. list:[],
  43. page:1,
  44. pageCount:0,
  45. radioSelection:0,
  46. keyword:'',
  47. selectUser:null,
  48. default_level:null,
  49. }
  50. },
  51. watch: {
  52. value() {
  53. this.radioSelection=0;
  54. this.keyword='';
  55. this.selectUser=null;
  56. this.showEdit.visible = true;
  57. if (this.value) {
  58. this.showEdit.visible = true;
  59. // this.getUser();
  60. } else {
  61. this.showEdit.id = '';
  62. this.showEdit.nickname = '';
  63. this.showEdit.keyword = '';
  64. this.showEdit.visible = false;
  65. }
  66. }
  67. ,
  68. 'showEdit.visible'() {
  69. if (!this.showEdit.visible) {
  70. this.editCancel();
  71. }
  72. },
  73. keyword(val){//监听用户昵称的输入框 如果为空(选择后删除了用户)则重新请求用户的数据 改为实时请求
  74. this.page = 1;
  75. this.pageCount = 0;
  76. this.getUser();
  77. }
  78. },
  79. created() {
  80. },
  81. methods: {
  82. getUser(){//请求用户的列表
  83. this.listLoading = true;
  84. request({
  85. params: {
  86. r: 'sales-company/default/search-agent',
  87. page:this.page,
  88. limit:20,
  89. keyword:this.keyword
  90. },
  91. method: 'get',
  92. }).then(response => {
  93. this.listLoading = false;
  94. if (response.data.code == 0) {
  95. this.list = response.data.data.list;
  96. this.pageCount = response.data.data.page_count;
  97. } else {
  98. this.$message.error(response.data.msg);
  99. }
  100. }).catch(response => {
  101. this.listLoading = false;
  102. });
  103. },
  104. pagination(currentPage) {
  105. this.page = currentPage;
  106. this.getUser();
  107. },
  108. selectionChange(e){
  109. this.selectUser = e;
  110. this.keyword = this.selectUser.id;
  111. },
  112. querySearchAsync(queryString, cb) {
  113. this.showEdit.keyword = queryString;
  114. this.get_user(cb);
  115. },
  116. get_user(cb) {
  117. request({
  118. params: {
  119. r: 'sales-company/default/search-agent',
  120. keyword: this.showEdit.keyword
  121. }
  122. }).then(res => {
  123. if (res.data.code == 0) {
  124. cb(res.data.data.list)
  125. } else {
  126. this.$message.error(res.data.msg);
  127. }
  128. });
  129. },
  130. shareClick(row) {
  131. this.showEdit.user_id = row.id
  132. },
  133. editCancel() {
  134. /* 重置表单中原来填入的数据 */
  135. this.selectUser = null;
  136. this.keyword = '';
  137. this.showEdit.user_id = '';
  138. this.showEdit.name = '';
  139. this.$emit('input', false);
  140. },
  141. editSave() {
  142. if(!this.showEdit.user_id){
  143. return this.$message.error('请选择下拉列表里的会员!');
  144. }
  145. this.showEdit.btnLoading = true;
  146. request({
  147. params: {
  148. r: 'sales-company/default/agent-edit'
  149. },
  150. method: 'post',
  151. data: {
  152. user_id:this.showEdit.user_id,
  153. name:this.showEdit.name,
  154. company_id:this.company_id,
  155. }
  156. }).then(response => {
  157. this.showEdit.btnLoading = false;
  158. if (response.data.code == 0) {
  159. this.$message.success('添加成功');
  160. this.$emit('savesuccess')
  161. this.editCancel();
  162. } else {
  163. this.$message.error(response.data.msg);
  164. }
  165. }).catch(response => {
  166. this.showEdit.btnLoading = false;
  167. });
  168. },
  169. keyUp() {
  170. console.log('key up')
  171. },
  172. }
  173. });
  174. </script>