| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <template id="stock-edit">
- <el-dialog :visible.sync="edit.visible" width="30%" title="添加代理商" center>
- <el-form size="small" label-width="80px">
- <el-form-item label="等级" required>
- <el-select v-model="level" placeholder="请选择代理商等级">
- <el-option
- v-for="item in level_list"
- :label="item.name"
- :value="item.level">
- </el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <el-form @submit.native.prevent size="small" label-width="80px">
- <el-form-item label="用户昵称" required>
- <el-autocomplete size="small" v-model="edit.nickname" value-key="nickname" @keyup.enter.native="keyUp"
- :fetch-suggestions="querySearchAsync" placeholder="请输入用户昵称/id/手机号"
- @select="shareClick"></el-autocomplete>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="editCancel" type="default" size="small">取消</el-button>
- <el-button type="primary" :loading="edit.btnLoading" style="margin-bottom: 10px;" size="small"
- @click="editSave">保存</el-button>
- </span>
- </el-dialog>
- </template>
- <script>
- Vue.component('stock-edit', {
- template: '#stock-edit',
- props: {
- value: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- edit: {
- visible: false,
- keyword: '',
- nickname: '',
- id: '',
- user_id:"",
- btnLoading: false,
- },
- level_list: [],
- level: '',
-
- listLoading:false,
- list:[],
- page:1,
- pageCount:0,
- radioSelection:0,
- keyword:'',
- selectUser:null
- }
- },
- watch: {
- value() {
- //console.log(113)
- this.radioSelection=0;
- this.keyword='';
- this.selectUser=null;
-
- if (this.value) {
- //console.log(115)
- this.edit.visible = true;
- this.getLevelList();//获取等级列表
- this.getUser();
- } else {
- this.edit.id = '';
- this.edit.nickname = '';
- this.edit.keyword = '';
- this.edit.visible = false;
- }
- }
- ,
- 'edit.visible'() {
- if (!this.edit.visible) {
- this.editCancel();
- }
- },
- keyword(val){//监听用户昵称的输入框 如果为空(选择后删除了用户)则重新请求用户的数据 改为实时请求
- /* if(val == ''){
- this.page = 1;
- this.pageCount = 0;
- this.getUser();
- } */
- this.page = 1;
- this.pageCount = 0;
- this.getUser();
- }
- },
- created() {
- //this.getLevelList();//获取等级列表
-
- },
- methods: {
- getUser(){//请求用户的列表
- //console.log('请求了getUser!page='+this.page+'----keyword='+this.keyword)
- this.listLoading = true;
- request({
- params: {
- r: 'cloud-stock-two/default/search-user',
- page:this.page,
- limit:20,
- keyword:this.keyword
- },
- method: 'get',
- }).then(response => {
- this.listLoading = false;
- //console.log('请求用户的列表结果='+JSON.stringify(response))
- if (response.data.code == 0) {
- this.list = response.data.data.list;
- this.pageCount = response.data.data.page_count;
- } else {
- this.$message.error(response.data.msg);
- }
- }).catch(response => {
- this.listLoading = false;
- });
-
- },
- pagination(currentPage) {
- this.page = currentPage;
- this.getUser();
- },
- selectionChange(e){
- //console.log('选中了='+JSON.stringify(e))
- this.selectUser = e;
- // this.keyword = this.selectUser.nickname;
- // 修改为查询ID,昵称存在空的情况
- this.keyword = this.selectUser.id;
- },
- querySearchAsync(queryString, cb) {
- this.edit.keyword = queryString;
- this.get_user(cb);
- },
- get_user(cb) {
- request({
- params: {
- r: 'cloud-stock-two/default/search-user',
- keyword: this.edit.keyword
- }
- }).then(res => {
- if (res.data.code == 0) {
- cb(res.data.data.list)
- } else {
- this.$message.error(res.data.msg);
- }
- });
- },
- agentClick(row) {
- this.edit.id = row.id
- },
- shareClick(row) {
- this.edit.user_id = row.id
- },
- getLevelList() {
- //this.edit.btnLoading = true;
- request({
- params: {
- r: 'cloud-stock-two/default/get-level-list' //代理商等级列
- },
- method: 'get',
- }).then(response => {
- if (response.data.code == 0) {
- this.level_list = response.data.data
- } else {
- this.$message.error(response.data.msg);
- }
- }).catch(response => {
- //this.edit.btnLoading = false;
- });
- },
- editCancel() {
- /* 重置表单中原来填入的数据 */
- this.level = '';
- this.selectUser = null;
- this.keyword = '';
-
- this.$emit('input', false);
- /* navigateTo({
- r: 'plugin/cloud_stock/mall/cloud-stock-two/index',
- }) */
- //this.value = false;
- },
- editSave() {
- if(!this.level){
- return this.$message.error('请选择代理商等级');
- }
- if(!this.edit.user_id){
- return this.$message.error('请选择下拉列表里的会员!');
- }
- this.edit.btnLoading = true;
- request({
- params: {
- r: 'cloud-stock-two/default/edit'//代理商添加//'plugin/stock/mall/stock/edit',
- },
- method: 'post',
- data: {
- user_id:this.edit.user_id,
- level:this.level
- }
- }).then(response => {
- this.edit.btnLoading = false;
- if (response.data.code == 0) {
- this.$message.success('添加成功');
- this.$emit('savesuccess')
- this.editCancel();
- } else {
- this.$message.error(response.data.msg);
- }
- }).catch(response => {
- this.edit.btnLoading = false;
- });
- },
- keyUp() {
- console.log('key up')
- },
- searchFun(){
- this.page = 1;
- this.getUser();
- }
- }
- });
- </script>
|