distribution-edit.php 4.1 KB

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