您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Keywordsearch.vue 4.4 KiB

2 年前
2 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="translation">
  3. <view style="width: 690rpx;height: 64rpx;margin: 0 auto;margin-top: 30rpx;background: #F2F2F2;border-radius: 32rpx;
  4. display: flex;align-items: center;">
  5. <view style="width: 10%;height: 64rpx;display: flex;align-items: center;">
  6. <image style="width: 28rpx;height: 28rpx;margin-left: 30rpx;" src="/static/images/search.png" mode=""></image>
  7. </view>
  8. <view style="width: 90%;height: 64rpx;display: flex;align-items: center;">
  9. <input type="text" @input="searchinfo" :disabled="disabled" v-model="keyword" placeholder="请输入关键字"
  10. style="width: 100%;color: #999999;font-size: 24rpx;"/>
  11. </view>
  12. </view>
  13. <view style="width: 690rpx;margin: 0 auto;margin-top: 10rpx;">
  14. <view style="width: 100%;border-bottom: 1px solid #E0E0E0;display: flex;padding-bottom: 10rpx;margin-top: 40rpx;"
  15. v-for="(item,index) in listarr" :key='index' @click="toaidoinfo(item.Content,item.corpusId,item.index)">
  16. <view style="width: 26rpx;height: 36rpx;margin-top: 4rpx;">
  17. <image style="width: 26rpx;height: 28rpx;" src="../../static/images/testimg.png" mode=""></image>
  18. </view>
  19. <view v-html="item.Content.text" style="color: #666666;font-size: 28rpx;line-height: 36rpx;margin-left: 10rpx;width: 80%;"></view>
  20. <view style="font-size: 28rpx;width: 10%;width: 14%;text-align: right;">{{item.Content.time}}</view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. var util = require("../../utils/util.js");
  27. var config = require("../../config");
  28. export default {
  29. data() {
  30. return {
  31. customerId:'',
  32. listarr:[],
  33. keyword:'',
  34. skpl:'',
  35. disabled:false,
  36. tipsFncName: '', // 通知其他页面的方法名称
  37. };
  38. },
  39. onLoad(options) {
  40. this.customerId = options.customerId;
  41. this.keyword=options.keyword;
  42. this.skpl=options.skpl;
  43. if (options.UpDateEvent) this.tipsFncName = options.UpDateEvent
  44. if(this.skpl==2){
  45. this.searchinfo()
  46. this.disabled=true;
  47. }else{
  48. this.disabled=false;
  49. }
  50. },
  51. methods: {
  52. formatTime(num) {
  53. //格式化时间格式
  54. num = num.toFixed(0);
  55. let second = num % 60;
  56. if (second < 10) second = '0' + second;
  57. let min = Math.floor(num / 60);
  58. if (min < 10) min = '0' + min;
  59. return min + ":" + second;
  60. },
  61. searchinfo(){
  62. if(this.keyword.length==0){
  63. return
  64. }else{
  65. let parames={
  66. keyword:this.keyword,
  67. customerId:this.customerId
  68. }
  69. this.$u.post("/corpus/keyWordsMatching", parames).then(res => {
  70. res.forEach(item=>{
  71. item.Content=JSON.parse(item.transferContent)
  72. })
  73. res.forEach(cet=>{
  74. cet.Content.time=this.formatTime(cet.Content.bg/1000)
  75. cet.Content.text=this.brightKeyword(cet.Content.onebest)
  76. })
  77. this.listarr=res;
  78. })
  79. }
  80. },
  81. //替换方法
  82. brightKeyword(val) {
  83. if (val.indexOf(this.keyword) !== -1) {
  84. return val.replace(this.keyword, `<font style='color: red'>${this.keyword}</font>`);
  85. } else {
  86. return val;
  87. }
  88. },
  89. //跳转
  90. toaidoinfo(item,id,index){
  91. uni.setStorageSync("entrance", 2); //写入缓存
  92. item.customerId=this.customerId;
  93. item.id=id;
  94. item.index=index;
  95. if(this.skpl==2){
  96. this.infostust(item)
  97. }else{
  98. let pages = getCurrentPages() //获取当前页面栈的信息
  99. let prevPage = pages[pages.length - 2] //获取上一个页面
  100. if (this.tipsFncName) uni.$emit(this.tipsFncName, item)
  101. prevPage.setData({ //把需要回传的值保存到上一个页面
  102. info: item
  103. });
  104. wx.navigateBack({ //然后返回上一个页面
  105. delta: 1
  106. })
  107. }
  108. },
  109. //只有一条的时候
  110. infostust(item){
  111. uni.setStorageSync("searchobj", item); //写入缓存
  112. const parames = {
  113. pageNum: 1,
  114. pageSize: 100,
  115. query: {
  116. customerId: this.customerId,
  117. }
  118. }
  119. this.$u.post("/corpus/findByPage", parames).then(res => {
  120. if(res[0].merge==0){
  121. let newobj = res[0];
  122. if (this.tipsFncName) {
  123. uni.$emit(this.tipsFncName, item)
  124. uni.navigateBack()
  125. return
  126. }
  127. uni.navigateTo({
  128. url: `/pages/mine/details2?customerId=${newobj.customerId}&status=${newobj.status}&stateisshow=${'2'}`
  129. })
  130. }else{
  131. let newobj = res[0];
  132. uni.navigateTo({
  133. url: `/pages/mine/details?customerId=${newobj.customerId}&status=${newobj.status}&stateisshow=${'2'}`
  134. })
  135. }
  136. })
  137. },
  138. },
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. </style>