<template>
  <div class="app-container">

     <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">

        <el-form-item label="姓名" prop="createBy">
           <el-input
              v-model="queryParams.nickName"
              placeholder="请输入姓名"
              clearable
              style="width: 200px"
              @keyup.enter="handleQuery"
           />
        </el-form-item>
        <el-form-item label="手机号" prop="createBy">
          <el-input
             v-model="queryParams.phonenumber"
             placeholder="请输入手机号"
             clearable
             style="width: 200px"
             @keyup.enter="handleQuery"
          />
       </el-form-item>

        <el-form-item>
           <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
           <el-button icon="Refresh" @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="Plus"
              @click="handleAdd"
              v-hasPermi="['system:notice:add']"
           >新增</el-button>
        </el-col>
        <el-col :span="1.5">
           <el-button
              type="success"
              plain
              icon="Edit"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:notice:edit']"
           >修改</el-button>
        </el-col>
        <el-col :span="1.5">
           <el-button
              type="danger"
              plain
              icon="Delete"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:notice:remove']"
           >删除</el-button>
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
     </el-row> -->

     <el-table v-loading="loading" :data="noticeList">

        <el-table-column label="序号" align="center" type="index" width="80" />
        <el-table-column
           label="姓名"
           :show-overflow-tooltip="true"
        >
        <template #default="scope">
         {{scope.row.nickName}}
            </template>
          </el-table-column>
          <el-table-column
          label="区域"

          :show-overflow-tooltip="true"
      >
      <template #default="scope">
        {{scope.row.provinceName}}--{{scope.row.cityName}}--{{scope.row.areaName}}
      </template>
      </el-table-column>

        <el-table-column label="手机号" align="center" prop="phonenumber">
        </el-table-column>
        <el-table-column label="人员类型" align="center" prop="role" width="100">
           <template #default="scope">
            <el-tag type="warning" v-if="scope.row.status=='0'">待审核</el-tag>
            <el-tag type="success" v-else-if="scope.row.status=='1'">已通过</el-tag>
            <el-tag type="danger" v-else>已驳回</el-tag>
           </template>
        </el-table-column>
        <!-- <el-table-column label="创建者" align="center" prop="createBy" width="100" /> -->
        <el-table-column label="申请时间" align="center" prop="createTime" >

        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
           <template #default="scope">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:notice:edit']">审核</el-button>
              <!-- <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:notice:remove']" >删除</el-button> -->
           </template>
        </el-table-column>
     </el-table>

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

     <!-- 添加或修改公告对话框 -->
     <el-dialog :title="title" v-model="open" width="40%" append-to-body>
      <el-form :model="form" :rules="rules" ref="userRef" label-width="80px">
        <el-row>
           <el-col :span="24">
              <el-form-item label="用户姓名" prop="nickName">
                 <el-input v-model="form.nickName" placeholder="请输入用户昵称" disabled maxlength="30" />
              </el-form-item>
           </el-col>
           <el-col :span="24">
            <el-form-item label="手机号码" prop="phonenumber">
              <el-input v-model="form.phonenumber" placeholder="请输入手机号码" disabled maxlength="11" />
           </el-form-item>
           </el-col>
        </el-row>
        <el-row>
           <el-col :span="24">
              <el-form-item label="区域" prop="phonenumber">
                <el-cascader v-model="addr"
                 :options="options"
                 disabled
                 style="width: 100%;"

                 :props="cityProps" clearable/>

              </el-form-item>
           </el-col>
           <el-col :span="24">
            <el-form-item label="身份证号" prop="phonenumber">
              <el-input v-model="form.identityNumber" placeholder="请输入" disabled maxlength="11" />
           </el-form-item>
           </el-col>
           <el-col :span="24">
            <el-form-item label="银行卡号" prop="phonenumber">
              <el-input v-model="form.bankCardNumber" placeholder="请输入" disabled maxlength="11" />
           </el-form-item>
           </el-col>
           <el-col :span="24">
            <el-form-item label="开户行" prop="phonenumber">
              <el-input v-model="form.bankName" placeholder="请输入" disabled maxlength="11" />
           </el-form-item>
           </el-col>


        </el-row>




        <!-- <el-row>
           <el-col :span="24">
              <el-form-item label="备注">
                 <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
           </el-col>
        </el-row> -->
     </el-form>
        <template #footer>
           <div class="dialog-footer">
            <el-button type="primary" @click="agreeAppId">通 过</el-button>
              <el-button type="danger" @click="rejectAppId">驳回</el-button>
              <el-button @click="cancel">取 消</el-button>
           </div>
        </template>
     </el-dialog>
  </div>
</template>

<script setup name="Notice">

import { supporterApply, agree, reject,deleteAppId } from "@/api/aftersales/afteruser";
import cityData from './city.json'
const { proxy } = getCurrentInstance();
const {  sys_user_sex,sys_normal_disable } = proxy.useDict("sys_user_sex","sys_normal_disable" );

const noticeList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const options =ref(cityData)
const cityProps = ref({
  value:'code',
  label:'name' ,
  children: 'children',
})
const roleOptions = ref([
  {
    roleId: 0,
    roleName: '客户',
  },
  {
    roleId: 1,
    roleName: '售后',

  }
])
const addr =ref()
const applyId =ref()

const data = reactive({
 form: {},
 queryParams: {
   pageNum: 1,
   pageSize: 10,
   noticeTitle: undefined,
   createBy: undefined,
   status: undefined
 },

});

const { queryParams, form } = toRefs(data);


function getList() {
 loading.value = true;
 supporterApply(queryParams.value).then(response => {
   noticeList.value = response.rows;
   total.value = response.total;
   loading.value = false;
 });
}
/** 取消按钮 */
function cancel() {
 open.value = false;
 reset();
}
/** 表单重置 */
function reset() {
 form.value = {
   applyId: undefined,

 };
 proxy.resetForm("applyRef");
}
/** 搜索按钮操作 */
function handleQuery() {
 queryParams.value.pageNum = 1;
 getList();
}
/** 重置按钮操作 */
function resetQuery() {
 proxy.resetForm("queryRef");
 handleQuery();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
 ids.value = selection.map(item => item.applyId);
 single.value = selection.length != 1;
 multiple.value = !selection.length;
}
/** 新增按钮操作 */
function handleAdd() {
 reset();
 open.value = true;
 title.value = "添加公告";
}
function handleChange(e){
  console.log(e)
  console.log(addr.value)

}
/**修改按钮操作 */
function handleUpdate(row) {
   reset();
   form.value = row;
   open.value = true;
   applyId.value =row.applyId
   title.value = row.nickName;
   addr.value =  [row.provinceCode.toString().substr(0,2), row.cityCode.toString().substr(0,4), row.areaCode.toString()]

}
function rejectAppId(){
  reject( applyId.value).then(res=>{
    proxy.$modal.msgSuccess("驳回成功");
    open.value = false
    getList()
  })
}

function agreeAppId() {
  console.log(addr.value)
  agree( applyId.value).then(res=>{
    proxy.$modal.msgSuccess("通过成功");
    open.value = false
    getList()
  })
}
/** 删除按钮操作 */
function handleDelete(row) {
 const applyIds = row.applyId || ids.value
 proxy.$modal.confirm('是否确认人员为"' + row.nickName + '"的数据项？').then(function() {
   return deleteAppId(applyIds);
 }).then(() => {
   getList();
   proxy.$modal.msgSuccess("删除成功");
 }).catch(() => {});
}

getList();
</script>
