list.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. :defaultLoadData="false"
  35. bordered>
  36. <!-- 状态 -->
  37. <template slot="enabledFlag" slot-scope="text, record">
  38. <a-switch v-if="$hasPermissions('B_supplierInfo_enabled')" checkedChildren="启用" unCheckedChildren="禁用" v-model="record.enableFlag" @change="changeFlagHandle(text, record)"/>
  39. <span v-else :style="{color:(record.enableFlag==1?'#00aa00':'#999')}"> {{ record.enableFlag==1? '已启用': '已禁用' }} </span>
  40. </template>
  41. <!-- 操作 -->
  42. <template slot="action" slot-scope="text, record">
  43. <a-button
  44. size="small"
  45. type="link"
  46. v-if="$hasPermissions('B_supplierInfo_relation')"
  47. class="button-warning"
  48. @click="handleRelated(record)"
  49. id="supplierInfoList-related-btn">关联产品</a-button>
  50. <a-button
  51. size="small"
  52. type="link"
  53. v-if="$hasPermissions('B_supplierInfo_edit')"
  54. class="button-info"
  55. @click="handleEdit(record)"
  56. id="supplierInfoList-edit-btn">编辑</a-button>
  57. <span v-if="!$hasPermissions('B_supplierInfo_relation') && !$hasPermissions('B_supplierInfo_edit')">--</span>
  58. </template>
  59. </s-table>
  60. </a-spin>
  61. </a-card>
  62. </template>
  63. <script>
  64. import { STable, VSelect } from '@/components'
  65. import { supplierList, updateEnableStatus } from '@/api/supplier'
  66. export default {
  67. components: { STable, VSelect },
  68. data () {
  69. return {
  70. spinning: false,
  71. tableHeight: 0,
  72. queryParam: { // 查询条件
  73. supplierName: '' // 供应商名称
  74. },
  75. disabled: false, // 查询、重置按钮是否可操作
  76. columns: [
  77. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  78. { title: '创建时间', dataIndex: 'createDate', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  79. { title: '供应商名称', dataIndex: 'supplierName', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  80. { title: '联系人', dataIndex: 'contact', align: 'center', width: '18%', ellipsis: true, customRender: function (text) { return text || '--' } },
  81. { title: '产品款数', dataIndex: 'totalProductCategory', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  82. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: '10%', align: 'center' },
  83. { title: '操作', scopedSlots: { customRender: 'action' }, width: '15%', align: 'center' }
  84. ],
  85. total: 0,
  86. // 加载数据方法 必须为 Promise 对象
  87. loadData: parameter => {
  88. this.disabled = true
  89. this.spinning = true
  90. return supplierList(Object.assign(parameter, this.queryParam)).then(res => {
  91. const data = res.data
  92. this.total = data.count || 0
  93. const no = (data.pageNo - 1) * data.pageSize
  94. for (var i = 0; i < data.list.length; i++) {
  95. data.list[i].no = no + i + 1
  96. data.list[i].enableFlag = data.list[i].enableFlag + '' === '1'
  97. }
  98. this.disabled = false
  99. this.spinning = false
  100. return data
  101. })
  102. }
  103. }
  104. },
  105. methods: {
  106. // 重置
  107. resetSearchForm () {
  108. this.queryParam.supplierName = ''
  109. this.$refs.table.refresh(true)
  110. },
  111. // 新增/编辑
  112. handleEdit (row) {
  113. if (row) { // 编辑
  114. this.$router.push({ name: `supplierInfoEdit`, params: { id: row.supplierSn } })
  115. } else { // 新增
  116. this.$router.push({ name: 'supplierInfoAdd' })
  117. }
  118. },
  119. // 关联产品
  120. handleRelated (row) {
  121. this.$router.push({ name: 'associatedProduct', params: { sn: row.supplierSn, name: encodeURI(row.supplierName) } })
  122. },
  123. // 修改状态
  124. changeFlagHandle (text, record) {
  125. const _data = {
  126. sn: record.supplierSn,
  127. flag: record.enableFlag ? '1' : '0'
  128. }
  129. this.spinning = true
  130. updateEnableStatus(_data).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.$refs.table.refresh()
  137. this.spinning = false
  138. }
  139. })
  140. },
  141. pageInit () {
  142. const _this = this
  143. this.$nextTick(() => { // 页面渲染完成后的回调
  144. _this.setTableH()
  145. })
  146. },
  147. setTableH () {
  148. const tableSearchH = this.$refs.tableSearch.offsetHeight
  149. this.tableHeight = window.innerHeight - tableSearchH - 235
  150. }
  151. },
  152. mounted () {
  153. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  154. this.pageInit()
  155. this.resetSearchForm()
  156. }
  157. },
  158. activated () {
  159. // 如果是新页签打开,则重置当前页面
  160. if (this.$store.state.app.isNewTab) {
  161. this.pageInit()
  162. this.resetSearchForm()
  163. }
  164. },
  165. beforeRouteEnter (to, from, next) {
  166. next(vm => {})
  167. }
  168. }
  169. </script>