Select過濾出當前選中的值,并不可點擊

1
2
<el-dialog
      title="banner排序"
      :visible.sync="sortDialogVisible"
      width="30%"
    >
      <el-table
        :data="gridSortData"
        border
        height="300"
      >
        <el-table-column property="title" label="分類名稱" />
        <el-table-column property="activityStatus" label="banner狀態(tài)">
          <template slot-scope="scope">
            // 這是自己封裝的組件
            <dict-tag
              :options="dict.type.sass_banner_status"
              :value="scope.row.activityStatus"
            />
          </template>
        </el-table-column>
        <el-table-column property="sort" label="當前排序">
          <template #default="{row,$index}">
            <el-select
              :value="row.sort"
              class="select-spec"
              @change="sortChange($event,row,$index)"
            >
              <el-option
                v-for="item in bannerSortOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              />
            </el-select>
          </template>
        </el-table-column>
      </el-table>
      <div class="sort-number">總共{{ sortOptions.length }}條數(shù)據(jù)</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="sortDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="onSortConfirm">確 定</el-button>
      </span>
    </el-dialog>
data(){
  sortOptions: [], // 排序選項
  bannerSortOptions: [] // 過濾排序選項
},
methods:{
  // 獲取banner排序列表
    async headSortClick() {
      this.sortDialogVisible = true
      this.loading = true
      await bannerSortList().then(({ code, data }) => {
        if (code === 0) {
          this.gridSortData = data
          this.sortOptions = data

          this.sortOptions.map((item, index) => {
            item.label = index + 1
            item.value = index + 1
          })
          const temp = JSON.parse(JSON.stringify(this.sortOptions))
          const res = this.filterArr(this.sortOptions, temp)
          this.bannerSortOptions = res
          this.loading = false
        }
      })
        .catch(() => {
          this.loading = false
        })
    },

    // 過濾
    filterArr(a, b) {
      const sortSet = new Set()
      for (const item of a) {
        sortSet.add(item.sort * 1)
      }

      // 遍歷數(shù)組b,根據(jù)id是否在sortSet中設置disabled屬性
      for (const item of b) {
        if (sortSet.has(item.value)) {
          item.disabled = true
        } else {
          item.disabled = false
        }
      }
      return b
    },
    // 修改排序
    sortChange($event, row) {
      this.sortBannerId = row.id
      this.sortId = row.sort = $event

      for (var i = 0; i < this.sortArray.length; i++) {
        if (this.sortArray[i].bannerId == this.sortBannerId) {
          this.sortArray[i].bannerId = this.sortBannerId
          this.sortArray[i].sort = parseInt(this.sortId)
          return
        }
      }

      this.sortArray.push({
        bannerId: this.sortBannerId,
        sort: parseInt(this.sortId)
      })

      // 這里是修改當前行生效的,你可以忽略  ok
      // this.sortOptions.filter((item, index) => index + 1 == this.sortId).map(item => {
      //   item.disabled = true
      // })
    },
}
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容