import http from "@/utils/request"
import common from "@/utils/common"

export default {
    queryDeviceModelBindNum: {
		method: 'QueryDeviceModelBindNum',
		name: "设备型号使用情况",
		post: async function (datas) {
            var data = {
                'DeviceModelCode': datas, 
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
    addDeviceType: {
		method: 'AddDeviceType',
		name: "新增设备类型",
		post: async function (req) {
            var tempList = []
            for (let index = 0; index < req.deviceModels.length; index++) {
              var element = req.deviceModels[index]
              //console.log(element)
              tempList.push({ 'DeviceModelName': element.value })
            }
            var data = {
                'DeviceTypeCode': req.deviceTypeCode, 
                'DeviceTypeName': req.deviceTypeName, 
                'DeviceModelList': tempList
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
    modifyDeviceType: {
		method: 'ModifyDeviceType',
		name: "修改设备类型",
		post: async function (req) {
            var tempList = []
            for (let index = 0; index < req.deviceModels.length; index++) {
                var code = req.deviceModels[index].key
                if (req.deviceModels[index].key.indexOf('DictionaryDO') === -1) {
                    code = ''
                }
                tempList.push({ 'DeviceModelName': req.deviceModels[index].value, 'DeviceModelCode': code })
            }
            var data = {
                'DeviceTypeCode': req.deviceTypeCode, 
                'DeviceTypeName': req.deviceTypeName, 
                'DeviceModelList': tempList
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
    deviceTypeList: {
		method: 'GetDeviceTypePages',
		name: "设备类型列表",
		post: async function (params) {
            var data = {
                'PageIndex': params.page,
                'PageSize': params.pageSize,
                'DeviceType': params.deviceType,
                'DeviceModel': params.deviceModel
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
    deviceList: {
		method: 'GetDevicePages',
		name: "获取设备列表",
		post: async function (params) {
            var queryType = params.searchType == null ? '' : params.searchType;
            var hospitals = (params.hospitals === null || params.hospitals === undefined || params.hospitals === '') ? null : [params.hospitals]
            var data = {
                'PageIndex': params.page,
                'PageSize': params.pageSize,
                'QueryType': queryType,
                'Keyword': params.keyword,
                'Hospitals': hospitals,
                'UserName': params.userName,
                'AdminName': params.adminName
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
    deviceUserList: {
		method: 'GetManageDeviceUserPages',
		name: "查询设备用户列表",
		post: async function (params) {
            var queryType = params.queryType == null ? '' : params.queryType
            var data = {
                'PageIndex': params.page,
                'PageSize': params.pageSize,
                'QueryType': queryType,
                'Keyword': params.keyword,
                'DeviceCodes': params.deviceCodes,
                'Type': params.type
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
    shareDevice: {
		method: 'ShareDevice',
		name: "设备分享",
		post: async function (params) {
            var data = {
                'DeviceCodes': params.deviceCodes,
                'UserCodeList': params.userCodeList
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
    removeShareDevice: {
		method: 'RemoveShareDevice',
		name: "移除设备分享",
		post: async function (params) {
            var data = {
                'DeviceCodes': params.deviceCodes,
                'UserCodeList': params.userCodeList
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
}
