/**
 * common.js
 * Description  公共方法
 * Creator JYW
 */
/*取消结束*/
import { $http } from '../config/https.js';
import { httpconfig as httpConfig } from '../config/httpConfig.js';
import Util from './util.js';
import Cache from './cache.js';
const cancelFinish = Util.debounce(function (admID, callback) {
    let userData = Cache.get('userData');
    let data = {
        params: [
            {
                admID: admID,
                userID: userData.userID,
                locID: userData.locID,
                hospID: userData.hospID
            }
        ]
    };
    $http.post(
        'urlDeault',
        this,
        {
            code: '03100125',
            data: data,
            success: function (res) {
                if (res.errorCode != '0') {
                    uni.showModal({
                        title: '提示',
                        content: res.errorMessage,
                        showCancel: false,
                        confirmText: '我知道了',
                        success(res) {}
                    });
                } else {
                    if (callback) {
                        uni.showModal({
                            title: '提示',
                            content: '取消结束成功!',
                            showCancel: false,
                            confirmText: '确认',
                            success(res) {}
                        });
                        callback(res);
                    }
                }
            }
        },
        {
            error: 'Y'
        }
    );
});
/*是否可取消结束*/
const canChangeFlag = function (admID, callback) {
    let patientData = Cache.get('patientData');
    if (!admID) {
        admID = patientData.admID;
    }
    const userData = Cache.get('userData');
    let data = {
        params: [
            {
                admID: admID,
                userID: userData.userID,
                locID: userData.locID,
                hospID: userData.hospID
            }
        ]
    };
    //
    $http.post('urlDeault', this, {
        code: '03100124',
        data: data,
        success: function (res) {
            if (res.errorCode == '0') {
                patientData.changeDataFlag = res.result;
                Cache.set('patientData', patientData);
                if (callback) {
                    callback(res);
                }
            }
        }
    });
};
/*是否未开医嘱*/
const getOrders = function (admID, callback) {
    const userData = Cache.get('userData');
    let data = {
        params: [
            {
                admID: admID,
                userID: userData.userID,
                locID: userData.locID,
                hospID: userData.hospID
            }
        ]
    };
    $http.post('urlDeault', this, {
        code: '03100131',
        data: data,
        success: function (res) {
            if (res.errorCode == '0') {
                if (callback) {
                    callback(res);
                }
            }
        }
    });
};
/*获取ip*/
const getIP = function (callback) {
    uni.request({
        url: httpConfig.domain + '/localIP',
        success: function (e) {
            callback(e.data.ipv4);
        },
        fail: function () {
            callback('127.0.0.1');
        }
    });
};
export default {
    cancelFinish,
    canChangeFlag,
    getOrders,
    getIP
};
