index.ts 4.9 KB

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