<template>
    <view class="check-container">
        <view class="check-top">
            <u-search placeholder="搜索岗位名" v-model="searchVal" @change="serchlist" :showAction="false"></u-search>
            <view class="top-type">
                <view :class="{ 'blue': checkType === 0 }" @click="changeCheckType(0)">全职岗位</view>
                <view :class="{ 'blue': checkType === 1 }" @click="changeCheckType(1)">零工岗位</view>
            </view>
        </view>
        <view class="check-content">
            <uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
                <uni-tr>
                    <uni-th width="104" align="center">操作</uni-th>
                    <uni-th align="center">岗位名称</uni-th>
                    <uni-th align="center">招聘人数</uni-th>
                    <uni-th align="center">参考工资</uni-th>
                    <uni-th align="center">零工工种</uni-th>
                    <uni-th align="center">年龄要求</uni-th>
                    <uni-th align="center">学历要求</uni-th>
                    <uni-th align="center">经验要求</uni-th>
                    <uni-th align="center">详细地址</uni-th>
                </uni-tr>
                <uni-tr v-for="(item, index) in tableData" :key="index">
                    <uni-td>
                        <view class="uni-group">
                            <button class="uni-button" v-if="item.reviewState !== 1" size="mini" type="primary"
                                @click="confirm(item)">通过</button>
                            <button class="uni-button" v-if="item.reviewState !== 9" size="mini" type="warn"
                                @click="cancle(item)">驳回</button>
                        </view>
                    </uni-td>
                    <template v-if="checkType === 0">
                        <uni-td align="center">{{ item.jobName }}</uni-td>
                    </template>
                    <template v-if="checkType === 1">
                        <uni-td align="center">{{ item.missionTitle }}</uni-td>
                    </template>
                    <uni-td align="center">{{ item.peopleNum }}</uni-td>
                    <uni-td align="center">{{ item.wage }}</uni-td>
                    <uni-td align="center">{{ item.worktypeNames }}</uni-td>
                    <uni-td align="center">{{ item.ageDesc }}</uni-td>
                    <uni-td align="center">{{ findEduArr(item.education)  }}</uni-td>
                    <uni-td align="center">{{ item.experienceDesc }}</uni-td>
                    <uni-td align="center">{{ item.address }}</uni-td>
                </uni-tr>
            </uni-table>
            <view class="uni-pagination-box">
                <uni-pagination :page-size="pageSize" :current="pageCurrent" :total="total" @change="pageChange" />
            </view>

            <!-- popup -->
            <u-modal :show="modalShow" @confirm="modalConfirm" ref="uModal" @cancel="modalShow = false" title="拒绝申请"
                :asyncClose="true" showCancelButton>
                <view class="slot-content" style="width: 100%;">
                    <u--textarea v-model="remarkVal" placeholder="请输入备注"></u--textarea>
                </view>
            </u-modal>
        </view>
    </view>
</template>
复制代码

</view>
</view>
</template>

<script>
    import {
        getMissionList,
        getJkWorksList,
        updateUserrecruitApproval
    } from '@/api/admin.js'
    import dic from '../../common/dic'
    import {
        debounce
    } from '@/untils/tools.js'
    export default {
        data() {
            return {
                eduArr: dic.eduArr,
                searchVal: '',
                remarkVal: '',
                tableData: [],
                pageSize: 10,
                pageCurrent: 0,
                total: 0,
                loading: false,
                checkType: 0, // 0 全职 1 零工
                modalShow: false,
                selectItem: null,
            }
        },
        onLoad() {
            this.getData('refresh')
        },
        methods: {
            async modalConfirm() {
                if (!this.remarkVal) {
                    this.modalShow = true
                    // #ifdef H5
                    this.$refs.uModal.loading = false
                    // #endif
                    // #ifndef H5
                    this.modalShow = false
                    // #endif
                    return this.$api.msg('请输入备注')
                } else {
                    let params = [{
                        jobType: this.checkType === 0 ? 1 : 0,
                        reviewState: 9,
                        id: this.selectItem.id,
                        reviewMsg: this.remarkVal
                    }]
                    let resData = await updateUserrecruitApproval(params)
                    if (resData.data.code === 200) {
                        this.getData('update')
                        this.modalShow = false
                    } else {
                        // #ifdef H5
                        this.$refs.uModal.loading = false
                        // #endif
                        // #ifndef H5
                        this.modalShow = false
                        // #endif
                    }
                }
            },
            confirm(value) {
                const _that = this
                uni.showModal({
                    title: '提示',
                    content: '确认通过审核',
                    success: async function(res) {
                        if (res.confirm) {
                            let params = [{
                                jobType: _that.checkType === 0 ? 1 : 0,
                                reviewState: 1,
                                id: value.id,
                                reviewMsg: _that.remarkVal
                            }]
                            let resData = await updateUserrecruitApproval(params)
                            if (resData.data.code === 200) {
                                _that.getData('update')
                            }
                        }
                    }
                });
            },
            cancle(value) {
                this.selectItem = value
                this.modalShow = true
            },
            serchlist: debounce(function(val) {
                this.getData('refresh')
            }, 600),
            changeCheckType(type) {
                this.checkType = type
                this.getData('refresh')
            },
            pageChange({
                type,
                current
            }) {
                switch (type) {
                    case 'next':
                        this.getData()
                        break;
                    case 'prev':
                        this.getData('prev')
                        break;
                }

            },
            async getData(type = 'next') {
                this.loading = true
                let params = {
                    current: this.pageCurrent,
                    pageSize: this.pageSize
                }
                switch (type) {
                    case 'next':
                        params.current += 1
                        break;
                    case 'prev':
                        params.current -= 1
                        break;
                    case 'refresh':
                        params.current = 1
                        params.pageSize = 10
                        break;
                }
                switch (this.checkType) {
                    case 0:
                        params.jobName = this.searchVal
                        break;
                    case 1:
                        params.missionTitle = this.searchVal
                        break;

                }
                let resData = null
                if (this.checkType === 0) {
                    resData = await getJkWorksList(params)
                } else {
                    resData = await getMissionList(params)
                }
                this.loading = false
                if (resData.data.code === 200) {
                    const {
                        current,
                        records,
                        total,
                        size
                    } = resData.data.data
                    this.tableData = records
                    this.pageCurrent = current
                    this.pageSize = size
                    this.total = total
                }
            },
            findEduArr(id) {
                const v = dic.eduArr[0].find((item) => item.value === id)
                if (v) return v.label
                return ''
            }

        }
    }
</script>

<style scoped>
    .check-container {
        padding: 12px;
    }

    .top-type {
        display: flex;
        justify-content: space-around;
        align-items: center;
        color: #666666;
        font-size: 14px;
        margin-top: 10px;
    }

    .blue {
        color: blue;
    }

    .check-top {
        margin-bottom: 24rpx;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        padding: 12px;
        z-index: 9;
        background-color: #ffffff;
    }

    .check-content {
        margin-top: 84px;
    }

    .uni-pagination-box {
        margin-top: 14px;
    }

    .uni-group {
        display: flex;
        align-items: center;
    }
</style>