Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/toolkit/MyUtl.lua
2020-11-30 22:39:38 +08:00

294 lines
8.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

MyUtl = {}
MyUtl.dampenStrength = 3 -- 惯性阻力
MyUtl.init = function(panel)
MyUtl.getUIContent(panel)
end
MyUtl.defaultTopHeight = 132
MyUtl.defaultBottomHeight = 147
local _ContentRect
local _sizeAdjust
---@return UnityEngine.Vector4
MyUtl.getUIContent = function(panel, top, bottom, forceCal)
-- if _ContentRect and (not forceCal) then
-- return _ContentRect
-- end
local sizeAdjust = UIRoot.GetPixelSizeAdjustment(panel.gameObject)
local height = Screen.height * sizeAdjust
top = top or MyUtl.defaultTopHeight
bottom = bottom or MyUtl.defaultBottomHeight
local offsetRect = NGUITools.offsetRect
top = top + offsetRect.y * height
bottom = bottom + offsetRect.w * height
_sizeAdjust = sizeAdjust
_ContentRect = Vector4(0, (bottom - top) / 2, Screen.width * sizeAdjust, height - (bottom + top))
return _ContentRect
end
MyUtl.setContentView = function(go, top, bottom)
local panel = go:GetComponent("UIPanel")
if panel then
panel.transform.localPosition = Vector3.zero
panel.clipOffset = Vector2.zero
panel.baseClipRegion = MyUtl.getUIContent(panel, top, bottom)
end
return panel.baseClipRegion
end
MyUtl.getSizeAdjust = function()
return _sizeAdjust
end
---@param cust _DBCust
MyUtl.showCallOption = function(cust)
---@type _ParamCLLPPopList2
local params = {}
params.title = "拨号选择"
params.list = {}
table.insert(
params.list,
{
index = 1,
name = joinStr("云拨号:", cust._phoneNo),
subname = joinStr("", DBCust.getTaskName(cust.custName))
}
)
table.insert(
params.list,
{
index = 2,
name = joinStr("本机拨号:", cust._phoneNo),
subname = joinStr("", DBCust.getTaskName(cust.custName))
}
)
params.callback = function(d)
local index = d.index
if index == 1 then
MyUtl.callCust(cust)
else
MyUtl.callCustByNative(cust.phoneNo, cust)
end
end
getPanelAsy("PanelPopList2", onLoadedPanelTT, params)
end
---public 拨号
MyUtl.callCust = function(cust)
if type(cust.jsonStr) == "string" then
cust.jsonStr = json.decode(cust.jsonStr)
end
cust.jsonStr = cust.jsonStr or {}
local phones = ArrayList()
local phonesVal = ArrayList()
local taskId = tostring(cust.taskId)
local fields = DBCust.getFieldsByTask(taskId)
for i, attr in ipairs(fields) do
if attr.attrType == DBCust.FieldType.phone then
local phNo = cust.jsonStr[joinStr(attr.id, "_", attr.attrName)]
if not isNilOrEmpty(phNo) then
phones:Add(joinStr(attr.attrName, ": ", MyUtl.hidePhone(phNo)))
phonesVal:Add(phNo)
end
end
end
if phones.Count > 0 then
phones:Insert(0, joinStr("默认: ", MyUtl.hidePhone(cust.phoneNo)))
phonesVal:Insert(0, cust.phoneNo)
CLUIPopListPanel.show(
phones,
phonesVal,
function(val, selectedItem)
if val then
MyUtl.doCall(cust.custId, val, cust)
end
end
)
else
MyUtl.doCall(cust.custId, cust.phoneNo, cust)
end
end
---public 云拨号
MyUtl.doCall = function(custId, phoneNo, cust, callback)
showHotWheel("拨号中...")
NetProto.send.bi_call(
custId,
phoneNo,
nil,
function(content)
hideHotWheel()
if content.success then
CLLCallListner.waite4Callback()
local orgs = {}
orgs.callback = "MyUtl.onEndincomingCall"
orgs.custList = cust and {cust} or content.result
orgs.phoneNo = phoneNo
CLLCallListner.waite4Callback(json.encode(orgs))
MyUtl.toastS("拨号成功,注意接听回拨电话!")
Utl.doCallback(callback)
end
end
)
end
MyUtl.onEndincomingCall = function(data)
local custList = data.custList
if custList and #custList > 0 then
if #custList == 1 then
getPanelAsy("PanelNewFollowSimple", onLoadedPanelTT, custList[1])
else
---@type _ParamCLLPPopList2
local params = {}
params.title = joinStr("新建跟进:", data.phoneNo)
params.list = {}
---@param _cust _DBCust
for i, _cust in ipairs(custList) do
table.insert(
params.list,
{
index = i,
name = joinStr("任务:", DBCust.getTaskName(_cust.taskId)),
subname = joinStr("客户:", _cust.custName)
}
)
end
params.callback = function(d)
local index = d.index
getPanelAsy("PanelNewFollowSimple", onLoadedPanelTT, custList[index])
end
getPanelAsy("PanelPopList2", onLoadedPanelTT, params)
end
else
MyUtl.confirm(
joinStr("是否将号码【", data.phoneNo, "】创建为客户?"),
function()
getPanelAsy("PanelNewCust", onLoadedPanelTT, {phoneNo = data.phoneNo})
end,
"创建为客户"
)
end
end
---public 调用系统拨打电话
MyUtl.callCustByNative = function(phoneNo, cust)
if CLUIFormUtl.callPhone then
CLUIFormUtl.callPhone(phoneNo)
else
Application.OpenURL(joinStr("tel:", phoneNo))
end
if cust then
getPanelAsy("PanelNewFollowSimple", onLoadedPanelTT, cust)
end
end
MyUtl.toast = function(msg, staySec)
CLToastRoot.toast(msg, CLToastRoot.Type.normal, staySec)
end
MyUtl.toastS = function(msg, staySec)
CLToastRoot.toast(msg, CLToastRoot.Type.success, staySec)
end
MyUtl.toastW = function(msg, staySec)
CLToastRoot.toast(msg, CLToastRoot.Type.warning, staySec)
end
MyUtl.toastE = function(msg, staySec)
CLToastRoot.toast(msg, CLToastRoot.Type.error, staySec)
end
MyUtl.confirm = function(msg, callback, buttonName)
getPanelAsy("PanelConfirm2", onLoadedPanelTT, {msg = msg, callback = callback, buttonName = buttonName})
end
MyUtl.isHidePhone = true
function MyUtl.setIsHidePhone(val)
MyUtl.isHidePhone = (val == 1 and true or false)
end
MyUtl.hidePhone = function(phone)
if isNilOrEmpty(phone) then
return ""
end
if not MyUtl.isHidePhone then
return phone
end
if #phone > 8 then
return joinStr(string.sub(phone, 1, 3), "****", string.sub(phone, 8))
else
return joinStr(string.sub(phone, 1, 3), "****")
end
end
MyUtl.Images = {
[".JPG"] = true,
[".JPEG"] = true,
[".PNG"] = true,
[".PDF"] = true,
[".BMP"] = true,
[".TGA"] = true,
[".GIF"] = true
}
---public 是图片
MyUtl.isImage = function(path)
local extension = Path.GetExtension(path)
return MyUtl.Images[string.upper(extension)] or false
end
MyUtl.CompressImage = function(imgPath, maxSize, quality)
if not File.Exists(imgPath) then
printe("文件不存在==" .. imgPath)
return
end
-- int quality = 80;//图片压缩质量1-100
quality = quality or 75
local bytes = File.ReadAllBytes(imgPath)
---@type UnityEngine.Texture2D
local texture = Texture2D(2, 2)
ImageConversion.LoadImage(texture, bytes)
texture = MyFileOpen.ResizeTexture(texture, maxSize, MyFileOpen.ImageFilterMode.Average)
local newBytes = ImageConversion.EncodeToJPG(texture, quality)
return newBytes
end
MyUtl.installNewApk = function(url)
if MyUtl.isDownloadingApk then
MyUtl.toast("正在下载安装,请耐心等待")
return
end
local downloadDir =
Utl.chgToSDCard(Path.Combine(Application.persistentDataPath, CLPathCfg.self.basePath, "download"))
local apkName
Path.GetFileName(url)
local localPath = joinStr(downloadDir, apkName)
if File.Exists(localPath) then
MyFileOpen.open(localPath)
else
MyUtl.isDownloadingApk = true
WWWEx.get(
url,
nil,
CLAssetType.bytes,
function(content, orgs)
MyUtl.isDownloadingApk = false
Directory.CreateDirectory(Path.GetDirectoryName(localPath))
File.WriteAllBytes(localPath, content)
MyFileOpen.open(localPath)
end,
function()
MyUtl.isDownloadingApk = false
end,
nil,
false,
1
)
end
end
return MyUtl