<template>
  <ele-modal
    title="选择业务员"
    custom-class="ele-dialog-form long-dialog-form"
    :visible.sync="visible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    top="5vh"
    :close-on-press-escape="false"
    append-to-body
    width="70%"
    :maxable="true"
  >
    <el-card shadow="never">
      <contentSearch @search="reload"></contentSearch>

      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        row-key="id"
        class="dict-table"
        @cell-click="cellClick"
      >
        <!-- 表头工具栏 -->
        <template v-slot:action="{ row }">
          <el-radio class="radio" v-model="radio" :label="row.id"
            ><i></i
          ></el-radio>
        </template>
      </ele-pro-table>
    </el-card>

    <div slot="footer">
      <el-button type="primary" size="small" @click="selected">选择</el-button>
      <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
  </ele-modal>
</template>

<script>
  import { getUserPage } from '@/api/system/organization';
  import contentSearch from './contentSearch.vue';
  export default {
    components: { contentSearch },
    props: {
      classType: {
        type: Number | String,
        default: 1
      }
    },
    data() {
      return {
        visible: false,
        statusOptions: [
          { value: 1, label: '全职' },
          { value: 2, label: '兼职' },
          { value: 3, label: '实习' },
          { value: 4, label: '正式' },
          { value: 5, label: '试用' },
          { value: 6, label: '离职' }
        ],
        columns: [
          {
            action: 'action',
            slot: 'action',
            align: 'center',
            label: '选择',
            width: 60
          },
          {
            columnKey: 'index',
            type: 'index',
            width: 60,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left',
            label: '序号'
          },
          {
            prop: 'name',
            label: '姓名',
            slot: 'name',
             align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'jobNumber',
            label: '工号',
             align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'postName',
            label: '岗位',
             align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          //   {
          //     prop: 'factoryId',
          //     label: '所属工厂',
          //     sortable: 'custom',
          //     showOverflowTooltip: true,
          //     minWidth: 110,
          //     formatter: (_row, _column, cellValue) => {
          //       return this.factoryList.find((item) => item.id == cellValue)
          //         ?.name;
          //     }
          //   },
          {
            prop: 'loginName',
            label: '用户账号',
             align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'sex',
            label: '性别',
             align: 'center',
            showOverflowTooltip: true,
            minWidth: 80,
            formatter: (_row, _column, cellValue) => {
              return cellValue == 1 ? '男' : cellValue == 2 ? '女' : '';
            }
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            width: 80,
            formatter: (_row, _column, cellValue) => {
              const dom = this.statusOptions.find((item) => {
                return item.value == cellValue;
              });
              return dom ? dom.label : '';
            }
          },
          {
            prop: 'isEnabled',
            align: 'center',
            label: '是否启用',
            showOverflowTooltip: true,
            formatter: (row, column) => {
              return row.isEnabled === 0
                ? '停用'
                : row.isEnabled === 1
                ? '启用'
                : '';
            }
          },
          {
            prop: 'createTime',
            label: '创建时间',
             align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
            formatter: (_row, _column, cellValue) => {
              return this.$util.toDateString(cellValue);
            }
          }
        ],

        radio: null
      };
    },

    watch: {},
    methods: {
      open(item) {
        if (item) {
          this.radio = item.id;
        }
        this.visible = true;
      },

      //   /* 表格数据源 */
      //   datasource({ page, limit, where, order }) {
      //     return contactPageUsages({
      //       pageNum: page,
      //       size: limit,

      //       ...where,
      //       status: '1'
      //     });
      //   },
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return getUserPage({
          ...where,
          pageNum: page,
          size: limit,
          //   groupId: this.organizationId,
          isQueryLZ: 0
        });
      },
      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ page: 1, where });
      },

      // 单击获取id
      cellClick(row) {
        this.current = row;
        this.radio = row.id;
      },
      handleClose() {
        this.visible = false;
        this.current = null;
        this.radio = '';
      },

      selected() {
        if (!this.current) {
          return this.$message.warning('请选择业务员');
        }
        this.$emit('changePersonnel', this.current);
        this.handleClose();
      }
    }
  };
</script>

<style lang="scss" scoped></style>
