item.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <MeScroll :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
  3. <card @delItem="delItem" @showDetail="showDetail" @pass="pass" @fail="fail" :loginType="loginType" :list="list" ></card>
  4. </MeScroll>
  5. </template>
  6. <script>
  7. import MeScroll from '@/components/mescroll-body/mescroll-uni.vue'
  8. import card from './card.vue'
  9. var app=getApp()
  10. export default {
  11. components:{
  12. MeScroll,card
  13. },
  14. props: {
  15. params:Object,
  16. type: Number,
  17. i: Number,
  18. item:Object
  19. },
  20. data() {
  21. return {
  22. //审核不通过时展示
  23. modelShow:false,
  24. //审核不通过的原因
  25. opinion:'',
  26. dataDetail:{},
  27. loginType:'',
  28. //访客openId
  29. openId:'',
  30. //园区id
  31. agencyId:'',
  32. //企业id
  33. enterpriseId:'',
  34. isInit: false, // 是否初始化
  35. list: [], // 列表数据
  36. mescroll: null, // mescroll 对象
  37. // 上拉配置参数
  38. up: {
  39. noMoreSize: 3,
  40. auto: false,
  41. page: {
  42. page: 0,
  43. size: 10
  44. }
  45. },
  46. // 下拉配置参数
  47. down: {
  48. use: true,
  49. auto: false
  50. }
  51. }
  52. },
  53. created() {
  54. this.loginType=this.$cache.get('loginType')
  55. if (this.loginType==this.$loginType.AGENCY) {
  56. //园区管理员
  57. this.agencyId=this.$cache.get('agencyId')
  58. }else if (this.loginType==this.$loginType.ENTERPRISE) {
  59. //企业
  60. this.enterpriseId=this.$cache.get('enterpriseId')
  61. }else{
  62. //访客
  63. this.openId=this.$cache.get('openId')
  64. }
  65. },
  66. watch:{
  67. type(val) {
  68. if(!this.isInit && val === this.i) {
  69. this.mescroll.resetUpScroll()
  70. }
  71. }
  72. },
  73. mounted() {
  74. if(!this.isInit && this.i === 0) {
  75. this.mescroll.resetUpScroll()
  76. }
  77. },
  78. methods: {
  79. delItem(item){
  80. this.$dialog.showModal('确定要删除此记录?').then(res=>{
  81. this.$api.guest.remove(item.id).then(res=>{
  82. if (res.success==true) {
  83. this.mescroll.resetUpScroll()
  84. }
  85. })
  86. })
  87. },
  88. /**
  89. * 显示详情
  90. * @param {Object} item
  91. */
  92. showDetail(item){
  93. this.$emit('showDetail',item)
  94. },
  95. /**
  96. * 通过审核
  97. */
  98. pass(item){
  99. let that=this
  100. let params={
  101. id:item.id,
  102. checkState:1
  103. }
  104. this.$showModel('确定要审核通过此申请记录吗?').then(()=>{
  105. this.$api.guest.check(params).then(res=>{
  106. if (res.success==true) {
  107. this.$u.toast('操作成功')
  108. this.send(item.openId)
  109. this.mescroll.resetUpScroll()
  110. }else{
  111. this.$u.toast('操作失败')
  112. }
  113. })
  114. })
  115. },
  116. async send(openId){
  117. let tokenData={
  118. grantType:this.$api.wxData.subscribe_grant_type,
  119. appId:this.$api.wxData.appId,
  120. secret:this.$api.wxData.secret
  121. }
  122. let res=await this.$api.wxApi.getAccessToken(tokenData)
  123. let token=JSON.parse(res.data).access_token
  124. let subscribeData={
  125. accessToken:token,
  126. touser:openId,
  127. lang:"zh_CN",
  128. page:'/pages/guest/records/records',
  129. miniprogramState:this.$miniprogramState,
  130. templateId: this.$staffTmplIds[0],
  131. "data": {
  132. "name1": {
  133. "value": this.$cache.get('loginAccount')
  134. },
  135. "phrase5":{
  136. "value": "开门申请"
  137. },
  138. "phrase2": {
  139. "value": "审核通过"
  140. },
  141. "thing3": {
  142. "value": '已阅'
  143. },
  144. }
  145. }
  146. let resp=await this.$api.wxApi.subscribe(subscribeData)
  147. },
  148. /**
  149. * 审核不通过
  150. * @param {Object} item
  151. */
  152. fail(item){
  153. this.$emit('fail',item)
  154. },
  155. /**
  156. * @param {Object} mescroll 初始化组件
  157. */
  158. initMeScroll(mescroll) {
  159. this.mescroll = mescroll
  160. },
  161. /**
  162. * @param {Object} mescroll 上拉回调
  163. */
  164. async upFn(mescroll) {
  165. try{
  166. let that=this
  167. let params={
  168. current:mescroll.num,
  169. size:mescroll.size,
  170. }
  171. //审核状态
  172. if (this.item.value!=-1) {
  173. params.checkState=this.item.value
  174. }
  175. if (!this.$isEmpty(this.params.guestName)) {
  176. params.guestName=this.params.guestName
  177. }
  178. if (!this.$isEmpty(this.params.guestTel)) {
  179. params.guestTel=this.params.guestTel
  180. }
  181. if (this.loginType==this.$loginType.AGENCY) {
  182. //园区管理员
  183. params.agencyId=this.agencyId
  184. }else if (this.loginType==this.$loginType.ENTERPRISE) {
  185. //企业
  186. params.enterpriseId=this.enterpriseId
  187. }else{
  188. //访客
  189. params.openId=this.openId
  190. }
  191. let res={}
  192. if(this.$isEmpty(params.openId)){
  193. //不是访客
  194. res=await this.$api.guest.page(params)
  195. }else{
  196. //是访客,访客调的是不需要token的接口
  197. //先去除token
  198. this.$cache.remove('tokenObj')
  199. this.$cache.remove('token')
  200. res=await this.$api.guest.getByGuestOpenId(params)
  201. }
  202. let data=res.data.records
  203. let total=res.data.total
  204. mescroll.endBySize(data.length,total);
  205. if(mescroll.num == 1) that.list = []; //如果是第一页需手动制空列表
  206. that.list=that.list.concat(data); //追加新数据
  207. }catch(e){
  208. mescroll.endErr();
  209. }
  210. },
  211. /**
  212. * 下拉回调
  213. * */
  214. downFn(mescroll) {
  215. setTimeout(()=>{
  216. this.mescroll.resetUpScroll()
  217. uni.showToast({
  218. title:"刷新成功",
  219. icon:"none",
  220. position:"top"
  221. })
  222. },1500)
  223. },
  224. }
  225. }
  226. </script>
  227. <style lang="scss" scoped>
  228. view{
  229. box-sizing: border-box;
  230. }
  231. </style>