list.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <a-card size="small" :bordered="false" class="supplierInfoList-wrap">
  3. <!-- 搜索条件 -->
  4. <div class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="供应商名称">
  9. <a-input id="supplierInfoList-supplierName" v-model.trim="queryParam.supplierName" allowClear placeholder="请输入供应商名称"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="supplierInfoList-refresh">查询</a-button>
  14. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="supplierInfoList-reset">重置</a-button>
  15. </a-col>
  16. </a-row>
  17. </a-form>
  18. </div>
  19. <!-- 操作按钮 -->
  20. <div class="table-operator">
  21. <a-button id="supplierInfoList-add" type="primary" class="button-error" @click="handleEdit()">新增</a-button>
  22. </div>
  23. <!-- 总计 -->
  24. <a-alert type="info" showIcon style="margin-bottom:15px">
  25. <div slot="message">合计:<strong>{{ total }}</strong>条</div>
  26. </a-alert>
  27. <!-- 列表 -->
  28. <s-table
  29. class="sTable"
  30. ref="table"
  31. size="default"
  32. :rowKey="(record) => record.id"
  33. :columns="columns"
  34. :data="loadData"
  35. bordered>
  36. <!-- 状态 -->
  37. <template slot="enabledFlag" slot-scope="text, record">
  38. <a-switch checkedChildren="启用" unCheckedChildren="禁用" v-model="record.enableFlag" @change="changeFlagHandle(text, record)"/>
  39. </template>
  40. <!-- 操作 -->
  41. <template slot="action" slot-scope="text, record">
  42. <a-button size="small" type="link" class="button-warning" @click="handleRelated(record)" id="supplierInfoList-related-btn">关联产品</a-button>
  43. <a-button size="small" type="link" class="button-info" @click="handleEdit(record)" id="supplierInfoList-edit-btn">编辑</a-button>
  44. </template>
  45. </s-table>
  46. </a-card>
  47. </template>
  48. <script>
  49. import { STable, VSelect } from '@/components'
  50. import { supplierList, updateEnableStatus } from '@/api/supplier'
  51. export default {
  52. components: { STable, VSelect },
  53. data () {
  54. return {
  55. queryParam: { // 查询条件
  56. supplierName: '' // 供应商名称
  57. },
  58. disabled: false, // 查询、重置按钮是否可操作
  59. columns: [
  60. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  61. { title: '创建时间', dataIndex: 'createDate', width: 160, align: 'center', customRender: function (text) { return text || '--' } },
  62. { title: '供应商名称', dataIndex: 'supplierName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  63. { title: '联系人', dataIndex: 'contact', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  64. { title: '产品款数', dataIndex: 'totalProductCategory', align: 'center', customRender: function (text) { return text || '--' } },
  65. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: 150, align: 'center', fixed: 'right' },
  66. { title: '操作', scopedSlots: { customRender: 'action' }, width: 150, align: 'center', fixed: 'right' }
  67. ],
  68. total: 0,
  69. // 加载数据方法 必须为 Promise 对象
  70. loadData: parameter => {
  71. this.disabled = true
  72. return supplierList(Object.assign(parameter, this.queryParam)).then(res => {
  73. const data = res.data
  74. this.total = data.count
  75. const no = (data.pageNo - 1) * data.pageSize
  76. for (var i = 0; i < data.list.length; i++) {
  77. data.list[i].no = no + i + 1
  78. data.list[i].enableFlag = data.list[i].enableFlag + '' === '1'
  79. }
  80. this.disabled = false
  81. return data
  82. })
  83. }
  84. }
  85. },
  86. methods: {
  87. // 重置
  88. resetSearchForm () {
  89. this.queryParam.supplierName = ''
  90. this.$refs.table.refresh(true)
  91. },
  92. // 新增/编辑
  93. handleEdit (row) {
  94. if (row) { // 编辑
  95. this.$router.push({ name: `supplierInfoEdit`, params: { id: row.id } })
  96. } else { // 新增
  97. this.$router.push({ name: 'supplierInfoAdd' })
  98. }
  99. },
  100. // 关联产品
  101. handleRelated (row) {
  102. this.$router.push({ name: 'associatedProduct', params: { sn: row.supplierSn, name: encodeURI(row.supplierName) } })
  103. },
  104. // 修改状态
  105. changeFlagHandle (text, record) {
  106. const _data = {
  107. sn: record.supplierSn,
  108. flag: record.enableFlag ? '1' : '0'
  109. }
  110. updateEnableStatus(_data).then(res => {
  111. if (res.status + '' === '200') {
  112. this.$message.success(res.message)
  113. } else {
  114. record.enableFlag = !record.enableFlag
  115. }
  116. })
  117. }
  118. }
  119. }
  120. </script>