list.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <a-card size="small" :bordered="false" class="supplierInfoList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="供应商名称">
  10. <a-input id="supplierInfoList-supplierName" v-model.trim="queryParam.supplierName" allowClear placeholder="请输入供应商名称"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="supplierInfoList-refresh">查询</a-button>
  15. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="supplierInfoList-reset">重置</a-button>
  16. </a-col>
  17. </a-row>
  18. </a-form>
  19. </div>
  20. <!-- 操作按钮 -->
  21. <div class="table-operator">
  22. <a-button id="supplierInfoList-add" type="primary" v-if="$hasPermissions('B_supplierInfo_add')" class="button-error" @click="handleEdit()">新增</a-button>
  23. </div>
  24. <!-- 列表 -->
  25. <s-table
  26. class="sTable fixPagination"
  27. ref="table"
  28. :style="{ height: tableHeight+84.5+'px' }"
  29. size="small"
  30. :rowKey="(record) => record.id"
  31. :columns="columns"
  32. :data="loadData"
  33. :scroll="{ y: tableHeight }"
  34. bordered>
  35. <!-- 状态 -->
  36. <template slot="enabledFlag" slot-scope="text, record">
  37. <a-switch v-if="$hasPermissions('B_supplierInfo_enabled')" checkedChildren="启用" unCheckedChildren="禁用" v-model="record.enableFlag" @change="changeFlagHandle(text, record)"/>
  38. <span v-else :style="{color:(record.enableFlag==1?'#00aa00':'#999')}"> {{ record.enableFlag==1? '已启用': '已禁用' }} </span>
  39. </template>
  40. <!-- 操作 -->
  41. <template slot="action" slot-scope="text, record">
  42. <a-button
  43. size="small"
  44. type="link"
  45. v-if="$hasPermissions('B_supplierInfo_relation')"
  46. class="button-warning"
  47. @click="handleRelated(record)"
  48. id="supplierInfoList-related-btn">关联产品</a-button>
  49. <a-button
  50. size="small"
  51. type="link"
  52. v-if="$hasPermissions('B_supplierInfo_edit')"
  53. class="button-info"
  54. @click="handleEdit(record)"
  55. id="supplierInfoList-edit-btn">编辑</a-button>
  56. <span v-if="!$hasPermissions('B_supplierInfo_relation') && !$hasPermissions('B_supplierInfo_edit')">--</span>
  57. </template>
  58. </s-table>
  59. </a-spin>
  60. </a-card>
  61. </template>
  62. <script>
  63. import { STable, VSelect } from '@/components'
  64. import { supplierList, updateEnableStatus } from '@/api/supplier'
  65. export default {
  66. components: { STable, VSelect },
  67. data () {
  68. return {
  69. spinning: false,
  70. tableHeight: 0,
  71. queryParam: { // 查询条件
  72. supplierName: '' // 供应商名称
  73. },
  74. disabled: false, // 查询、重置按钮是否可操作
  75. columns: [
  76. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  77. { title: '创建时间', dataIndex: 'createDate', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  78. { title: '供应商名称', dataIndex: 'supplierName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  79. { title: '联系人', dataIndex: 'contact', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  80. { title: '产品款数', dataIndex: 'totalProductCategory', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  81. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: 100, align: 'center' },
  82. { title: '操作', scopedSlots: { customRender: 'action' }, width: 150, align: 'center' }
  83. ],
  84. total: 0,
  85. // 加载数据方法 必须为 Promise 对象
  86. loadData: parameter => {
  87. this.disabled = true
  88. this.spinning = true
  89. return supplierList(Object.assign(parameter, this.queryParam)).then(res => {
  90. const data = res.data
  91. this.total = data.count || 0
  92. const no = (data.pageNo - 1) * data.pageSize
  93. for (var i = 0; i < data.list.length; i++) {
  94. data.list[i].no = no + i + 1
  95. data.list[i].enableFlag = data.list[i].enableFlag + '' === '1'
  96. }
  97. this.disabled = false
  98. this.spinning = false
  99. return data
  100. })
  101. }
  102. }
  103. },
  104. methods: {
  105. // 重置
  106. resetSearchForm () {
  107. this.queryParam.supplierName = ''
  108. this.$refs.table.refresh(true)
  109. },
  110. // 新增/编辑
  111. handleEdit (row) {
  112. if (row) { // 编辑
  113. this.$router.push({ name: `supplierInfoEdit`, params: { id: row.supplierSn } })
  114. } else { // 新增
  115. this.$router.push({ name: 'supplierInfoAdd' })
  116. }
  117. },
  118. // 关联产品
  119. handleRelated (row) {
  120. this.$router.push({ name: 'associatedProduct', params: { sn: row.supplierSn, name: encodeURI(row.supplierName) } })
  121. },
  122. // 修改状态
  123. changeFlagHandle (text, record) {
  124. const _data = {
  125. sn: record.supplierSn,
  126. flag: record.enableFlag ? '1' : '0'
  127. }
  128. this.spinning = true
  129. updateEnableStatus(_data).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.$refs.table.refresh()
  136. this.spinning = false
  137. }
  138. })
  139. },
  140. setTableH () {
  141. const tableSearchH = this.$refs.tableSearch.offsetHeight
  142. this.tableHeight = window.innerHeight - tableSearchH - 235
  143. }
  144. },
  145. mounted () {
  146. const _this = this
  147. this.$nextTick(() => { // 页面渲染完成后的回调
  148. _this.setTableH()
  149. })
  150. },
  151. beforeRouteEnter (to, from, next) {
  152. next(vm => {
  153. vm.$refs.table.refresh()
  154. })
  155. }
  156. }
  157. </script>