SelectDistributor.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <el-dialog append-to-body :title="title" :visible.sync="innerVisible" @close="close">
  3. <el-row>
  4. <el-col :span="24">
  5. <div style="float: right">
  6. <el-button size="mini" type="primary" @click="handleAdd">新建经销商</el-button>
  7. <el-dropdown style="margin-left: 10px" trigger="click">
  8. <el-button icon="el-icon-more" size="mini" />
  9. <el-dropdown-menu slot="dropdown">
  10. <el-dropdown-item icon="el-icon-upload2">导入</el-dropdown-item>
  11. <el-dropdown-item icon="el-icon-download">导出</el-dropdown-item>
  12. </el-dropdown-menu>
  13. </el-dropdown>
  14. </div>
  15. </el-col>
  16. </el-row>
  17. <el-row>
  18. <el-col :span="24">
  19. <el-input
  20. v-model="queryForm.distName"
  21. clearable
  22. placeholder="经销商名称"
  23. style="width: 30%; margin-right: 10px"
  24. suffix-icon="el-icon-search" />
  25. <table-tool :check-list.sync="checkList" :columns="columns" style="float: right" />
  26. </el-col>
  27. </el-row>
  28. <el-table ref="distributorTable" v-loading="listLoading" :data="list" @selection-change="setSelectRows">
  29. <el-table-column align="center" type="selection" />
  30. <el-table-column
  31. v-for="(item, index) in finallyColumns"
  32. :key="index"
  33. align="center"
  34. :label="item.label"
  35. :prop="item.prop"
  36. show-overflow-tooltip
  37. :sortable="item.sortable"
  38. :width="item.width">
  39. <template #default="{ row }">
  40. <span v-if="item.prop === 'custStatus'">
  41. {{ row.custStatus == 10 ? '正常' : '异常' }}
  42. </span>
  43. <span v-else>{{ row[item.prop] }}</span>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <el-pagination
  48. background
  49. :current-page="queryForm.pageNum"
  50. :layout="layout"
  51. :page-size="queryForm.pageSize"
  52. :total="total"
  53. @current-change="handleCurrentChange"
  54. @size-change="handleSizeChange" />
  55. <span slot="footer">
  56. <el-button size="mini" type="primary" @click="save">保存</el-button>
  57. <el-button size="mini" @click="innerVisible = false">取消</el-button>
  58. </span>
  59. <!-- 新增编辑经销商弹窗 -->
  60. <distributor-edit ref="edit" @customerSave="fetchData" />
  61. </el-dialog>
  62. </template>
  63. <script>
  64. import distributorApi from '@/api/base/distr/distr'
  65. import TableTool from '@/components/table/TableTool'
  66. import DistributorEdit from '@/views/base/distributor/components/DistrEdit'
  67. export default {
  68. name: 'SelectDistributor',
  69. components: {
  70. TableTool,
  71. DistributorEdit,
  72. },
  73. props: {
  74. title: {
  75. type: String,
  76. default: '选择经销商/代理商',
  77. },
  78. multiple: Boolean,
  79. queryParams: {
  80. type: Object,
  81. default() {
  82. return {}
  83. },
  84. },
  85. },
  86. data() {
  87. return {
  88. innerVisible: false,
  89. queryForm: {
  90. distName: '',
  91. pageNum: 1,
  92. pageSize: 10,
  93. },
  94. checkList: [],
  95. columns: [
  96. {
  97. label: '经销商名称',
  98. width: 'auto',
  99. prop: 'distName',
  100. // sortable: true,
  101. disableCheck: true,
  102. },
  103. {
  104. label: '助记名',
  105. width: 'auto',
  106. prop: 'abbrName',
  107. },
  108. {
  109. label: '所在省份',
  110. width: 'auto',
  111. prop: 'provinceDesc',
  112. },
  113. {
  114. label: '归属销售',
  115. width: 'auto',
  116. prop: 'belongSale',
  117. },
  118. {
  119. label: '业务范围',
  120. width: 'auto',
  121. prop: 'businessScope',
  122. },
  123. {
  124. label: '负责人',
  125. width: 'auto',
  126. prop: 'distBoss',
  127. },
  128. {
  129. label: '负责人电话',
  130. width: 'auto',
  131. prop: 'distBossPhone',
  132. },
  133. {
  134. label: '创建人',
  135. width: 'auto',
  136. prop: 'createdName',
  137. },
  138. {
  139. label: '创建时间',
  140. width: 'auto',
  141. prop: 'createdTime',
  142. // sortable: true,
  143. },
  144. ],
  145. list: [],
  146. listLoading: true,
  147. layout: 'total, sizes, prev, pager, next, jumper',
  148. total: 0,
  149. selectRows: [],
  150. }
  151. },
  152. computed: {
  153. finallyColumns() {
  154. return this.columns.filter((item) => this.checkList.includes(item.label))
  155. },
  156. },
  157. mounted() {
  158. this.fetchData()
  159. },
  160. methods: {
  161. open() {
  162. this.innerVisible = true
  163. },
  164. close() {
  165. this.selectRows = []
  166. },
  167. save() {
  168. this.innerVisible = false
  169. this.$emit('save', this.selectRows)
  170. },
  171. handleAdd() {
  172. this.$refs.edit.showEdit()
  173. },
  174. async fetchData() {
  175. this.listLoading = true
  176. let query = Object.assign(this.queryForm, this.queryParams)
  177. const {
  178. data: { list, total },
  179. } = await distributorApi.getList(query)
  180. this.list = list
  181. this.total = total
  182. this.listLoading = false
  183. },
  184. setSelectRows(val) {
  185. if (!this.multiple && val.length === this.list.length && val.length > 1) {
  186. // 返回单条数据情况下-控制全选情况下单选第一条数据
  187. if (this.selectRows.length === 1) {
  188. this.$refs.distributorTable.clearSelection()
  189. return
  190. }
  191. this.$refs.distributorTable.clearSelection()
  192. this.$refs.distributorTable.toggleRowSelection(val.shift(), true)
  193. } else if (!this.multiple && val.length > 1) {
  194. // 返回单条数据情况下-控制选择当前点击数据
  195. this.$refs.distributorTable.clearSelection()
  196. this.$refs.distributorTable.toggleRowSelection(val.pop(), true)
  197. } else {
  198. this.selectRows = val
  199. }
  200. },
  201. handleSizeChange(val) {
  202. this.queryForm.pageSize = val
  203. this.fetchData()
  204. },
  205. handleCurrentChange(val) {
  206. this.queryForm.pageNum = val
  207. this.fetchData()
  208. },
  209. },
  210. }
  211. </script>
  212. <style scoped></style>