list.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. bordered>
  24. <!-- 操作 -->
  25. <template slot="action" slot-scope="text, record">
  26. <a-button
  27. size="small"
  28. type="link"
  29. class="button-info"
  30. v-if="record.state == 'WAIT' && $hasPermissions('B_intelligentReplenishment_edit')"
  31. @click="handleEdit(record)"
  32. id="intelligentReplenishmentList-edit-btn">编辑</a-button>
  33. <a-button
  34. size="small"
  35. type="link"
  36. class="button-error"
  37. v-if="record.state == 'WAIT' && $hasPermissions('B_intelligentReplenishment_del')"
  38. @click="handleDel(record)"
  39. id="intelligentReplenishmentList-del-btn">删除</a-button>
  40. <a-button
  41. size="small"
  42. type="link"
  43. class="button-success"
  44. v-if="record.state != 'WAIT' && $hasPermissions('B_intelligentReplenishment_detail')"
  45. @click="handleDetail(record)"
  46. id="customerManagementList-detail-btn">详情</a-button>
  47. <a-button
  48. size="small"
  49. type="link"
  50. class="button-warning"
  51. v-if="record.state == 'FINISH' && $hasPermissions('B_intelligentReplenishment_down')"
  52. @click="handleDownload(record)"
  53. id="chainTransferInList-download-btn">结果下载</a-button>
  54. <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>
  55. </template>
  56. </s-table>
  57. </a-spin>
  58. <!-- 详情 -->
  59. <intelligent-replenishment-detail-modal :openModal="openDetailModal" :itemSn="itemSn" @close="closeModal" />
  60. </a-card>
  61. </template>
  62. <script>
  63. import moment from 'moment'
  64. import { STable, VSelect } from '@/components'
  65. import intelligentReplenishmentDetailModal from './detailModal.vue'
  66. import { predictList, predictSave, predictDel, predictstockPredictExport } from '@/api/predict'
  67. export default {
  68. components: { STable, VSelect, intelligentReplenishmentDetailModal },
  69. data () {
  70. return {
  71. spinning: false,
  72. tableHeight: 0,
  73. columns: [
  74. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  75. { title: '创建时间', dataIndex: 'createDate', width: 160, align: 'center', customRender: function (text) { return text || '--' } },
  76. { title: '创建人', dataIndex: 'creatorName', align: 'center', customRender: function (text) { return text || '--' } },
  77. { title: '状态', dataIndex: 'stateDictValue', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  78. { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center' }
  79. ],
  80. // 加载数据方法 必须为 Promise 对象
  81. loadData: parameter => {
  82. this.spinning = true
  83. return predictList({}).then(res => {
  84. const data = res.data
  85. for (var i = 0; i < data.length; i++) {
  86. data[i].no = i + 1
  87. }
  88. this.spinning = false
  89. return data
  90. })
  91. },
  92. itemSn: '', // 当前sn
  93. openDetailModal: false
  94. }
  95. },
  96. methods: {
  97. // 新增/编辑
  98. handleEdit (row) {
  99. if (row) { // 编辑
  100. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/edit/${row.stockPredictSn}` })
  101. } else { // 新增
  102. this.spinning = true
  103. predictSave({}).then(res => {
  104. this.spinning = false
  105. if (res.status == 200) {
  106. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/add/${res.data.stockPredictSn}` })
  107. }
  108. })
  109. }
  110. },
  111. // 详情
  112. handleDetail (row) {
  113. this.itemSn = row ? row.stockPredictSn : null
  114. this.openDetailModal = true
  115. },
  116. // 设置
  117. handleSet () {
  118. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/set` })
  119. },
  120. // 删除
  121. handleDel (row) {
  122. const _this = this
  123. this.$confirm({
  124. title: '提示',
  125. content: '删除后不可恢复,确定要进行删除吗?',
  126. centered: true,
  127. onOk () {
  128. _this.spinning = true
  129. predictDel({ sn: row.stockPredictSn }).then(res => {
  130. if (res.status == 200) {
  131. _this.$message.success(res.message)
  132. _this.$refs.table.refresh()
  133. _this.spinning = false
  134. } else {
  135. _this.spinning = false
  136. }
  137. })
  138. }
  139. })
  140. },
  141. // 关闭弹框
  142. closeModal () {
  143. this.itemSn = ''
  144. this.openDetailModal = false
  145. this.$refs.table.refresh(true)
  146. },
  147. // 结果下载
  148. handleDownload (row) {
  149. const _this = this
  150. _this.spinning = true
  151. predictstockPredictExport({ sn: row.stockPredictSn }).then(res => {
  152. _this.spinning = false
  153. if (res.type == 'application/json') {
  154. var reader = new FileReader()
  155. reader.addEventListener('loadend', function () {
  156. const obj = JSON.parse(reader.result)
  157. _this.$notification.error({
  158. message: '提示',
  159. description: obj.message
  160. })
  161. })
  162. reader.readAsText(res)
  163. } else {
  164. this.download(res)
  165. }
  166. })
  167. },
  168. download (data) {
  169. if (!data) { return }
  170. const url = window.URL.createObjectURL(new Blob([data]))
  171. const link = document.createElement('a')
  172. link.style.display = 'none'
  173. link.href = url
  174. const a = moment().format('YYYYMMDDHHmmss')
  175. const fname = '智能补货' + a
  176. link.setAttribute('download', fname + '.xlsx')
  177. document.body.appendChild(link)
  178. link.click()
  179. },
  180. setTableH () {
  181. const tableSearchH = this.$refs.tableSearch.offsetHeight
  182. this.tableHeight = window.innerHeight - tableSearchH - 230
  183. }
  184. },
  185. mounted () {
  186. const _this = this
  187. this.$nextTick(() => { // 页面渲染完成后的回调
  188. _this.setTableH()
  189. })
  190. },
  191. beforeRouteEnter (to, from, next) {
  192. next(vm => {
  193. vm.$refs.table.refresh()
  194. })
  195. }
  196. }
  197. </script>