SelectCustomer.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <el-dialog append-to-body :title="title" :visible.sync="innerVisible" @close="close">
  3. <el-row v-if="add" style="margin-top: -30px">
  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.custName"
  21. clearable
  22. placeholder="客户名称"
  23. style="width: 30%; margin-right: 10px"
  24. suffix-icon="el-icon-search" />
  25. <!-- <span>显示:</span>-->
  26. <!-- <el-radio-group v-model="queryForm.type">-->
  27. <!-- <el-radio-button label="全部客户" />-->
  28. <!-- <el-radio-button label="我负责的客户" />-->
  29. <!-- </el-radio-group>-->
  30. <table-tool :check-list.sync="checkList" :columns="columns" style="float: right" />
  31. </el-col>
  32. </el-row>
  33. <el-table ref="customerTable" v-loading="listLoading" :data="list" @selection-change="setSelectRows">
  34. <el-table-column align="center" type="selection" />
  35. <el-table-column
  36. v-for="(item, index) in finallyColumns"
  37. :key="index"
  38. align="center"
  39. :label="item.label"
  40. :prop="item.prop"
  41. show-overflow-tooltip
  42. :sortable="item.sortable"
  43. :width="item.width">
  44. <template #default="{ row }">
  45. <span v-if="item.prop === 'custStatus'">
  46. {{ row.custStatus == 10 ? '正常' : '异常' }}
  47. </span>
  48. <span v-else-if="item.prop === 'createdTime'">
  49. {{ parseTime(row.createdTime, '{y}-{m}-{d} {h}:{i}') }}
  50. </span>
  51. <span v-else>{{ row[item.prop] }}</span>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <el-pagination
  56. background
  57. :current-page="queryForm.pageNum"
  58. :layout="layout"
  59. :page-size="queryForm.pageSize"
  60. :total="total"
  61. @current-change="handleCurrentChange"
  62. @size-change="handleSizeChange" />
  63. <span slot="footer">
  64. <el-button size="mini" type="primary" @click="save">保存</el-button>
  65. <el-button size="mini" @click="innerVisible = false">取消</el-button>
  66. </span>
  67. <!-- 新增编辑客户弹窗 -->
  68. <customer-edit ref="edit" @createContact="createContact" @customerSave="fetchData" />
  69. <!-- 新建联系人弹窗 -->
  70. <customer-contact ref="contact" @contactSave="fetchData" />
  71. </el-dialog>
  72. </template>
  73. <script>
  74. import customerApi from '@/api/customer/index'
  75. import TableTool from '@/components/table/TableTool'
  76. import CustomerEdit from '@/views/customer/components/Edit'
  77. import CustomerContact from '@/views/customer/components/Contact'
  78. export default {
  79. name: 'SelectCustomer',
  80. components: {
  81. TableTool,
  82. CustomerEdit,
  83. CustomerContact,
  84. },
  85. props: {
  86. title: {
  87. type: String,
  88. default: '选择客户',
  89. },
  90. add: Boolean,
  91. multiple: Boolean,
  92. queryParams: {
  93. type: Object,
  94. default() {
  95. return {}
  96. },
  97. },
  98. },
  99. data() {
  100. return {
  101. innerVisible: false,
  102. queryForm: {
  103. custName: '',
  104. pageNum: 1,
  105. pageSize: 10,
  106. },
  107. checkList: [],
  108. columns: [
  109. {
  110. label: '客户名称',
  111. width: 'auto',
  112. prop: 'custName',
  113. // sortable: true,
  114. disableCheck: true,
  115. },
  116. {
  117. label: '助记名',
  118. width: 'auto',
  119. prop: 'abbrName',
  120. },
  121. {
  122. label: '所在地区',
  123. width: 'auto',
  124. prop: 'custLocation',
  125. },
  126. {
  127. label: '客户行业',
  128. width: 'auto',
  129. prop: 'custIndustry',
  130. },
  131. {
  132. label: '客户级别',
  133. width: 'auto',
  134. prop: 'custLevel',
  135. },
  136. {
  137. label: '客户状态',
  138. width: 'auto',
  139. prop: 'custStatus',
  140. },
  141. {
  142. label: '创建人',
  143. width: 'auto',
  144. prop: 'createdName',
  145. },
  146. {
  147. label: '创建时间',
  148. width: 'auto',
  149. prop: 'createdTime',
  150. // sortable: true,
  151. },
  152. ],
  153. list: [],
  154. listLoading: true,
  155. layout: 'total, sizes, prev, pager, next, jumper',
  156. total: 0,
  157. selectRows: [],
  158. }
  159. },
  160. computed: {
  161. finallyColumns() {
  162. return this.columns.filter((item) => this.checkList.includes(item.label))
  163. },
  164. },
  165. mounted() {
  166. // this.fetchData()
  167. },
  168. methods: {
  169. open() {
  170. this.innerVisible = true
  171. this.fetchData()
  172. },
  173. close() {
  174. this.selectRows = []
  175. this.$refs.customerTable.clearSelection()
  176. },
  177. save() {
  178. this.innerVisible = false
  179. this.$emit('save', this.selectRows)
  180. },
  181. handleAdd() {
  182. this.$refs.edit.init()
  183. },
  184. // 联系人弹窗
  185. async createContact(res) {
  186. this.$refs.contact.contactForm.custId = res.id
  187. this.$refs.contact.contactForm.custName = res.name
  188. this.$refs.contact.contactVisible = true
  189. },
  190. async fetchData() {
  191. this.listLoading = true
  192. let query = Object.assign(this.queryForm, this.queryParams)
  193. const {
  194. data: { list, total },
  195. } = await customerApi.getList(query)
  196. this.list = list
  197. this.total = total
  198. this.listLoading = false
  199. },
  200. setSelectRows(val) {
  201. if (!this.multiple && val.length === this.list.length && val.length > 1) {
  202. // 返回单条数据情况下-控制全选情况下单选第一条数据
  203. if (this.selectRows.length === 1) {
  204. this.$refs.customerTable.clearSelection()
  205. return
  206. }
  207. this.$refs.customerTable.clearSelection()
  208. this.$refs.customerTable.toggleRowSelection(val.shift(), true)
  209. } else if (!this.multiple && val.length > 1) {
  210. // 返回单条数据情况下-控制选择当前点击数据
  211. this.$refs.customerTable.clearSelection()
  212. this.$refs.customerTable.toggleRowSelection(val.pop(), true)
  213. } else {
  214. this.selectRows = val
  215. }
  216. },
  217. handleSizeChange(val) {
  218. this.queryForm.pageSize = val
  219. this.fetchData()
  220. },
  221. handleCurrentChange(val) {
  222. this.queryForm.pageNum = val
  223. this.fetchData()
  224. },
  225. },
  226. }
  227. </script>
  228. <style scoped></style>