choose-user.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template id="choose-user">
  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="请输入用户昵称"
  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('choose-user', {
  20. template: '#choose-user',
  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. id: '',
  34. btnLoading: false,
  35. }
  36. };
  37. },
  38. watch: {
  39. value() {
  40. if (this.value) {
  41. this.edit.visible = true;
  42. } else {
  43. this.edit.id = '';
  44. this.edit.nickname = '';
  45. this.edit.keyword = '';
  46. this.edit.visible = false;
  47. }
  48. },
  49. 'edit.visible'() {
  50. if (!this.edit.visible) {
  51. this.editCancel();
  52. }
  53. }
  54. },
  55. methods: {
  56. querySearchAsync(queryString, cb) {
  57. this.edit.keyword = queryString;
  58. this.get_user(cb);
  59. },
  60. get_user(cb) {
  61. request({
  62. params: {
  63. r: 'plugin/o2o_store/mall/store/choose-user',
  64. keyword: this.edit.keyword
  65. }
  66. }).then(res => {
  67. if (res.data.code == 0) {
  68. cb(res.data.data.list)
  69. } else {
  70. this.$message.error(res.data.msg);
  71. }
  72. });
  73. },
  74. shareClick(row) {
  75. this.edit.id = row.id
  76. },
  77. editCancel() {
  78. this.$emit('input', false);
  79. },
  80. editSave() {
  81. this.edit.btnLoading = true;
  82. request({
  83. params: {
  84. r: 'plugin/distribution/mall/distribution/edit',
  85. },
  86. method: 'post',
  87. data: {
  88. id: this.edit.id,
  89. }
  90. }).then(response => {
  91. this.edit.btnLoading = false;
  92. if (response.data.code == 0) {
  93. this.$message.success('添加成功');
  94. this.editCancel();
  95. } else {
  96. this.$message.error(response.data.msg);
  97. }
  98. }).catch(response => {
  99. this.edit.btnLoading = false;
  100. });
  101. },
  102. keyUp() {
  103. console.log('key up')
  104. }
  105. }
  106. });
  107. </script>