grainInfo.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="content">
  3. <u-popup :show="messageShow" mode="top" @close="messageShow = false">
  4. <view class="msg">
  5. <text>{{message}}</text>
  6. </view>
  7. </u-popup>
  8. <view class="search-bar">
  9. <u--form :model="searchForm" ref="searchForm">
  10. <u-form-item label="仓房名称:" prop="storehouseName" label-width="80px">
  11. <u--input v-model="searchForm.storehouseName"></u--input>
  12. <u-button type="primary" text="查询" class="btn" @tap="search"></u-button>
  13. <u-button text="重置" class="btn" @tap="reset"></u-button>
  14. </u-form-item>
  15. </u--form>
  16. <view class="exports">
  17. <u-button type="success" text="导出报表" class="btn" @tap="exportTable"></u-button>
  18. <view class="tip">温馨提示:仅可导出近30天内的数据。</view>
  19. </view>
  20. </view>
  21. <uni-table border stripe emptyText="暂无更多数据" :loading="this.loading">
  22. <!-- 表头行 -->
  23. <uni-tr>
  24. <uni-th align="center">序号</uni-th>
  25. <uni-th align="center">库区名称</uni-th>
  26. <uni-th align="center">仓房名称</uni-th>
  27. <uni-th align="center">仓温</uni-th>
  28. <uni-th align="center">最高粮温(℃)</uni-th>
  29. <uni-th align="center">最低粮温(℃)</uni-th>
  30. <uni-th align="center">平均粮温(℃)</uni-th>
  31. <uni-th align="center">同上次相比平均粮温</uni-th>
  32. <uni-th align="center">采集时间</uni-th>
  33. </uni-tr>
  34. <!-- 表格数据行 -->
  35. <uni-tr v-for="(item, index) in tableData" :key="item.id">
  36. <uni-td align="center">{{ index + 1 }}</uni-td>
  37. <uni-td align="center">{{ item.orgName }}</uni-td>
  38. <uni-td align="center">{{ item.storehouseName }}</uni-td>
  39. <uni-td align="center">{{ item.inTemp }}</uni-td>
  40. <uni-td align="center">{{ item.tempMax }}</uni-td>
  41. <uni-td align="center">{{ item.tempMin }}</uni-td>
  42. <uni-td align="center">{{ item.tempAvg }}</uni-td>
  43. <uni-td align="center" v-html="compareText(item)"></uni-td>
  44. <uni-td align="center">{{ item.gatherTime }}</uni-td>
  45. </uni-tr>
  46. </uni-table>
  47. <uni-pagination show-icon="true" :total="pageInfo.total" :current="pageInfo.current" class="pagination" @change="paginationChang"></uni-pagination>
  48. </view>
  49. </template>
  50. <script>
  51. import simpleList from '@/components/simple-list/index'
  52. import { getList, exportData } from '@/api/grainInfo'
  53. import { server_host } from '@/config/system'
  54. import { errorMsg } from '@/utils/tools'
  55. export default {
  56. mixins: [simpleList],
  57. data() {
  58. return {
  59. searchForm: {
  60. storehouseName: null,
  61. },
  62. messageShow: false,
  63. message: null,
  64. }
  65. },
  66. methods: {
  67. getListFun() {
  68. return getList
  69. },
  70. compareText(item) {
  71. const code = item.compareLastTempAvg
  72. switch(code + '') {
  73. case '2': return '<span class="compare-text" style="color: blue;"> ↑上升 </span>'
  74. case '3': return '<span class="compare-text" style="color: red;"> ↓下降 </span>'
  75. default: return '<span class="compare-text"> - </span>'
  76. }
  77. },
  78. exportTable() {
  79. uni.downloadFile({
  80. url: `${server_host}/statisticalReport.info/grainTemp/exportExcel`,
  81. header: {
  82. token: getApp().globalData.token
  83. },
  84. success: (res) => {
  85. if (res.statusCode === 200) {
  86. console.log('下载成功', res.tempFilePath);
  87. uni.saveFile({
  88. tempFilePath: res.tempFilePath,
  89. success: (ss) => {
  90. console.log('save finish', ss);
  91. uni.openDocument({
  92. filePath: ss.savedFilePath,
  93. showMenu: true,
  94. success: (or) => {
  95. console.log('open document success', or);
  96. },
  97. fail: (err) => {
  98. console.log('open doc fail', err);
  99. this.message = `导出成功到 ${ss.savedFilePath}`
  100. this.messageShow = true
  101. setTimeout(() => {
  102. this.messageShow = false
  103. }, 5_000)
  104. }
  105. })
  106. }
  107. })
  108. }else {
  109. errorMsg('导出失败 - 01')
  110. }
  111. },
  112. fail: (err) => {
  113. errorMsg('导出失败')
  114. }
  115. })
  116. }
  117. }
  118. }
  119. </script>
  120. <style scoped lang="scss">
  121. .content {
  122. padding: 10px;
  123. .btn {
  124. width: 100px;
  125. margin-left: 5px;
  126. }
  127. .tip {
  128. color: red;
  129. }
  130. .exports {
  131. margin-bottom: 10px;
  132. }
  133. }
  134. .msg {
  135. padding-left: 10px;
  136. }
  137. .search-bar {
  138. }
  139. </style>