<template>
  <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item prop="phonenumber">
        <el-select v-model="queryParams.customerType" placeholder="客户类型" clearable size="small">
          <el-option
            v-for="dict in peopleTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
        </el-form-item>
        <el-form-item prop="phonenumber">
          <el-input
            v-model="queryParams.account"
            placeholder="客户账号"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item prop="phonenumber">
          <el-input
            v-model="queryParams.customerName"
            placeholder="客户名称"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item prop="phonenumber">
          <el-input
            v-model="queryParams.phone"
            placeholder="绑定手机号"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" 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="list">
        <el-table-column label="序号" type="index" width="50" align="center" />
        <el-table-column label="客户账号" align="center" prop="account" />
        <el-table-column label="客户类型" align="center" prop="customerType" />
        <el-table-column label="微信号/昵称" align="center" prop="nickName" />
        <el-table-column label="客户名称" align="center" prop="customerName" />
        <el-table-column label="绑定手机号" align="center" prop="phone" />
        <el-table-column label="认证状态" align="center" width="160">
          <template slot-scope="scope">
            <span>{{ scope.row.isCompany == 0 ? '是' : '否' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="modifiedTime" width="160">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.modifiedTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户状态" align="center" prop="createTime">
          <template slot-scope="scope">
              <el-switch
                v-model="scope.row.isEnable"
                style="display: block"
                @change="handelUserStatus($event,scope.row)"
                :active-value="1"
                :inactive-value="0"
                v-hasPermi="['customerManage:customers:uStatus']"
                active-text="未启用"
                inactive-text="已启用">
              </el-switch>
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          width="280"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="success"
              icon="el-icon-view"
              @click="resetPw(scope.row)"
              v-hasPermi="['customerManage:customers:resetpwd']"
            >重置密码</el-button>
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-view"
              @click="handleView(scope.row)"
              v-hasPermi="['customerManage:customers:view']"
            >查看</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row)"
              icon="el-icon-delete"
              v-hasPermi="['customerManage:customers:del']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <add-mobiel
      			v-if="modal.visibleModal"
      			:title="modal.title"
      			:action="modal.action"
      			:visible="modal.visibleModal"
      			:selectRow="modal.selectRow"
      			@closeModal="closeModal">
      		</add-mobiel>
  </div>
</template>
<script>
import { listCustomer , userStatus , delUser , resetPassword } from "@/api/customerManage/customer";
import addMobiel from './modal/addMobiel'
export default {
  name: "customer",
  components: {
    addMobiel
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 状态数据字典
      peopleTypeOptions: [],
      // 表单参数
      form: {},
      //弹出层
      modal:{
        action:'',
        title:'',
        visibleModal:false,
        selectRow:null
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  created() {
    //申请状态字典
    this.getDicts("customerManage_peopleType").then(response => {
      this.peopleTypeOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询产婆类别列表 */
    getList() {
      this.loading = true;
      listCustomer(this.queryParams).then(res => {
          if(res.retHead.errCode == 0){
            this.list = res.retBody
            this.total = res.retHead.total;
          }
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.queryParams = {
        pageNo:1,
        pageSize:10
      }
      this.handleQuery();
    },
    /** 查看按钮操作 */
    handleView(item){
        this.modal.visibleModal = true
        this.modal.title = '用户详情'
        this.modal.action = 'view'
        this.modal.selectRow = item
    },
    /** 删除按钮操作 */
    handleDelete(item) {
      let params = {
        guid:item.guid,
        state:1
      }
      this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delUser(params);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    //密码重置
    resetPw(item){
      let params = {
        guid:item.guid,
      }
      this.$confirm('是否确认要重置该用户登录密码?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return resetPassword(params);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    //更改用户状态
    handelUserStatus(val,row){
      let params = {
        guid:row.guid,
        isEnable:val
      }
      let _this = this;
      this.$confirm('你确定是否改变改客户的账号状态?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
            return userStatus(params);
        }).then(() => {
            _this.getList();
            _this.msgSuccess("操作成功");
        }).catch(function() {
            _this.getList()
        });
    },
    //窗口关闭
    closeModal(flag = false){
      this.modal.visibleModal = false
      flag && this.getList()
    }
  }
};
</script>
