index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <a-card :bordered="false" style="margin-bottom: 10px" class="mb-2">
  3. <a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
  4. <a-row :gutter="24">
  5. <a-col :span="6">
  6. <a-form-item label="客户名称" name="name">
  7. <a-input v-model:value="searchFormState.name" placeholder="请输入客户名称" />
  8. </a-form-item>
  9. </a-col>
  10. <a-col :span="6">
  11. <a-form-item label="手机号" name="phone">
  12. <a-input v-model:value="searchFormState.phone" placeholder="请输入手机号" />
  13. </a-form-item>
  14. </a-col>
  15. <a-col :span="6">
  16. <a-button type="primary" @click="tableRef.refresh()">查询</a-button>
  17. <a-button style="margin: 0 8px" @click="reset">重置</a-button>
  18. <a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('customerAdd')">
  19. <template #icon><plus-outlined /></template>
  20. 新增
  21. </a-button>
  22. </a-col>
  23. </a-row>
  24. </a-form>
  25. </a-card>
  26. <a-card :bordered="false">
  27. <s-table
  28. ref="tableRef"
  29. :columns="columns"
  30. :data="loadData"
  31. bordered
  32. :row-key="(record) => record.id"
  33. >
  34. <template #bodyCell="{ column, record, index }">
  35. <template v-if="column.dataIndex === 'serial'">
  36. {{ index + 1 }}
  37. </template>
  38. <template v-if="column.dataIndex === 'action'">
  39. <a-space>
  40. <a @click="formRef.onOpen(record)" v-if="hasPerm('customerEdit')">编辑</a>
  41. <a-divider type="vertical" v-if="hasPerm(['customerEdit', 'customerDelete'], 'and')" />
  42. <a-popconfirm title="确定要删除吗?" @confirm="deleteCustomer(record)">
  43. <a-button type="link" danger size="small" v-if="hasPerm('customerDelete')">删除</a-button>
  44. </a-popconfirm>
  45. <a-divider type="vertical" v-if="hasPerm(['customerEdit', 'customerDelete'], 'or') && hasPerm('customerAccount')" />
  46. <a @click="accountFormRef.onOpen(record)" v-if="hasPerm('customerAccount')">账号管理</a>
  47. </a-space>
  48. </template>
  49. </template>
  50. </s-table>
  51. </a-card>
  52. <Form ref="formRef" @successful="tableRef.refresh()" />
  53. <AccountForm ref="accountFormRef" @successful="tableRef.refresh()" />
  54. </template>
  55. <script setup name="customer">
  56. import { cloneDeep } from 'lodash-es'
  57. import Form from './form.vue'
  58. import AccountForm from './accountIndex.vue'
  59. import customerApi from '@/api/biz/customerApi'
  60. const searchFormState = ref({})
  61. const searchFormRef = ref()
  62. const tableRef = ref()
  63. const formRef = ref()
  64. const accountFormRef = ref()
  65. const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
  66. const columns = [
  67. {
  68. title: '序号',
  69. width: 50,
  70. dataIndex: 'serial',
  71. align:'center'
  72. },
  73. {
  74. title: '客户名称',
  75. width: 180,
  76. dataIndex: 'name'
  77. },
  78. {
  79. title: '联系人',
  80. width: 80,
  81. dataIndex: 'contact'
  82. },
  83. {
  84. title: '手机号',
  85. width: 80,
  86. dataIndex: 'phone'
  87. },
  88. {
  89. title: '客户地址',
  90. width: 250,
  91. dataIndex: 'address'
  92. },
  93. {
  94. title: '备注',
  95. dataIndex: 'remark'
  96. },
  97. ]
  98. // 操作栏通过权限判断是否显示
  99. if (hasPerm(['customerEdit', 'customerDelete', 'customerAccount'])) {
  100. columns.push({
  101. title: '操作',
  102. dataIndex: 'action',
  103. align: 'center',
  104. width: 220
  105. })
  106. }
  107. const selectedRowKeys = ref([])
  108. // 列表选择配置
  109. const options = {
  110. // columns数字类型字段加入 needTotal: true 可以勾选自动算账
  111. alert: {
  112. show: true,
  113. clear: () => {
  114. selectedRowKeys.value = ref([])
  115. }
  116. },
  117. rowSelection: {
  118. onChange: (selectedRowKey, selectedRows) => {
  119. selectedRowKeys.value = selectedRowKey
  120. }
  121. }
  122. }
  123. const loadData = (parameter) => {
  124. const searchFormParam = cloneDeep(searchFormState.value)
  125. return customerApi.customerPage(Object.assign(parameter, searchFormParam)).then((data) => {
  126. return data
  127. })
  128. }
  129. // 重置
  130. const reset = () => {
  131. searchFormRef.value.resetFields()
  132. tableRef.value.refresh(true)
  133. }
  134. // 删除
  135. const deleteCustomer = (record) => {
  136. let params = [
  137. {
  138. id: record.id
  139. }
  140. ]
  141. customerApi.customerDelete(params).then(() => {
  142. tableRef.value.refresh(true)
  143. })
  144. }
  145. // 批量删除
  146. const deleteBatchCustomer = (params) => {
  147. customerApi.customerDelete(params).then(() => {
  148. tableRef.value.clearRefreshSelected()
  149. })
  150. }
  151. </script>