list.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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: 80, align: 'center' },
  76. { title: '创建时间', dataIndex: 'createDate', width: 160, align: 'center', customRender: function (text) { return text || '--' } },
  77. { title: '创建人', dataIndex: 'creatorName', align: 'center', customRender: function (text) { return text || '--' } },
  78. { title: '状态', dataIndex: 'stateDictValue', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  79. { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center' }
  80. ],
  81. // 加载数据方法 必须为 Promise 对象
  82. loadData: parameter => {
  83. this.spinning = true
  84. return predictList({}).then(res => {
  85. const data = res.data
  86. for (var i = 0; i < data.length; i++) {
  87. data[i].no = i + 1
  88. }
  89. this.spinning = false
  90. return data
  91. })
  92. },
  93. itemSn: '', // 当前sn
  94. openDetailModal: false
  95. }
  96. },
  97. methods: {
  98. // 新增/编辑
  99. handleEdit (row) {
  100. if (row) { // 编辑
  101. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/edit/${row.stockPredictSn}` })
  102. } else { // 新增
  103. this.spinning = true
  104. predictSave({}).then(res => {
  105. this.spinning = false
  106. if (res.status == 200) {
  107. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/add/${res.data.stockPredictSn}` })
  108. }
  109. })
  110. }
  111. },
  112. // 详情
  113. handleDetail (row) {
  114. this.itemSn = row ? row.stockPredictSn : null
  115. this.openDetailModal = true
  116. },
  117. // 设置
  118. handleSet () {
  119. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/set` })
  120. },
  121. // 删除
  122. handleDel (row) {
  123. const _this = this
  124. this.$confirm({
  125. title: '提示',
  126. content: '删除后不可恢复,确定要进行删除吗?',
  127. centered: true,
  128. onOk () {
  129. _this.spinning = true
  130. predictDel({ sn: row.stockPredictSn }).then(res => {
  131. if (res.status == 200) {
  132. _this.$message.success(res.message)
  133. _this.$refs.table.refresh()
  134. _this.spinning = false
  135. } else {
  136. _this.spinning = false
  137. }
  138. })
  139. }
  140. })
  141. },
  142. // 关闭弹框
  143. closeModal () {
  144. this.itemSn = ''
  145. this.openDetailModal = false
  146. this.$refs.table.refresh(true)
  147. },
  148. // 结果下载
  149. handleDownload (row) {
  150. const _this = this
  151. _this.spinning = true
  152. predictstockPredictExport({ sn: row.stockPredictSn }).then(res => {
  153. _this.spinning = false
  154. if (res.type == 'application/json') {
  155. var reader = new FileReader()
  156. reader.addEventListener('loadend', function () {
  157. const obj = JSON.parse(reader.result)
  158. _this.$notification.error({
  159. message: '提示',
  160. description: obj.message
  161. })
  162. })
  163. reader.readAsText(res)
  164. } else {
  165. this.download(res)
  166. }
  167. })
  168. },
  169. download (data) {
  170. if (!data) { return }
  171. const url = window.URL.createObjectURL(new Blob([data]))
  172. const link = document.createElement('a')
  173. link.style.display = 'none'
  174. link.href = url
  175. const a = moment().format('YYYYMMDDHHmmss')
  176. const fname = '智能补货' + a
  177. link.setAttribute('download', fname + '.xlsx')
  178. document.body.appendChild(link)
  179. link.click()
  180. },
  181. setTableH () {
  182. const tableSearchH = this.$refs.tableSearch.offsetHeight
  183. this.tableHeight = window.innerHeight - tableSearchH - 230
  184. }
  185. },
  186. mounted () {
  187. const _this = this
  188. this.$nextTick(() => { // 页面渲染完成后的回调
  189. _this.setTableH()
  190. })
  191. },
  192. activated () {
  193. // 如果是新页签打开,则重置当前页面
  194. if (this.$store.state.app.isNewTab) {
  195. this.$refs.table.refresh(true)
  196. }
  197. },
  198. beforeRouteEnter (to, from, next) {
  199. next(vm => {
  200. if (!vm.spinning) {
  201. vm.$refs.table.refresh()
  202. }
  203. })
  204. }
  205. }
  206. </script>