list.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <a-card size="small" :bordered="false" class="intelligentReplenishmentList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 操作按钮 -->
  5. <div ref="tableSearch" class="table-operator">
  6. <a-button v-if="$hasPermissions('B_intelligentReplenishment_add')" id="intelligentReplenishmentList-add" type="primary" class="button-error" @click="handleEdit()">新增</a-button>
  7. <a-button v-if="$hasPermissions('B_intelligentReplenishment_set')" id="intelligentReplenishmentList-set" type="primary" class="button-warning" @click="handleSet">基础信息设置</a-button>
  8. </div>
  9. <a-alert type="info" style="margin-bottom:10px">
  10. <div slot="message">为保证系统性能,仅保留最近10次的预测结果</div>
  11. </a-alert>
  12. <!-- 列表 -->
  13. <s-table
  14. class="sTable fixPagination"
  15. ref="table"
  16. :style="{ height: tableHeight+84.5+'px' }"
  17. size="small"
  18. :rowKey="(record) => record.id"
  19. :columns="columns"
  20. :data="loadData"
  21. :scroll="{ y: tableHeight }"
  22. :showPagination="false"
  23. :defaultLoadData="false"
  24. bordered>
  25. <!-- 操作 -->
  26. <template slot="action" slot-scope="text, record">
  27. <a-button
  28. size="small"
  29. type="link"
  30. class="button-info"
  31. v-if="record.state == 'WAIT' && $hasPermissions('B_intelligentReplenishment_edit')"
  32. @click="handleEdit(record)"
  33. id="intelligentReplenishmentList-edit-btn">编辑</a-button>
  34. <a-button
  35. size="small"
  36. type="link"
  37. class="button-error"
  38. v-if="record.state == 'WAIT' && $hasPermissions('B_intelligentReplenishment_del')"
  39. @click="handleDel(record)"
  40. id="intelligentReplenishmentList-del-btn">删除</a-button>
  41. <a-button
  42. size="small"
  43. type="link"
  44. class="button-success"
  45. v-if="record.state != 'WAIT' && $hasPermissions('B_intelligentReplenishment_detail')"
  46. @click="handleDetail(record)"
  47. id="customerManagementList-detail-btn">详情</a-button>
  48. <a-button
  49. size="small"
  50. type="link"
  51. class="button-warning"
  52. v-if="record.state == 'FINISH' && $hasPermissions('B_intelligentReplenishment_down')"
  53. @click="handleDownload(record)"
  54. id="chainTransferInList-download-btn">结果下载</a-button>
  55. <span v-if="!(record.state == 'WAIT' && $hasPermissions('B_intelligentReplenishment_edit'))&&!(record.state == 'WAIT' && $hasPermissions('B_intelligentReplenishment_del'))&&!(record.state != 'WAIT' && $hasPermissions('B_intelligentReplenishment_detail'))&&!(record.state == 'FINISH' && $hasPermissions('B_intelligentReplenishment_down'))">--</span>
  56. </template>
  57. </s-table>
  58. </a-spin>
  59. <!-- 详情 -->
  60. <intelligent-replenishment-detail-modal :openModal="openDetailModal" :itemSn="itemSn" @close="closeModal" />
  61. </a-card>
  62. </template>
  63. <script>
  64. import moment from 'moment'
  65. import { STable, VSelect } from '@/components'
  66. import intelligentReplenishmentDetailModal from './detailModal.vue'
  67. import { predictList, predictSave, predictDel, predictstockPredictExport } from '@/api/predict'
  68. export default {
  69. components: { STable, VSelect, intelligentReplenishmentDetailModal },
  70. data () {
  71. return {
  72. spinning: false,
  73. tableHeight: 0,
  74. columns: [
  75. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  76. { title: '创建时间', dataIndex: 'createDate', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  77. { title: '创建人', dataIndex: 'creatorName', width: '45%', align: 'center', customRender: function (text) { return text || '--' } },
  78. { title: '状态', dataIndex: 'stateDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  79. { title: '操作', scopedSlots: { customRender: 'action' }, width: '20%', align: 'center' }
  80. ],
  81. // 加载数据方法 必须为 Promise 对象
  82. loadData: parameter => {
  83. this.spinning = true
  84. return predictList({}).then(res => {
  85. let data
  86. if (res.status == 200) {
  87. data = res.data
  88. for (var i = 0; i < data.length; i++) {
  89. data[i].no = i + 1
  90. }
  91. }
  92. this.spinning = false
  93. return data
  94. })
  95. },
  96. itemSn: '', // 当前sn
  97. openDetailModal: false
  98. }
  99. },
  100. methods: {
  101. // 新增/编辑
  102. handleEdit (row) {
  103. if (row) { // 编辑
  104. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/edit/${row.stockPredictSn}` })
  105. } else { // 新增
  106. this.spinning = true
  107. predictSave({}).then(res => {
  108. this.spinning = false
  109. if (res.status == 200) {
  110. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/add/${res.data.stockPredictSn}` })
  111. }
  112. })
  113. }
  114. },
  115. // 详情
  116. handleDetail (row) {
  117. this.itemSn = row ? row.stockPredictSn : null
  118. this.openDetailModal = true
  119. },
  120. // 设置
  121. handleSet () {
  122. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/set` })
  123. },
  124. // 删除
  125. handleDel (row) {
  126. const _this = this
  127. this.$confirm({
  128. title: '提示',
  129. content: '删除后不可恢复,确定要进行删除吗?',
  130. centered: true,
  131. onOk () {
  132. _this.spinning = true
  133. predictDel({ sn: row.stockPredictSn }).then(res => {
  134. if (res.status == 200) {
  135. _this.$message.success(res.message)
  136. _this.$refs.table.refresh()
  137. _this.spinning = false
  138. } else {
  139. _this.spinning = false
  140. }
  141. })
  142. }
  143. })
  144. },
  145. // 关闭弹框
  146. closeModal () {
  147. this.itemSn = ''
  148. this.openDetailModal = false
  149. this.$refs.table.refresh(true)
  150. },
  151. // 结果下载
  152. handleDownload (row) {
  153. const _this = this
  154. _this.spinning = true
  155. predictstockPredictExport({ sn: row.stockPredictSn }).then(res => {
  156. _this.spinning = false
  157. if (res.type == 'application/json') {
  158. var reader = new FileReader()
  159. reader.addEventListener('loadend', function () {
  160. const obj = JSON.parse(reader.result)
  161. _this.$notification.error({
  162. message: '提示',
  163. description: obj.message
  164. })
  165. })
  166. reader.readAsText(res)
  167. } else {
  168. this.download(res)
  169. }
  170. })
  171. },
  172. download (data) {
  173. if (!data) { return }
  174. const url = window.URL.createObjectURL(new Blob([data]))
  175. const link = document.createElement('a')
  176. link.style.display = 'none'
  177. link.href = url
  178. const a = moment().format('YYYYMMDDHHmmss')
  179. const fname = '智能补货' + a
  180. link.setAttribute('download', fname + '.xlsx')
  181. document.body.appendChild(link)
  182. link.click()
  183. },
  184. pageInit () {
  185. const _this = this
  186. this.$nextTick(() => { // 页面渲染完成后的回调
  187. _this.setTableH()
  188. })
  189. },
  190. setTableH () {
  191. const tableSearchH = this.$refs.tableSearch.offsetHeight
  192. this.tableHeight = window.innerHeight - tableSearchH - 230
  193. }
  194. },
  195. watch: {
  196. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  197. this.setTableH()
  198. }
  199. },
  200. mounted () {
  201. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  202. this.pageInit()
  203. this.$refs.table.refresh(true)
  204. }
  205. },
  206. activated () {
  207. // 如果是新页签打开,则重置当前页面
  208. if (this.$store.state.app.isNewTab) {
  209. this.pageInit()
  210. this.$refs.table.refresh(true)
  211. }
  212. // 仅刷新列表,不重置页面
  213. if (this.$store.state.app.updateList) {
  214. this.pageInit()
  215. this.$refs.table.refresh()
  216. }
  217. },
  218. beforeRouteEnter (to, from, next) {
  219. next(vm => {})
  220. }
  221. }
  222. </script>