utils.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. import { queryGetDivisions } from "./api/common/index";
  2. import { getTaAccounts } from './api/account/index';
  3. import { v4 } from "../utils/uuid/index";
  4. import { IMessageHead } from './../services/socket/trade/protobuf/proto';
  5. import Toast from "../miniprogram_npm/@vant/weapp/toast/toast";
  6. /// 获取履约步骤类型ID
  7. export function getSteptype(typeid: number): string {
  8. switch (typeid) {
  9. case 1:
  10. return '买方支付'
  11. break;
  12. case 2:
  13. return '卖方收款'
  14. break;
  15. case 3:
  16. return '买方自提'
  17. break;
  18. case 4:
  19. return '卖方发货'
  20. break;
  21. case 5:
  22. return '买方确认货'
  23. break;
  24. case 6:
  25. return '卖方发票'
  26. break;
  27. case 7:
  28. return '买方确认票'
  29. break;
  30. case 8:
  31. return '卖仓单转移'
  32. break;
  33. case 9:
  34. return '释放卖方冻结'
  35. break;
  36. case 10:
  37. return '货款溢短'
  38. break;
  39. case 11:
  40. return '生成合同[中江]'
  41. break;
  42. case 12:
  43. return '运费'
  44. break;
  45. case 90:
  46. return '确认支付'
  47. break;
  48. case 91:
  49. return '确认放行'
  50. break;
  51. default:
  52. return '买方支付(直接扣款)'
  53. break;
  54. }
  55. }
  56. /// 获取履约步骤类型ID
  57. export function getStepStatus(stepstatus: number): string {
  58. switch (stepstatus) {
  59. case 1:
  60. return '待开始'
  61. break;
  62. case 2:
  63. return '进行中'
  64. break;
  65. case 3:
  66. return '已完成'
  67. break;
  68. case 4:
  69. return '延期(进行中)'
  70. break;
  71. case 5:
  72. return '失败'
  73. break;
  74. case 6:
  75. return '自动完成'
  76. break;
  77. default:
  78. return '超时关闭'
  79. break;
  80. }
  81. }
  82. /// 获取履约状态
  83. export function getPerformancestatus(status: number): string {
  84. switch (status) {
  85. case 1:
  86. return '待激活'
  87. break;
  88. case 2:
  89. return '正常'
  90. break;
  91. case 3:
  92. return '处理错误'
  93. break;
  94. case 4:
  95. return '违约待处理'
  96. break;
  97. case 5:
  98. return '违约处理中'
  99. break;
  100. case 6:
  101. return '完成'
  102. break;
  103. case 7:
  104. return '违约已完成'
  105. break;
  106. case 8:
  107. return '释放冻结失败 '
  108. break;
  109. case 9:
  110. return '超时待处理'
  111. break;
  112. default:
  113. return '超时关闭'
  114. break;
  115. }
  116. }
  117. /// 获取地区区域信息
  118. export function getDivisions() {
  119. /// 发送请求
  120. queryGetDivisions({
  121. enableAuthorization: false,
  122. success: (res) => {
  123. /// 数据缓存
  124. setDivisions(res.data)
  125. },
  126. fail: () => {
  127. Toast('地区信息获取失败')
  128. }
  129. })
  130. }
  131. /// 获取资金账户信息
  132. export function taAccounts() {
  133. /// 发送请求
  134. getTaAccounts({
  135. data: {
  136. loginID: loginid()
  137. },
  138. success: (res) => {
  139. /// 数据缓存
  140. wx.setStorageSync('GetTaAccounts', res.data)
  141. wx.setStorageSync('AccountID', res.data[0].accountid)
  142. },
  143. fail: () => {
  144. Toast('资金账户信息获取失败')
  145. }
  146. })
  147. }
  148. /// 获取当前对应的资金账户
  149. export function taAccount(accountid: number): GuangZuan.TaAccount {
  150. const tas = <GuangZuan.TaAccount[]>wx.getStorageSync('GetTaAccounts')
  151. return tas.filter(obj => {
  152. return obj.accountid === accountid
  153. })[0]
  154. }
  155. /// 获取登录Loginid
  156. export function loginid() {
  157. return wx.getStorageSync('LoginID')
  158. }
  159. /// 获取用户userid
  160. export function userid() {
  161. return wx.getStorageSync('UserId')
  162. }
  163. /// 获取资金用户ID
  164. export function accountid(): number {
  165. return wx.getStorageSync('AccountID') ?? 0
  166. }
  167. /// 获取用户Token
  168. export function xtoken() {
  169. return wx.getStorageSync('Authorization')
  170. }
  171. /// 清除用户Token
  172. export function clearXtoken() {
  173. wx.removeStorageSync('Authorization')
  174. }
  175. /// 获取市场id
  176. export function marketid() {
  177. return wx.getStorageSync('MarketID')
  178. }
  179. export function marketID(mode: number) {
  180. return loginQuery().markets.filter(obj => { return obj.trademode === mode})[0].marketid
  181. }
  182. /// 是否加密
  183. export function isEncrypted() {
  184. return false
  185. }
  186. /// 存储地区信息
  187. export function setDivisions(datas: GuangZuan.GetDivisions[]) {
  188. wx.setStorageSync('GetDivisions', datas)
  189. }
  190. /// 获取地区信息
  191. export function divisions() {
  192. return wx.getStorageSync('GetDivisions')
  193. }
  194. /// 终端类型
  195. export function clientType() {
  196. return 5
  197. }
  198. /// 返回proto交易头
  199. export function protoHeader(funcode: number, marketID: number = marketid()) {
  200. /// 组合请求头
  201. const header: IMessageHead = {
  202. FunCode: funcode,
  203. AccountID: accountid(),
  204. UserID: userid(),
  205. MarketID: marketID,
  206. UUID: v4()
  207. }
  208. return header
  209. }
  210. /// 获取时间戳
  211. export function timetample() {
  212. return Date.parse(new Date().toString())
  213. }
  214. /// 获取登录查询数据信息
  215. export function loginQuery(): GuangZuan.LoginQuery {
  216. const data = <GuangZuan.LoginQuery>wx.getStorageSync('LoginQuery')
  217. return data
  218. }
  219. /// 获取登录账号
  220. export function loginCode(): string {
  221. const code = (<GuangZuan.LoginQuery>wx.getStorageSync('LoginQuery')).loginAccount.logincode
  222. return code === '' ? loginid() : code
  223. }
  224. /// 存储所有的枚举信息
  225. export function setAllEnums(enums: GuangZuan.AllEnums[]) {
  226. wx.setStorageSync('AllEnums', enums)
  227. }
  228. export function getAllEnums(): GuangZuan.AllEnums[] {
  229. const objs = <[GuangZuan.AllEnums]>wx.getStorageSync('AllEnums')
  230. return objs
  231. }
  232. export function getEnumList(enumdiccode: string): GuangZuan.AllEnums[] {
  233. const objs = getAllEnums().filter(obj => {
  234. return obj.enumdiccode === enumdiccode
  235. })
  236. return objs
  237. }
  238. /// 获取对应枚举的值
  239. export function getEnumdicValue(enumdiccode: string, enumitemname: number): string {
  240. const objs = getEnumList(enumdiccode)
  241. if (objs.length != 0) {
  242. const enums = objs.filter(obj => {
  243. return obj.enumitemname === enumitemname
  244. })
  245. return enums[0].enumdicname
  246. }
  247. return ''
  248. }
  249. /// 缓存所有的错误码信息
  250. export function setAllErrors(errors: GuangZuan.Error[]) {
  251. wx.setStorageSync('AllErrors', errors)
  252. }
  253. export function getAllErrors(): GuangZuan.Error[] {
  254. return <[GuangZuan.Error]>wx.getStorageSync('AllErrors')
  255. }
  256. export function getErrorMsg(retcode: number): string {
  257. const errors = getAllErrors()
  258. return errors.filter(obj => {
  259. return retcode.toString() === obj.errorcode
  260. })[0].description
  261. }
  262. /// 设置登录账号
  263. export function setLoginCode(code: string) {
  264. wx.setStorageSync('loginCode', code)
  265. }
  266. export function getLoginCode(): string {
  267. return wx.getStorageSync('loginCode')
  268. }
  269. /// 设置我的收藏
  270. export function saveMyFavorites(data: String[]) {
  271. wx.setStorageSync('Favorites', data)
  272. }
  273. /// 获取我的收藏
  274. export function getMyFavorites(): String[] {
  275. return <String[]>wx.getStorageSync('Favorites')
  276. }
  277. /// 判断是否为我的收藏
  278. export function isMyFavorite(goodsno: string): boolean {
  279. const objs = getMyFavorites()
  280. return objs.some(obj => { return obj === goodsno })
  281. }
  282. /// 移除我的收藏
  283. export function removeMyFavorite(goodsno: string) {
  284. const objs = getMyFavorites()
  285. /// 移除数据
  286. if (objs.some(obj => { return obj === goodsno })) {
  287. const news = objs.filter(obj => { return obj != goodsno })
  288. /// 更新数据
  289. saveMyFavorites(news)
  290. }
  291. }
  292. /// 添加我的收藏
  293. export function addMyFavotite(goodsno: String) {
  294. var objs = getMyFavorites()
  295. /// 移除数据
  296. if (!(objs.some(obj => { return obj === goodsno }))) {
  297. objs.push(goodsno)
  298. /// 更新数据
  299. saveMyFavorites(objs)
  300. }
  301. }
  302. /// 登录查询
  303. export function saveLoginQuery(data: GuangZuan.LoginQuery) {
  304. /// 数据存储
  305. wx.setStorageSync('LoginQuery', data)
  306. }
  307. /// 存储市场ID
  308. export function saveMarketID(id: number) {
  309. wx.setStorageSync('MarketID', id)
  310. }
  311. /// 默认挂牌大厅为出售
  312. export function saveTradeActive(active: number) {
  313. wx.setStorageSync('trade_active', active)
  314. }
  315. /// getTradeActive
  316. export function getTradeActive() {
  317. return Number(wx.getStorageSync('trade_active'))
  318. }
  319. /// 存储token
  320. export function saveAuthorization(token: string) {
  321. wx.setStorageSync('Authorization', token)
  322. }
  323. /// 存储LoginID
  324. export function saveLoginID(loginId: number) {
  325. wx.setStorageSync('LoginID', loginId)
  326. }
  327. /// 存储UserId
  328. export function saveUserId(userId: number) {
  329. wx.setStorageSync('UserId', userId)
  330. }
  331. /// 存储微信头像
  332. export function saveAvatarUrl(avatarUrl: string) {
  333. wx.setStorageSync('avatarUrl', avatarUrl)
  334. }
  335. /// 获取微信头像
  336. export function getAvatarUrl(): string {
  337. return wx.getStorageSync('avatarUrl')
  338. }
  339. export function setRUserecevieInfo(obj: GuangZuan.UserReceiveInfo) {
  340. wx.setStorageSync('UserReceiveInfo', obj)
  341. }
  342. export function getUserRecevieInfo(): GuangZuan.UserReceiveInfo {
  343. return wx.getStorageSync('UserReceiveInfo')
  344. }
  345. export function deleteUserRecevieInfo() {
  346. const obj = getWrUserReceiptInfo()
  347. if (obj) {
  348. wx.removeStorageSync('UserReceiveInfo')
  349. }
  350. }
  351. export function setWrUserReceiptInfo(obj: GuangZuan.WrUserReceiptInfo) {
  352. wx.setStorageSync('WrUserReceiptInfo', obj)
  353. }
  354. export function getWrUserReceiptInfo(): GuangZuan.WrUserReceiptInfo {
  355. return wx.getStorageSync('WrUserReceiptInfo')
  356. }
  357. export function deleteWrUserReceiptInfo() {
  358. const obj = getWrUserReceiptInfo()
  359. if (obj) {
  360. wx.removeStorageSync('WrUserReceiptInfo')
  361. }
  362. }
  363. /// 保存查询钻石条件
  364. export function saveDiamondFilters(info: any) {
  365. const jsonStr = JSON.stringify(info)
  366. wx.setStorageSync('TradeParams', jsonStr)
  367. }
  368. export function diamondFilters() {
  369. const jsonStr = wx.getStorageSync('TradeParams') ?? ''
  370. if (jsonStr != '' ) {
  371. return JSON.parse(jsonStr)
  372. }
  373. return undefined
  374. }
  375. export function removeDiamondFilters() {
  376. wx.removeStorageSync('TradeParams')
  377. }