modal.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div>
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 列表 -->
  5. <s-table
  6. class="sTable fixPagination"
  7. ref="table"
  8. size="small"
  9. :rowKey="(record) => record.id"
  10. :columns="columns"
  11. :scroll="{ y: 400 }"
  12. :data="loadData"
  13. :defaultLoadData="false"
  14. :showPagination="false"
  15. bordered>
  16. </s-table>
  17. <div style="padding-top: 15px;">
  18. <a-button id="newProduct-modal-btn" @click="viewMore" block type="primary" ghost>查看更多{{ onlineFalg==1?'新品':'下线产品' }}</a-button>
  19. </div>
  20. </a-spin>
  21. </div>
  22. </template>
  23. <script>
  24. import { commonMixin } from '@/utils/mixin'
  25. // 组件
  26. import { STable } from '@/components'
  27. // 接口
  28. import { queryNewProductPage } from '@/api/product'
  29. export default {
  30. name: 'NewProductListModal',
  31. mixins: [commonMixin],
  32. components: { STable },
  33. props: {
  34. onlineFalg: { // 上下线标识 1为上线,0为下线
  35. type: [ String, Number ],
  36. default: '1'
  37. }
  38. },
  39. data () {
  40. return {
  41. spinning: false,
  42. queryParam: {}, // 查询参数
  43. // 加载数据方法 必须为 Promise 对象
  44. loadData: parameter => {
  45. this.spinning = true
  46. // 获取表格数据 无分页
  47. return queryNewProductPage(Object.assign(parameter, this.queryParam, { onlineFalg: this.onlineFalg })).then(res => {
  48. let data
  49. if (res.status == 200) {
  50. data = res.data
  51. // 计算表格序号
  52. const no = (data.pageNo - 1) * data.pageSize
  53. for (var i = 0; i < data.list.length; i++) {
  54. data.list[i].no = no + i + 1
  55. }
  56. }
  57. this.spinning = false
  58. return data
  59. })
  60. }
  61. }
  62. },
  63. computed: {
  64. columns () {
  65. const arr = [
  66. { title: '序号', dataIndex: 'no', width: 50, align: 'center' },
  67. { title: '产品品牌', dataIndex: 'productBrandName', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  68. { title: '产品编码', dataIndex: 'code', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  69. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  70. { title: '单位', dataIndex: 'unit', width: 60, align: 'center', customRender: function (text) { return text || '--' } }
  71. ]
  72. if (this.onlineFalg == '1') {
  73. arr.push({ title: '上线时间', dataIndex: 'auditTime', width: 140, align: 'center', customRender: function (text) { return text || '--' } })
  74. } else if (this.onlineFalg == '0') {
  75. arr.push({ title: '下线时间', dataIndex: 'auditTime', width: 140, align: 'center', customRender: function (text) { return text || '--' } })
  76. }
  77. return arr
  78. }
  79. },
  80. methods: {
  81. // 查看更多
  82. viewMore () {
  83. this.$emit('seeMore')
  84. }
  85. },
  86. mounted () {
  87. this.$nextTick(() => {
  88. this.$refs.table.refresh(true)
  89. })
  90. },
  91. watch: {
  92. onlineFalg (newValue, oldValue) {
  93. const _this = this
  94. setTimeout(() => {
  95. _this.$refs.table && _this.$refs.table.refresh(true)
  96. }, 400)
  97. }
  98. }
  99. }
  100. </script>