<template>
  <el-dialog
    title="品牌选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal="false"
    width="80%"
    center
  >
    <el-row :gutter="20">
      <!--品牌数据-->
      <el-col :span="20" :xs="20">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="品牌编码" prop="brandCode">
            <el-input
              v-model="queryParams.brandCode"
              placeholder="请输入品牌编码"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="品牌名称" prop="brandName">
            <el-input
              v-model="queryParams.brandName"
              placeholder="请输入品牌名称"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-table
          v-loading="loading"
          :data="brandList"
          @current-change="handleCurrent"
          @row-dblclick="handleRowDbClick"
        >
          <el-table-column width="50" align="center">
            <template v-slot="scope">
              <el-radio
                v-model="selectedBrandId"
                :label="scope.row.brandId"
                @change="handleRowChange(scope.row)"
                >{{ "" }}</el-radio
              >
            </template>
          </el-table-column>
          <el-table-column
            label="品牌编码"
            width="120"
            align="center"
            key="brandCode"
            prop="brandCode"
            v-if="columns[0].visible"
          >
          </el-table-column>

          <el-table-column
            label="品牌名称"
            min-width="120"
            align="center"
            key="brandName"
            prop="brandName"
            v-if="columns[1].visible"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="集团"
            width="120"
            align="center"
            key="groupName"
            prop="groupName"
            v-if="columns[2].visible"
            :show-overflow-tooltip="true"
          />
          <!-- <el-table-column
            label="地址"
            align="center"
            key="address"
            prop="address"
            v-if="columns[3].visible"
            :show-overflow-tooltip="true"
          /> -->
          <el-table-column
            label="销售对接人"
            align="center"
            key="salesContact"
            prop="salesContact"
            v-if="columns[3].visible"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
          <el-table-column
            label="开发对接人"
            align="center"
            key="devContact"
            prop="devContact"
            v-if="columns[4].visible"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <!-- <el-table-column
            label="品牌背景"
            align="center"
            key="background"
            prop="background"
            v-if="columns[4].visible"
            :show-overflow-tooltip="true"
          ></el-table-column> -->
          <el-table-column
            label="经营范围"
            align="center"
            key="scope"
            prop="scope"
            v-if="columns[5].visible"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            label="潜力项目"
            align="center"
            key="potentialProject"
            prop="potentialProject"
            v-if="columns[6].visible"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <!-- <el-table-column
            label="廉洁规定"
            align="center"
            key="integrityRegulations"
            prop="integrityRegulations"
            v-if="columns[4].visible"
            :show-overflow-tooltip="true"
          ></el-table-column> -->
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="showFlag = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listBrand } from "@/api/mes/md/brand";
export default {
  name: "MdBrandSelectSingle",
  components: {},
  data() {
    return {
      showFlag: false,
      // 选中数组
      selectedBrandId: undefined,
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 品牌表格数据
      brandList: [],
      // // 品牌名称
      // brandName: undefined,
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brandCode: null,
        brandName: null,
        brandId: null,
      },
      // 列信息
      columns: [
        { key: 0, label: `品牌编码`, visible: true },
        { key: 1, label: `品牌名称`, visible: true },
        { key: 2, label: `集团`, visible: true },
        // { key: 3, label: `地址`, visible: true },
        { key: 3, label: `销售对接人`, visible: true },
        { key: 4, label: `开发对接人`, visible: true },
        // { key: 6, label: `品牌背景`, visible: true },
        { key: 5, label: `经营范围`, visible: true },
        { key: 6, label: `潜力项目`, visible: true },
        // { key: 6, label: `廉洁规定`, visible: true },
      ],
    };
  },
  // watch: {
  //   // 根据名称筛选分类树
  //   itemTypeName(val) {
  //     this.$refs.tree.filter(val);
  //   },
  // },
  created() {
    console.log("日志:已进入brandSingle页面的列表查询方法"); // 在created钩子函数中输出日志
    this.getList();
  },
  methods: {
    // /** 查询物料编码列表 */
    // getList() {
    //   this.loading = true;
    //   listMdItem(this.queryParams).then((response) => {
    //     this.itemList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },
    /** 查询品牌列表 */
    getList() {
      this.loading = true;
      listBrand(this.queryParams).then((response) => {
        this.brandList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    //双击选中
    handleRowDbClick(row) {
      if (row) {
        this.selectedRows = row;
        this.$emit("onSelected", this.selectedRows);
        this.showFlag = false;
      }
    },
    //确定选中
    confirmSelect() {
      if (this.selectedBrandId == null || this.selectedBrandId == 0) {
        this.$notify({
          title: "提示",
          type: "warning",
          message: "请至少选择一条数据!",
        });
        return;
      }
      this.$emit("onSelected", this.selectedRows);
      this.showFlag = false;
    },
  },
};
</script>
