SelectContact.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <el-dialog append-to-body :title="title" :visible.sync="innerVisible">
  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.keyword"
  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="contactTable" 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>{{ row[item.prop] }}</span>
  49. </template>
  50. </el-table-column>
  51. </el-table>
  52. <el-pagination
  53. background
  54. :current-page="queryForm.pageNo"
  55. :layout="layout"
  56. :page-size="queryForm.pageSize"
  57. :total="total"
  58. @current-change="handleCurrentChange"
  59. @size-change="handleSizeChange" />
  60. <span slot="footer">
  61. <el-button size="mini" type="primary" @click="save">保存</el-button>
  62. <el-button size="mini" @click="innerVisible = false">取消</el-button>
  63. </span>
  64. <!-- 新建联系人弹窗 -->
  65. <customer-contact ref="contact" @contactSave="fetchData" />
  66. </el-dialog>
  67. </template>
  68. <script>
  69. import customerApi from '@/api/customer/index'
  70. import TableTool from '@/components/table/TableTool'
  71. import CustomerContact from '@/views/customer/components/Contact'
  72. export default {
  73. name: 'SelectContact',
  74. components: {
  75. TableTool,
  76. CustomerContact,
  77. },
  78. props: {
  79. title: {
  80. type: String,
  81. default: '选择客户联系人',
  82. },
  83. multiple: Boolean,
  84. // 示例{ custId: id, custName: custName}
  85. defaultCustomer: {
  86. type: Object,
  87. default() {
  88. return {}
  89. },
  90. },
  91. queryParams: {
  92. type: Object,
  93. default() {
  94. return {}
  95. },
  96. },
  97. },
  98. data() {
  99. return {
  100. innerVisible: false,
  101. queryForm: {
  102. keyword: '',
  103. type: '全部客户',
  104. pageNum: 1,
  105. pageSize: 10,
  106. },
  107. checkList: [],
  108. columns: [
  109. {
  110. label: '联系人姓名',
  111. width: 'auto',
  112. prop: 'cuctName',
  113. // sortable: true,
  114. disableCheck: true,
  115. },
  116. {
  117. label: '客户名称',
  118. width: 'auto',
  119. prop: 'custName',
  120. },
  121. {
  122. label: '手机号码',
  123. width: 'auto',
  124. prop: 'telephone',
  125. },
  126. {
  127. label: '微信',
  128. width: 'auto',
  129. prop: 'wechat',
  130. },
  131. {
  132. label: '邮箱',
  133. width: 'auto',
  134. prop: 'email',
  135. },
  136. {
  137. label: '职务',
  138. width: 'auto',
  139. prop: 'postion',
  140. },
  141. {
  142. label: '关键决策人',
  143. width: 'auto',
  144. prop: 'policy',
  145. },
  146. {
  147. label: '性别',
  148. width: 'auto',
  149. prop: 'cuctGender',
  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. methods: {
  167. open() {
  168. this.innerVisible = true
  169. this.fetchData()
  170. },
  171. save() {
  172. this.innerVisible = false
  173. console.log(this.selectRows)
  174. this.$emit('save', this.selectRows)
  175. },
  176. handleAdd() {
  177. this.$refs.contact.contactForm.custId = this.defaultCustomer.custId
  178. this.$refs.contact.contactForm.custName = this.defaultCustomer.custName
  179. this.$refs.contact.contactVisible = true
  180. },
  181. async fetchData() {
  182. this.listLoading = true
  183. let query = Object.assign(this.queryForm, this.queryParams)
  184. const {
  185. data: { list, total },
  186. } = await customerApi.getContact(query)
  187. this.list = list
  188. this.total = total
  189. this.listLoading = false
  190. },
  191. setSelectRows(val) {
  192. if (!this.multiple && val.length === this.list.length && val.length > 1) {
  193. // 返回单条数据情况下-控制全选情况下单选第一条数据
  194. this.$refs.contactTable.clearSelection()
  195. if (this.selectRows.length === 1) {
  196. return
  197. }
  198. this.$refs.contactTable.toggleRowSelection(val.shift(), true)
  199. } else if (!this.multiple && val.length > 1) {
  200. // 返回单条数据情况下-控制选择当前点击数据
  201. this.$refs.contactTable.clearSelection()
  202. this.$refs.contactTable.toggleRowSelection(val.pop(), true)
  203. } else {
  204. this.selectRows = val
  205. }
  206. },
  207. handleSizeChange(val) {
  208. this.queryForm.pageSize = val
  209. this.fetchData()
  210. },
  211. handleCurrentChange(val) {
  212. this.queryForm.pageNo = val
  213. this.fetchData()
  214. },
  215. },
  216. }
  217. </script>
  218. <style scoped></style>