utils.ts 9.1 KB

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