generateList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <view class="gbox">
  3. <u-list @scrolltolower="scrolltolower" height="100%">
  4. <u-list-item v-for="(item, index) in list" :key="index">
  5. <view class="gbox-item">
  6. <view class="gbox-item-top adf">
  7. <view class="gbox-item-top-type">{{typeCfg[item.type]||'个人版'}}</view>
  8. <view class="gbox-item-top-title">{{item.reportName||''}}</view>
  9. </view>
  10. <view class="gbox-item-ps">
  11. <view class="gbox-item-p adfac">
  12. <view class="gbox-item-p-left">团队名称:</view>
  13. <view class="gbox-item-p-right">{{item.teamName||''}}</view>
  14. </view>
  15. <view class="gbox-item-p adf">
  16. <view class="gbox-item-p-left">报告状态:</view>
  17. <view class="gbox-item-p-right" :style="{'color':stateColor[item.state]}">{{stateDict[item.state]}}</view>
  18. </view>
  19. <view class="gbox-item-p adf">
  20. <view class="gbox-item-p-left">创建时间:</view>
  21. <view class="gbox-item-p-right">{{item.createDate||''}}</view>
  22. </view>
  23. <image class="gbox-item-ask" :src="imgBase+'report_ask.png'" @click="askReport(item)" v-if="item.state==1&&item.fileUrl"></image>
  24. </view>
  25. <view class="gbox-item-bottom adfacjb">
  26. <view class="gbox-item-bottom-rightbox adfac" v-if="item.type==1">
  27. <view class="gbox-item-bottom-right" @click="reviewPdf(item)" v-if="item.state==1">预览报告</view>
  28. <view class="gbox-item-bottom-right" @click="reviewReport(item)" v-if="item.state==1&&item.fileUrl">查看报告</view>
  29. <view class="gbox-item-bottom-right" @click="reSendReport(item)" v-if="item.state==-1">重新生成</view>
  30. </view>
  31. <view class="gbox-item-bottom-rightbox adfac" v-else-if="item.type==2">
  32. <view class="gbox-item-bottom-right" @click="forwardReport(item)" v-if="item.state==1&&item.fileUrl">发送邮件</view>
  33. <view class="gbox-item-bottom-right" @click="reviewPdf(item)" v-if="item.state==1">预览报告</view>
  34. <view class="gbox-item-bottom-right" @click="reviewReport(item)" v-if="item.state==1&&item.fileUrl">查看报告</view>
  35. <view class="gbox-item-bottom-right" @click="sendReport(item)" v-if="item.state!=-1">发送报告</view>
  36. <view class="gbox-item-bottom-right" @click="reSendReport(item)" v-if="item.state==-1">重新生成</view>
  37. </view>
  38. </view>
  39. </view>
  40. </u-list-item>
  41. </u-list>
  42. <cus-select-team-user
  43. ref="selectTeamUser"
  44. :show="teamUserShow"
  45. :list="teamUserList"
  46. @close="handleClose"
  47. @changeAll="changeAll"
  48. @handleSelectUser="handleSelectUser"
  49. @handleConfirm="sendConfirm"
  50. ></cus-select-team-user>
  51. </view>
  52. </template>
  53. <script>
  54. import { getPlatformInfo } from '@/utils/platform.js';
  55. import CusSelectTeamUser from '@/components/CusSelectTeamUser/index.vue'
  56. export default {
  57. props:{
  58. list:{
  59. typeof:Array,
  60. default:[]
  61. }
  62. },
  63. components:{ CusSelectTeamUser },
  64. data(){
  65. return {
  66. typeCfg:{
  67. 1:'个人版',
  68. 2:'团队版',
  69. 0:'团队PRO版'
  70. },
  71. stateDict:{
  72. '0':'生成中',
  73. '1':'生成成功',
  74. '-1':'生成失败'
  75. },
  76. stateColor:{
  77. '0':'#FFD750',
  78. '1':'#33A7A7',
  79. '-1':'#F4657A'
  80. },
  81. teamUserShow:false,
  82. teamUserList:[],
  83. categoryData:[],
  84. sendType:1,
  85. selectItem:null,
  86. }
  87. },
  88. methods:{
  89. scrolltolower(){
  90. this.$emit('scrolltolower')
  91. },
  92. getUserCategoryData(){
  93. return new Promise((resolve,reject)=>{
  94. this.$api.get('/getListByType/UserCategory').then(({data:res})=>{
  95. if(res.code!==0) return this.$showToast(res.msg)
  96. this.categoryData = res.data.map(d=>({name:d.dictLabel,id:d.dictValue}))
  97. resolve()
  98. })
  99. })
  100. },
  101. async forwardReport(item){
  102. //发送给账号自己的邮箱
  103. if(!uni.getStorageSync('userInfo')||!JSON.parse(uni.getStorageSync('userInfo')).email) return this.$showModal('发送邮件前请先在我的-设置-用户信息中绑定邮箱')
  104. uni.showModal({
  105. title:'温馨提示',
  106. content:`是否确认将“${item.reportName||''}”下的PDF报告文件发送到账号绑定邮箱中?`,
  107. confirmText:'确认',
  108. success: (res) => {
  109. if(res.confirm){
  110. this.$api.get(`/core/report/sendToEmail/${item.reportId}`).then(({data:res})=>{
  111. if(res.code!==0) return this.$showToast(res.msg)
  112. this.$showModal('邮件发送成功,可在绑定的邮箱中查看详细内容。')
  113. })
  114. }
  115. }
  116. })
  117. // this.sendType = 1;
  118. // this.$refs.selectTeamUser.title = '发送邮件'
  119. // await this.getUserCategoryData()
  120. // this.$api.get(`/core/member/listByQueTeamId/${item.teamQueId}`).then(({data:res})=>{
  121. // if(res.code!==0) return this.$showToast(res.msg)
  122. // this.teamUserList = res.data;
  123. // this.teamUserList.forEach((l,i)=>{
  124. // l.categoryName = this.categoryData.find(c=>c.id==l.category)?.name;
  125. // this.$set(this.teamUserList[i],'select',false);
  126. // })
  127. // this.teamUserShow = true;
  128. // })
  129. },
  130. handleSelectUser(index){
  131. this.$set(this.teamUserList[index],'select',!this.teamUserList[index].select);
  132. this.dealNumAndAll()
  133. },
  134. handleClose(){
  135. this.teamUserShow = false;
  136. this.initSelectUserComponent();
  137. },
  138. changeAll(selected){
  139. this.teamUserList.forEach((l,i)=>{
  140. this.$set(this.teamUserList[i],'select',selected);
  141. })
  142. this.$refs.selectTeamUser.selectNums = this.teamUserList.filter(l=>l.select).length;
  143. },
  144. dealNumAndAll(){
  145. const selectnum = this.teamUserList.filter(l=>l.select).length;
  146. this.$refs.selectTeamUser.selectNums = selectnum;
  147. this.$refs.selectTeamUser.selectAll = selectnum === this.teamUserList.length;
  148. },
  149. sendConfirm(){
  150. if(this.teamUserList.filter(t=>t.select).length===0) return this.$showToast('请选择要发送的用户')
  151. if(this.sendType===1&&(!uni.getStorageSync('userInfo')||!JSON.parse(uni.getStorageSync('userInfo')).email)) return this.$showModal('发送前请先在我的-设置-用户信息中绑定邮箱')
  152. if(this.sendType===1){
  153. this.handleClose();
  154. } else if(this.sendType===2){
  155. const item = JSON.parse(JSON.stringify(this.selectItem));
  156. uni.showModal({
  157. title:'发送报告',
  158. content:`是否确认将“${item.reportName||''}”发送给团队成员`,
  159. confirmText:'确认',
  160. success: (res) => {
  161. if(res.confirm){
  162. this.$api.post(`/core/report/sendReport`,{
  163. reportId:item.reportId,
  164. memberList:this.teamUserList.filter(t=>t.select).map(t=>({id:t.id,mobile:t.mobile,category:t.category}))
  165. }).then(({data:res})=>{
  166. if(res.code!==0) return this.$showToast(res.msg)
  167. this.handleClose();
  168. uni.navigateTo({
  169. url:'/pagesHome/sendResult?result='+res.code
  170. })
  171. })
  172. }
  173. }
  174. })
  175. }
  176. },
  177. initSelectUserComponent(){
  178. this.$refs.selectTeamUser.selectNums = 0;
  179. this.$refs.selectTeamUser.selectAll = false;
  180. },
  181. reviewPdf(item){
  182. let url = `/pagesHome/pdf?reportId=${item.reportId}`;
  183. if(item.type==2) url = `/pagesHome/pdfZyb?reportId=${item.reportId}`
  184. uni.navigateTo({ url })
  185. },
  186. reviewReport(item){
  187. const { isPC, isMobile, platform } = getPlatformInfo();
  188. console.log(platform,'platform');//android
  189. if (isPC) {
  190. this.$showModal('请在手机端该微信小程序中查看报告')
  191. } else if (isMobile||platform==='devtools') {
  192. if(!item.fileUrl) return this.$showToast('报告pdf为空,请稍后再试。')
  193. this.openPdf(item.fileUrl)
  194. // uni.navigateTo({
  195. // url:'/pages/webView?src='+item.fileUrl
  196. // })
  197. }
  198. },
  199. async openPdf(pdfUrl) {
  200. try {
  201. // 1. 显示加载提示
  202. uni.showLoading({ title: '加载中...' });
  203. // 2. 先下载PDF文件到本地(解决安卓直接预览网络文件慢的问题)
  204. const downloadRes = await uni.downloadFile({
  205. url: pdfUrl,
  206. // 可选:设置超时时间,避免长时间等待
  207. timeout: 30000
  208. });
  209. const dres = downloadRes[1]||null;
  210. if (dres.statusCode !== 200) {
  211. uni.hideLoading();
  212. uni.showToast({ title: '文件下载失败', icon: 'none' });
  213. return;
  214. }
  215. // 3. 用微信原生API打开本地PDF
  216. const openRes = await uni.openDocument({
  217. filePath: dres.tempFilePath,
  218. fileType: 'pdf',
  219. showMenu: true // 允许用户转发/保存等
  220. });
  221. uni.hideLoading();
  222. } catch (error) {
  223. uni.hideLoading();
  224. uni.showToast({ title: '加载失败,请重试', icon: 'none' });
  225. }
  226. },
  227. askReport(item){
  228. uni.navigateTo({
  229. url:`/pages/reportAsk?pdfUrl=${item.fileUrl}&fileName=${this.typeCfg[item.type]||'个人版'}-${item.reportName}`
  230. })
  231. },
  232. async sendReport(item){
  233. if(!item.fileUrl) return this.$showModal('该报告尚未生成PDF文件,请等待生成后发送。')
  234. this.sendType = 2;
  235. this.$refs.selectTeamUser.title = '发送报告'
  236. this.selectItem = item;
  237. await this.getUserCategoryData()
  238. this.$api.get(`/core/member/listByQueTeamId/${item.teamQueId}`).then(({data:res})=>{
  239. if(res.code!==0) return this.$showToast(res.msg)
  240. this.teamUserList = res.data;
  241. this.teamUserList.forEach((l,i)=>{
  242. l.categoryName = this.categoryData.find(c=>c.id==l.category)?.name;
  243. this.$set(this.teamUserList[i],'select',false);
  244. })
  245. this.teamUserShow = true;
  246. })
  247. },
  248. reSendReport(item){
  249. this.$api.get(`/core/report/regenerateReport/${item.reportId}`).then(({data:res})=>{
  250. if(res.code!==0) return this.$showToast(res.msg)
  251. this.$emit('reSendReport')
  252. })
  253. }
  254. }
  255. }
  256. </script>
  257. <style scoped lang="scss">
  258. .gbox{
  259. height: 100%;
  260. &-item{
  261. margin-top: 20rpx;
  262. background: #FFFFFF;
  263. border-radius: 24rpx;
  264. padding: 40rpx 20rpx 20rpx;
  265. &-top{
  266. &-type{
  267. width: 98rpx;
  268. height: 36rpx;
  269. padding: 2rpx 13rpx;
  270. box-sizing: border-box;
  271. background: #FFF7DC;
  272. border-radius: 6rpx;
  273. font-family: PingFangSC, PingFang SC;
  274. font-weight: 400;
  275. font-size: 24rpx;
  276. color: #BA9B31;
  277. line-height: 33rpx;
  278. }
  279. &-title{
  280. width: calc(100% - 98rpx);
  281. font-family: PingFang-SC, PingFang-SC;
  282. font-weight: bold;
  283. font-size: 32rpx;
  284. color: #002846;
  285. line-height: 32rpx;
  286. text-indent: 17rpx;
  287. }
  288. }
  289. &-ps{
  290. margin-top: 20rpx;
  291. background: #F5F8FA;
  292. border-radius: 5px;
  293. padding: 20rpx 20rpx 30rpx;
  294. position: relative;
  295. }
  296. &-p{
  297. margin-top: 32rpx;
  298. &:first-child{
  299. margin-top: 0;
  300. }
  301. &>view{
  302. font-family: PingFangSC, PingFang SC;
  303. font-weight: 400;
  304. font-size: 24rpx;
  305. color: #667E90;
  306. line-height: 24rpx;
  307. }
  308. &-left{
  309. width: 134rpx;
  310. }
  311. &-right{
  312. width: calc(100% - 134rpx);
  313. }
  314. &-progress{
  315. width: calc(100% - 134rpx);
  316. &-l{
  317. width: 410rpx;
  318. height: 12rpx;
  319. background: #F0F2F8;
  320. border-radius: 6rpx;
  321. position: relative;
  322. &-current{
  323. height: 12rpx;
  324. background: #FFDF73;
  325. border-radius: 6rpx;
  326. position: absolute;
  327. left: 0;
  328. top: 0;
  329. }
  330. }
  331. &-r{
  332. width: calc(100% - 410rpx);
  333. font-family: PingFangSC, PingFang SC;
  334. font-weight: 400;
  335. font-size: 24rpx;
  336. color: #002846;
  337. line-height: 24rpx;
  338. text-align: right;
  339. }
  340. }
  341. }
  342. &-ask{
  343. width: 64rpx;
  344. height: 64rpx;
  345. position: absolute;
  346. right: 20rpx;
  347. bottom: 42rpx;
  348. }
  349. &-bottom{
  350. margin-top: 20rpx;
  351. overflow: hidden;
  352. &-rightbox{
  353. flex: 1;
  354. margin-left: -35rpx;
  355. justify-content: flex-end;
  356. }
  357. &-left{
  358. &>view{
  359. font-family: PingFangSC, PingFang SC;
  360. font-weight: 400;
  361. font-size: 24rpx;
  362. color: #667E90;
  363. line-height: 24rpx;
  364. }
  365. }
  366. &-right{
  367. width: calc(25% - 35rpx);
  368. padding: 15rpx;
  369. text-align: center;
  370. box-sizing: border-box;
  371. background: linear-gradient( 90deg, #33A7A7 0%, #4DB2B2 100%);
  372. border-radius: 20rpx;
  373. font-family: PingFang-SC, PingFang-SC;
  374. font-size: 24rpx;
  375. color: #FFFFFF;
  376. margin-left: 35rpx;
  377. }
  378. }
  379. }
  380. }
  381. </style>