/**
@author:fugy
@date:2019.1.16
@info:项目抢单规则设定=project-rule-api
 */
const planHz = [
    { id: 'd', name: '每日' },
    { id: 'w', name: '每周' },
    { id: 'm', name: '每月' },
    { id: 'y', name: '每年' }
]
import httputils from '@/api/httputils'
const api = {
    getLevelDef() {
        return { value: 'id', label: 'name', children: 'content' }
    },
    //获取级别列表
    getLevelList() {
        return new Promise((resolve, reject) => {
            httputils.getJson('/server/workorder/engineer/level/def/list', null, resp => {
                let result = []
                resp.content.forEach(item => {
                    let temp = { id: item.skillId, name: item.name, content: [] }
                    if (item.content) {
                        item.content.forEach(level => {
                            temp.content.push({ id: level.levelId, name: level.name })
                        })
                    }
                    result.push(temp)
                })
                resolve(result)
            })
        })
    },
    // 获取工单类型列表
    getOrderType() {
        return new Promise(resolve => {
            httputils.getJson('/server/workorder/rule/queryWoTypeList', {}, resp => {
                if (resp.result == 'success' && resp.count) {
                    resolve(resp.content)
                } else {
                    resolve([])
                }
            })
        })
    },
    //获取计划频率
    getPlanHz() {
        return planHz
    },
    //获取项目抢单规则的列表数据
    getListData(params) {
        return new Promise(resolve => {
            httputils.postJson('/server/workorder/rule/query', params, resp => {
                if (resp.result == 'success' && resp.content.length) {
                    resolve(resp.content)
                } else {
                    resolve([])
                }
            })
        })
    },
    //配置当前的工单的规则
    updateWorkOrder(params) {
        return new Promise(resolve => {
            httputils.postJson('/server/workorder/rule/createOrUpdate', params, resp => {
                resolve(resp)
            })
        })
    }
}
export default api
