edit.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template id="agent-edit">
  2. <el-dialog :visible.sync="pull.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="pull.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. <div>
  14. <el-form @submit.native.prevent size="small" label-width="150px">
  15. <el-form-item label="绑定上级用户">
  16. <el-autocomplete size="small" v-model="push.nickname" value-key="nickname"
  17. @keyup.enter.native="keyUp"
  18. :fetch-suggestions="querySearchAsync" placeholder="请输入用户昵称/id/手机号"
  19. @select="agentClickPush"></el-autocomplete>
  20. </el-form-item>
  21. </el-form>
  22. </div>
  23. <span slot="footer" class="dialog-footer">
  24. <el-button @click="editCancel" type="default" size="small">取消</el-button>
  25. <el-button type="primary" :loading="pull.btnLoading" style="margin-bottom: 10px;" size="small"
  26. @click="editSave">保存</el-button>
  27. <el-button :loading="btnLoading" type="primary" @click="changePlatform">修改成平台</el-button>
  28. </span>
  29. </el-dialog>
  30. </template>
  31. <script>
  32. Vue.component('agent-edit', {
  33. template: '#agent-edit',
  34. props: {
  35. value: {
  36. type: Boolean,
  37. default: false
  38. }
  39. },
  40. data() {
  41. return {
  42. pull: {
  43. visible: false,
  44. keyword: '',
  45. nickname: '',
  46. id: '',
  47. btnLoading: false,
  48. },
  49. push: {
  50. visible: false,
  51. keyword: '',
  52. nickname: '',
  53. id: '',
  54. },
  55. }
  56. },
  57. watch: {
  58. value() {
  59. if (this.value) {
  60. this.pull.visible = true;
  61. } else {
  62. this.pull.id = '';
  63. this.pull.nickname = '';
  64. this.pull.keyword = '';
  65. this.pull.visible = false;
  66. this.push.id = '';
  67. this.push.nickname = '';
  68. this.push.keyword = '';
  69. }
  70. }
  71. ,
  72. 'pull.visible'() {
  73. if (!this.pull.visible) {
  74. this.editCancel();
  75. }
  76. }
  77. },
  78. created() {
  79. },
  80. methods: {
  81. querySearchAsync(queryString, cb) {
  82. this.pull.keyword = queryString;
  83. this.get_user(cb);
  84. },
  85. get_user(cb) {
  86. request({
  87. params: {
  88. r: 'double-copy/default/search-user',
  89. keyword: this.pull.keyword
  90. }
  91. }).then(res => {
  92. if (res.data.code == 0) {
  93. cb(res.data.data.list)
  94. } else {
  95. this.$message.error(res.data.msg);
  96. }
  97. });
  98. },
  99. agentClick(row) {
  100. this.pull.id = row.id
  101. },
  102. agentClickPush(row) {
  103. this.push.id = row.id
  104. },
  105. editCancel() {
  106. this.$emit('input', false);
  107. navigateTo({
  108. r: 'double-copy/spread/index',
  109. })
  110. },
  111. editSave() {
  112. this.pull.btnLoading = true;
  113. if(!this.pull.id){
  114. this.$message.error('选择下级用户');
  115. this.pull.btnLoading = false;
  116. return false;
  117. }
  118. if(!this.push.id){
  119. this.$message.error('绑定上级用户');
  120. this.pull.btnLoading = false;
  121. return false;
  122. }
  123. if(this.pull.id == this.push.id){
  124. this.$message.error('选择下级用户和绑定上级用户不能相同');
  125. this.pull.btnLoading = false;
  126. return false;
  127. }
  128. request({
  129. params: {
  130. r: 'double-copy/spread/edit',
  131. },
  132. method: 'post',
  133. data: {
  134. pull_user_id: this.pull.id,
  135. push_user_id: this.push.id,
  136. }
  137. }).then(response => {
  138. this.pull.btnLoading = false;
  139. if (response.data.code == 0) {
  140. this.$message.success('添加成功');
  141. this.editCancel();
  142. } else {
  143. this.$message.error(response.data.msg);
  144. }
  145. }).catch(response => {
  146. this.pull.btnLoading = false;
  147. });
  148. },
  149. keyUp() {
  150. console.log('key up')
  151. },
  152. changePlatform(){
  153. this.pull.btnLoading = true;
  154. if(!this.pull.id){
  155. this.$message.error('选择下级用户');
  156. this.pull.btnLoading = false;
  157. return false;
  158. }
  159. this.$confirm('是否把推荐人修改成平台?', '警告', {type: 'warning'}).then(() => {
  160. this.btnLoading = true;
  161. request({
  162. params: {
  163. r: 'double-copy/spread/edit-platform'
  164. },
  165. method: 'post',
  166. data: {
  167. pull_user_id: this.pull.id,
  168. }
  169. }).then(res => {
  170. this.pull.btnLoading = false;
  171. if (res.data.code == 0) {
  172. this.$message.success(res.data.msg);
  173. this.editCancel();
  174. } else {
  175. this.$message.error(response.data.msg);
  176. }
  177. }).catch(err => {
  178. this.pull.btnLoading = false;
  179. })
  180. });
  181. },
  182. }
  183. });
  184. </script>