省市区全选和电站名称全选

 <el-col :span="6">
              <el-form-item label="省市区">
                <el-cascader
                  :options="options"
                  :props="{ multiple: true }"
                  v-model="form.optionsCity"
                  collapse-tags
                  clearable
                  @change="searchBuilds"
                  placeholder="请选择省市区"
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="电站名称">
                <el-select
                  v-model="form.buildId"
                  placeholder="请选择电站名称"
                  multiple
                  clearable
                  collapse-tags
                  @click.native="searchBuildsClick"
                  @change="changeSelect"
                >
                  <el-checkbox
                    v-model="checked"
                    @change="selectAll"
                    style="text-align: right; width: 100%; padding-right: 10px"
                    >全 选</el-checkbox
                  >
                  <el-option
                    v-for="item in buildData"
                    :key="item.code"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

  

    // 省市区与电站名称联动
    searchBuilds() {
      this.form.buildId = "";
      this.buildData = [];
      const [_province = "", _city = "", _area = ""] = this.form.optionsCity;
      this.$post(xxxxxxxx, {
        page: 1,
        size: 3000,
        province: _province || "",
        city: _city || "",
        area: _area || "",
      })
        .then((res) => {
          if (res.status == 1) {
            this.buildData = res.data.rows;
          }
        })
        .catch(() => {
          this.$message.warning("网络异常,稍后请重试");
        });
    },
    // 获取电站名称
    searchBuildsClick() {
      if (!this.form.buildId || this.form.buildId.length <= 0) {
        this.form.buildId = "";
        this.buildData = [];
        const [_province = "", _city = "", _area = ""] = this.form.optionsCity;
        this.$post(SelectUserBuildPowerAndPage, {
          page: 1,
          size: 3000,
          province: _province || "",
          city: _city || "",
          area: _area || "",
        })
          .then((res) => {
            if (res.status == 1) {
              this.buildData = res.data.rows;
            }
          })
          .catch(() => {
            this.$message.warning("网络异常,稍后请重试");
          });
      }
    },
    //电站选择事件
    changeSelect(val) {
      if (val.length === this.buildData.length) {
        this.checked = true;
      } else {
        this.checked = false;
      }
    },
    // 电站全选
    selectAll() {
      this.form.buildId = [];
      if (this.checked) {
        this.buildData.map((item) => {
          this.form.buildId.push(item.id);
        });
        console.log(this.form.buildId, "全选");
      } else {
        this.form.buildId = [];
      }
    },

  

posted @ 2022-09-16 15:37  崛起崛起  阅读(65)  评论(0)    收藏  举报