index.vue 3.89 KB
Newer Older
qd01's avatar
qd01 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
<!--用户投资产品-->
<template>
  <div>
    <p style="text-align: center; font-size: 28px">请选择产品</p>
    <el-select v-model="selects" placeholder="请选择产品" class="pull">
      <el-option
        :label="item.productName"
        :value="item.productId"
        v-for="(item, index) in productlist"
        :key="index"
      ></el-option>
    </el-select>
    <p style="text-align: center; font-size: 28px">请选择人员</p>
    <el-autocomplete
      v-model="state"
      :fetch-suggestions="querySearchAsync"
      placeholder="请输入内容"
      @select="handleSelect"
    ></el-autocomplete>


  <div style="text-align: center; font-size: 20px" >
    <p>用户列表</p>
  <p v-show="username">{{identityId}}/{{username}}
    <el-divider></el-divider></p>

  </div>
    <el-row class="btn">
      <el-button type="primary" @click="sub">确定</el-button>
      <el-button @click="quxiao">取消</el-button>
    </el-row>
    <!--  <button @click="click1">12313123</button>-->
  </div>
</template>

<script>
import { gettouzi, getprudect, buy } from "@/api/ops/user/touzi";
export default {
  dicts: ['sys_normal_disable'],
  data() {
    return {
      id: null,
      selects: "",
      restaurants: [],
      state: "",
      timeout: null,
      productlist: "",
      data: {},
      identityId:"",
      username:'',


    };
  },

  methods: {
    quxiao(){

      this.$message({
        message: '已取消',
        center: true
      });
      this.state=''
      this.selects=''
      this.username=''
      this.identityId=''
    },

    sub() {
      let data = {
        userId: this.id,
        productId: this.selects,
      };
      buy(data).then((res) => {
        console.log(res.code);
        if (res.code == 200) {
          this.$message({
            message: '新增成功',
            type: "success",
          });
        }
      });
      this.state=''
      this.selects=''
      this.username=''
      this.identityId=''
      // console.log(data)
    },

    getprudectlist() {
      getprudect().then((res) => {
        console.log(res.rows);
        this.productlist = res.rows;
      });
    },
    querySearchAsync(queryString, cb) {
      clearTimeout(this.timeout);
      var results = [];
      if (queryString == "") {
        cb(results);
      } else {
        //掉接口需要的参数
        var find = {
          search: queryString, //上面输入框绑定的数据
        };
        //这里去掉后端的接口.根据自己接口的情况进行赋值
        gettouzi(find).then((res) => {
          if (res.code == 200) {
            var result = res.rows;

            //循环放到一个远程搜索需要的数组
            for (let i = 0; i < result.length; i++) {
              const element = result[i];
              results.push({
                identityId:element.identityId,
                value: element.userName,
                id: element.userId,
                username:element.userName
              });
            }
            cb(results);
          } else {
            results = [];
            cb(results);
          }
        });
      }
    },

    createStateFilter(queryString) {
      return (state) => {
        gettouzi({ search: queryString }).then((res) => {

          console.log(res.rows)
          return res.rows.userName;

        });
      };
    },
    handleSelect(item) {

      if(item.identityId){
        this.identityId='已实名'
      }else {
        this.identityId='未实名'
      }
      // this.identityId=item.identityId
      this.id = item.id;
      this.username=item.username
      console.log(1, item.username);
    },
  },
  created() {
    gettouzi().then((res) => {
      console.log(res.rows)})
    this.getprudectlist();
  },
};
</script>
<style scoped lang="scss">
.el-autocomplete {
  width: 100%;
}
.btn {
  margin-top: 25px;
  text-align: center;
  width: 100%;
  //margin: auto;
}
.pull {
  width: 100%;
}
</style>