<template>
    <div>
      <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="工龄" prop="serverAge">
            <el-input
              v-model="queryParams.serverAge"
              placeholder="请输入工龄"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="家政等级" prop="serverLevel">
            <el-select v-model="queryParams.serverLevel" placeholder="请选择">
              <el-option
                v-for="item in serverLevelOptions"
                :key="item.decodeValue"
                :label="item.decodeValue"
                :value="item.decodeId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="用户手机号" prop="phone">
            <el-input
              v-model="queryParams.phone"
              placeholder="请输入用户手机号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="姓名" prop="realName">
            <el-input
              v-model="queryParams.realName"
              placeholder="请输入姓名"
              clearable
              size="small"
              @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-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:user:add']"
            >添加人员</el-button>
          </el-col>


          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            type="index"
            width="50"
            label="序号">
          </el-table-column>
          <el-table-column label="用户手机号" align="center" prop="phone" width="150" />
          <el-table-column label="姓名" align="center" prop="realName" width="80" />
          <el-table-column label="工龄" align="center" prop="serverAge" />
          <el-table-column label="家政等级" align="center" prop="serverLevel" />
          <el-table-column label="成交单量" align="center"   >
            <template slot-scope="scope">
              <a @click="infoSee(scope.row)" style="color:blue;cursor:pointer">{{ scope.row.orderCount }}</a>
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="stopOrder" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="toSeviceTime(scope.row)"
                v-hasPermi="['system:user:edit']"
              >设置服务时间</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="selfInfoSEE(scope.row)"
                v-hasPermi="['system:user:edit']"
              >查看</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="toEdit(scope.row)"
                v-hasPermi="['system:user:edit']"
              >编辑</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:user:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <!-- 服务项目 -->
        <el-dialog title="服务项目" :visible.sync="serviceOpen" width="500px" append-to-body>

          <el-table :data="serviceProgramme">
            <el-table-column label="服务主题" align="center" prop="phone" >

            </el-table-column>
            <el-table-column label="服务类型" align="center" prop="phone" >

            </el-table-column>
            <el-table-column label="单价/(台）" align="center" prop="phone" >

            </el-table-column>
            <el-table-column label="大概服务时长" align="center" prop="phone" >

            </el-table-column>
          </el-table>

        </el-dialog>

        <el-dialog title="服务人员信息" :visible.sync="open" width="600px" append-to-body="">
          <el-row>
            <el-col>
              手机号：{{form.phone}}
            </el-col>

            <el-col>
              姓名：{{form.realName}}
            </el-col>
            <el-col>
              工龄：{{form.serverAge}}
            </el-col>
            <el-col>
              等级：{{form.serverLevel}}
            </el-col>
            <el-col>
              个人简介：{{form.desc}}
            </el-col>

          </el-row>

        </el-dialog>
      </div>
    </div>
</template>

<script>
  import { listUser, getUser, delUser, addUser, updateUser, exportUser } from "@/api/system/ServiceUserService";
  import { getCode, listCode } from '../../api/system/dict/code'
  export default {
    name: 'service',
    data() {
      return {
        //家政等级
        serverLevelOptions:[
        ],
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 服务人员表格数据
        userList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //服务项目弹出层
        serviceOpen:false,
        //服务项目数据
        serviceProgramme:[],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          merchantId: null,
          serverAge: null,
          orderCount: null,
          serverLevel: null,
          phone: null,
          openId: null,
          appleId: null,
          nikeName: null,
          realName: null,
          age: null,
          sex: null,
          avatar: null,
          closeTime: null,
          closeReason: null,
          password: null,
          status: null,
          loginIp: null,
          loginDate: null,
          column1: null,
          column2: null,
          column3: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          phone: [
            { required: true, message: "用户手机号不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      this.getList();
      this.getServiceLever();
    },
    mounted(){

    },
    methods: {
      toSeviceTime(row){
        this.$router.push({
          path:'/merchant/serviceTime',
          query:{
            serverId:row.serverId
          }
        })
      },
      infoSee(row){
        this.serviceOpen=true;
      },
      /** 查询家政等级*/
      getServiceLever(){
        let params={
          codeValue:'服务等级'
        }

        listCode(params).then(res=>{
          this.serverLevelOptions=res.rows;
        })
      },

      /** 查询服务人员列表 */
      getList() {
        this.loading = true;
        listUser(this.queryParams).then(response => {
          this.userList = response.rows;
          for(let i in this.userList){
            for(let j in this.serverLevelOptions){
                if(this.userList[i].serverLevel==this.serverLevelOptions[j].decodeId){
                  this.userList[i].serverLevel=this.serverLevelOptions[j].decodeValue
                }

            }
            if(this.userList[i].stopOrder=='0'){
              this.userList[i].stopOrder='正常'
            }else{
              this.userList[i].stopOrder='停止服务'
            }
          }

          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          serverId: null,
          merchantId: null,
          serverAge: null,
          orderCount: null,
          serverLevel: null,
          phone: null,
          openId: null,
          appleId: null,
          nikeName: null,
          realName: null,
          age: null,
          sex: null,
          avatar: null,
          closeTime: null,
          closeReason: null,
          password: null,
          status: "0",
          loginIp: null,
          loginDate: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          column1: null,
          column2: null,
          column3: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.serverId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
		  debugger
          this.$router.push('/merchant/ServicePeopleAdd') 
      },
     /**编辑按钮操作*/
     toEdit(row){
       this.$router.push({path:'/merchant/ServicePeopleAdd',query:{selfInfo:row}})
     },

      selfInfoSEE(row){
        this.reset();
        const serverId = row.serverId || this.ids
        getUser(serverId).then(response => {
          this.form = response.data;
            for(let j in this.serverLevelOptions){
              if(this.form.serverLevel==this.serverLevelOptions[j].decodeId){
                this.form.serverLevel=this.serverLevelOptions[j].decodeValue
              }

            }
          this.open = true;
        });

      },

      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.serverId != null) {
              updateUser(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addUser(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const serverIds = row.serverId || this.ids;
        this.$modal.confirm('是否确认删除服务人员编号为"' + serverIds + '"的数据项？').then(function() {
          return delUser(serverIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
    }
  }
</script>

<style scoped>

</style>
