<!--
  @description:供应商用户列表
  @Modifier:qk/haofengxain
  @routerPath:supplier/user
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />供应商用户列表
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link
            :underline="false"
            :class="toggleSearchStatus?'arrow-is-active':''"
            type="primary"
            class="toggleSearchStatus icon el-icon-arrow-down"
          />
          {{ toggleSearchStatus?'收起高级查询' :'展开高级查询' }}
        </span>
      </div>
      <section :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
          >
            <el-form-item ref="userName" label="用户名" prop="userName">
              <el-input v-model="searchForm.userName" placeholder="请输入用户名" style="width: 228px" />
            </el-form-item>
            <el-form-item ref="realName" label="姓名" prop="realName">
              <el-input v-model="searchForm.realName" placeholder="请输入姓名" style="width: 228px" />
            </el-form-item>
            <el-form-item ref="departName" label="供应商名称" prop="departName">
              <el-input v-model="searchForm.departName" placeholder="请输入供应商名称" style="width: 228px" />
            </el-form-item>
            <el-form-item ref="departName" label="联系方式" prop="departName">
              <el-input v-model="searchForm.mobilePhone" placeholder="请输入联系方式" style="width: 228px" />
            </el-form-item>
            <el-form-item label="注册时间">
              <el-date-picker
                v-model="searchForm.createDate"
                :value-format="elValueSaveFormat"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:228px"
              />
            </el-form-item>
            <el-form-item ref="lastLoginIp" label="登录IP" prop="lastLoginIp">
              <el-input v-model="searchForm.lastLoginIp" placeholder="请输入登录IP" style="width: 228px" />
            </el-form-item>
            <el-form-item label="最后登录时间">
              <el-date-picker
                v-model="searchForm.lastLoginTime"
                :value-format="elValueSaveFormat"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:228px"
              />
            </el-form-item>
            <el-form-item ref="effectStatus" label="状态" prop="effectStatus">
              <el-select v-model="searchForm.effectStatus" placeholder="请选择" style="width:228px">
                <el-option
                  v-for="item in supplierStatus"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" @click="onSearch">
            搜 索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重 置
          </el-button>
        </div>
      </section>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <div class="mb10">
        <el-button type="primary" @click="enableDisable('1')">
          启用
        </el-button>
        <el-button type="primary" @click="enableDisable('0')">
          停用
        </el-button>
        <el-button type="primary" plain @click="enableDisable('','1')">
          删除
        </el-button>
      </div>
      <section class="mt10">
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
          @selection-change="selectionChange"
        >
          <el-table-column
            type="selection"
            width="55"
            align="center"
          />
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="userName"
            label="用户名"
            min-width="160"
          >
            <template slot-scope="scope">
              {{ scope.row.userName }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="realName"
            label="姓名"
            min-width="110"
          />
          <el-table-column
            header-align="center"
            prop="mobilePhone"
            label="联系方式"
            width="120"
            align="center"
          />
          <el-table-column
            header-align="center"
            label="供应商名称"
            prop="departName"
            align="left"
            min-width="200"
          >
            <template slot-scope="scope">
              <!-- {{ scope.row.departName }} -->
              <el-link
                :underline="false"
                type="primary"
                @click="examineSupplierInfo(scope.row)"
              >
                {{ scope.row.departName }}
              </el-link>
            </template>
          </el-table-column>
          <el-table-column
            label="注册日期"
            prop="createDate"
            align="center"
            width="130"
          >
            <template slot-scope="scope">
              <span>
                {{ scope.row.createDate && $Moment(scope.row.createDate).format(momentDateTime) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            label="最后登录时间"
            prop="lastLoginTime"
            align="center"
            width="130"
          >
            <template slot-scope="scope">
              <span>
                {{ scope.row.lastLoginTime && $Moment(scope.row.lastLoginTime).format(momentDateTime) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            label="登录IP"
            prop="lastLoginIp"
            align="center"
            width="200"
          />
          <el-table-column
            label="状态"
            prop="effectStatus"
            align="center"
            width="80"
          >
            <template slot-scope="scope">
              {{ filterDictText(supplierStatus,scope.row.effectStatus) }}
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            width="110"
            align="center"
          >
            <template slot-scope="scope">
              <el-link type="primary" @click="passReset(scope.row)">
                [密码重置]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
    <!-- 供应商重置密码弹框 -->
    <supplierPassReset ref="supplierPassReset" />
    <!-- 供应商信息查看-弹框 -->
    <editorDeclarationDetailDialong ref="supplierInfo" />
  </div>
</template>
<script>
/* 接口*/
import { listUserByDepartRoleNamePages, updateUserById } from '@/api/common/user.js'
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { initGroupMixin } from '@/mixins/initGroupMixin'// 字典信息
/* 常用方法 */
import { filterDictText, restoreInitialValue } from '@/assets/js/utils'// 常用方法
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import supplierPassReset from './supplierPassReset-dialog'// 供应商重置密码弹框
import editorDeclarationDetailDialong from '@/views/supplier/editorDeclaration/editorDeclarationContent/editorDeclarationDetail-dialog'// 供应商信息查看
export default {
  name: 'ProjectManagerTenderList',
  components: {
    pagination, // 分页
    supplierPassReset, // 重置密码弹框
    editorDeclarationDetailDialong // 供应商信息查看-弹框
  },
  mixins: [ListMixin, initGroupMixin],
  data() {
    return {
      loading: true,
      // 选择的供应商-供应商id
      supplierIds: '', //
      date: [], // 注册时间
      dateTime: [], // 最后登录时间
      // 供应商用户状态-字典信息
      supplierStatus: [{
        typecode: '1',
        typename: '启用'
      }, {
        typecode: '0',
        typename: '停用'
      }],
      value: '',
      // 搜索
      searchForm: {
        userName: '', // 用户名
        realName: '', // 真实姓名
        lastLoginIp: '', // 登录ip
        departRoleName: '12', // 角色类型 12 供应商角色
        departName: '', // 供应商名称
        mobilePhone: '', // 联系方式
        createDate: [], // 注册时间
        createDateBegin: '', // 注册开始时间
        createDateEnd: '', // 注册时间 结束
        effectStatus: '', // 状态
        lastLoginTime: [], // 最后登录时间
        lastLoginTimeBegin: '', // 最后登录时间开始
        lastLoginTimeEnd: '' // 最后登录时间结束
      },
      tableData: []
    }
  },
  created() {
    // 获取列表信息
    this.loadData()
  },
  methods: {
    filterDictText,
    // 复选框回调
    selectionChange(val) {
      const supplierIds = []
      // 遍历供应商id
      val.forEach(item => {
        supplierIds.push(item.id)
      })
      this.supplierIds = supplierIds.join(',')
    },
    // 启用/禁用/删除
    // status, // 状态 1 启用 0 禁用
    // deleteStatus 1 删除用户
    enableDisable(status, deleteStatus) {
      // 标题
      const title = deleteStatus === '1' ? '删除' : status === '1' ? '启用' : '停用'
      if (this.supplierIds) { // 判断是否选中供应商
        this.$confirm('确认' + title + '选中记录么?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          const data = {
            id: this.supplierIds// 供应商id
          }
          if (deleteStatus === '1') {
            // 删除
            data.deleteFlag = deleteStatus
          } else {
            // 启用/禁用
            data.status = status // 状态 1 启用 0 禁用
          }
          updateUserById(data).then(res => {
            this.$message({
              message: title + '成功',
              type: 'success'
            })
            this.loadData()
          })
        }).catch(() => {
        })
      } else {
        this.$alert('至少选择一条记录！', '提示', {
          dangerouslyUseHTMLString: true
        })
      }
    },
    // 密码重置
    passReset(row) {
      // 重置
      this.$refs.supplierPassReset.open(row)
    },
    // 获取数据
    loadData() {
      this.supplierIds = ''// 清空选中的供应商
      const params = this.getQueryParams()// 查询条件
      listUserByDepartRoleNamePages(params).then(response => {
        this.loading = false
        // this.tableData = response.data.records
        this.tableData = Object.freeze(response.data.records)
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      this.searchForm.createDateBegin = this.searchForm.createDate[0] // 注册开始时间
      this.searchForm.createDateEnd = this.searchForm.createDate[1] // 注册结束时间
      this.searchForm.lastLoginTimeBegin = this.searchForm.lastLoginTime[0] // 最后登录开始时间
      this.searchForm.lastLoginTimeEnd = this.searchForm.lastLoginTime[1] // 最后登录结束时间
      this.searchForm.departRoleName = '12'// 角色类型 12 供应商角色
      // -----------------------------------------------------------------
      const param = Object.assign({}, this.searchForm)
      // 删除不需要的参数
      delete param.createDate
      delete param.lastLoginTime
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm() {
      restoreInitialValue(this.searchForm)
      // 获取列表信息
      this.onSearch()
    },
    // 供应商信息-弹框
    examineSupplierInfo(row) {
      this.$refs.supplierInfo.open(row.departId)// 供应商主键id
    }
  }
}
</script>
<style lang="less" scoped>
</style>
