index.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import { gzCertAddressConfig, gzCertAddressParam } from "../../../services/api/orders/index"
  2. import { hideLoading, showLoading, showToast } from "../../../utils/message/index"
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. /// tabs
  9. tabs: [{id: 0, name: '国内'}, {id: 1, name: '国际'}],
  10. /// tab索引
  11. active: 0,
  12. /// 参数配置信息
  13. configs: <GuangZuan.GzCertAddressConfig[]>[],
  14. /// 显示的数据
  15. datas: <GuangZuan.GzCertAddressConfig[]>[],
  16. /// 选中的证书类型
  17. config: <GuangZuan.GzCertAddressConfig>{},
  18. /// 证书参数信息
  19. params: <GuangZuan.GzCertAddressParam[]>[],
  20. /// 证书号
  21. certno: '',
  22. /// 防伪码
  23. securityCode: '',
  24. /// 查询地址
  25. paramAddress: ''
  26. },
  27. /**
  28. * 证书查询
  29. */
  30. certSearch() {
  31. /// 合规性校验
  32. if (!this.check()) { return }
  33. var param = ''
  34. /// 参数拼接
  35. var filters = this.data.params.filter(itm => {
  36. return itm.certtype == this.data.config.certtype
  37. })
  38. /// 地址拼接
  39. filters.forEach(obj => {
  40. if (obj.orderindex == 1) {
  41. param = param.concat(obj.paramkey+'='+this.data.certno+(filters.length > 1 ? '&' : ''))
  42. } else {
  43. param = param.concat(obj.paramkey+'='+this.data.securityCode)
  44. }
  45. })
  46. /// 最终的查询地址
  47. this.setData({ paramAddress: this.data.config.queryaddress+(param != "" ? param : '') })
  48. },
  49. /**
  50. * 清空
  51. */
  52. clear() {
  53. /// 数据清空
  54. this.setData({
  55. certno: '',
  56. securityCode: '',
  57. paramAddress: ''
  58. })
  59. },
  60. /// 复制粘贴板
  61. setClipboard() {
  62. /// 数据为空
  63. if (this.data.paramAddress === '') {
  64. return
  65. }
  66. wx.setClipboardData({
  67. data: this.data.paramAddress,
  68. success: (res) => {
  69. console.log(res)
  70. /// 已复制到粘贴板
  71. showToast('已复制到粘贴板', 'success')
  72. }
  73. })
  74. },
  75. /**
  76. * 获取证书地址参数查询
  77. */
  78. gzCertAddressConfig() {
  79. /// loding.....
  80. showLoading(()=>{
  81. /// 发送查询
  82. gzCertAddressConfig({
  83. success: (res) => {
  84. if (res.code != 200) {
  85. hideLoading(()=>{}, '参数加载失败,原因:'+res.msg)
  86. return
  87. }
  88. /// 加载成功
  89. hideLoading(()=>{
  90. /// 设置数据
  91. this.setData({
  92. /// 配置数据
  93. configs: res.data,
  94. /// 显示数据
  95. datas: res.data.filter(itm => {
  96. /// 默认选中第一个
  97. if (itm.orderindex == 1) { itm.isCheck = true }
  98. return itm.certregion == this.data.active+1
  99. }),
  100. })
  101. /// 默认选中第一个
  102. this.setData({ config: this.data.datas[0] })
  103. })
  104. },
  105. fail: (emsg) => {
  106. hideLoading(()=>{}, emsg)
  107. }
  108. })
  109. })
  110. },
  111. /**
  112. * 钻石证书地址参数
  113. */
  114. gzCertAddressParam() {
  115. /// showLoading
  116. showLoading(()=>{
  117. /// 发送查询
  118. gzCertAddressParam({
  119. success: (res) => {
  120. if (res.code != 200) {
  121. hideLoading(()=>{}, '证书地址参数加载失败,原因:'+res.msg)
  122. return
  123. }
  124. hideLoading(()=>{
  125. /// 设置数据
  126. this.setData({
  127. /// 配置数据
  128. params: res.data,
  129. })
  130. })
  131. },
  132. fail: (emsg) => {
  133. hideLoading(()=>{}, emsg)
  134. }
  135. })
  136. })
  137. },
  138. /**
  139. * tab触发事件
  140. */
  141. onTabChange(e: any) {
  142. /// 设置激活项
  143. this.setData({
  144. active: e.detail.index,
  145. /// 显示数据
  146. datas: this.data.configs.filter(itm => {
  147. return itm.certregion == e.detail.index+1
  148. })
  149. })
  150. /// 默认选中第一个
  151. this.setData({ config: this.data.datas[0] })
  152. },
  153. /**
  154. * 返回上层视图
  155. */
  156. backToParent() {
  157. /// 返回上层视图
  158. wx.navigateBack()
  159. },
  160. /// 形状按钮点击事件
  161. onButtonClick(e: any) {
  162. const index = e.target.id
  163. /// 设置数据
  164. this.setData({
  165. datas: this.data.datas.map(item => {
  166. item.isCheck = item.orderindex == index
  167. return item
  168. }),
  169. })
  170. this.setData({ config: this.data.datas.filter(itm => { return itm.orderindex == index })[0] })
  171. },
  172. /**
  173. * 生命周期函数--监听页面加载
  174. */
  175. onLoad() {
  176. /// 获取参数配置信息
  177. this.gzCertAddressConfig()
  178. /// 获取钻石证书地址参数
  179. this.gzCertAddressParam()
  180. },
  181. /**
  182. * 生命周期函数--监听页面初次渲染完成
  183. */
  184. onReady() {
  185. },
  186. /// 合规性校验
  187. check(): boolean {
  188. /// 请输入证书号
  189. if (this.data.certno.length == 0) {
  190. showToast('请输入证书号!')
  191. return false
  192. }
  193. /// 请输入防伪码
  194. if (this.data.securityCode.length == 0) {
  195. showToast('请输入防伪码!')
  196. return false
  197. }
  198. return true
  199. },
  200. /**
  201. * 生命周期函数--监听页面显示
  202. */
  203. onShow() {
  204. },
  205. /**
  206. * 生命周期函数--监听页面隐藏
  207. */
  208. onHide() {
  209. },
  210. /**
  211. * 生命周期函数--监听页面卸载
  212. */
  213. onUnload() {
  214. },
  215. /**
  216. * 页面相关事件处理函数--监听用户下拉动作
  217. */
  218. onPullDownRefresh() {
  219. },
  220. /**
  221. * 页面上拉触底事件的处理函数
  222. */
  223. onReachBottom() {
  224. },
  225. /**
  226. * 用户点击右上角分享
  227. */
  228. onShareAppMessage() {
  229. }
  230. })