SelectBusinessContact.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <el-dialog append-to-body :title="title" :visible.sync="innerVisible" @close="close">
  3. <el-row>
  4. <el-col :span="24">
  5. <el-input
  6. v-model="queryForm.keyword"
  7. clearable
  8. placeholder="客户名称/手机/电话"
  9. style="width: 30%; margin-right: 10px"
  10. suffix-icon="el-icon-search"
  11. @keyup.enter.native="fetchData" />
  12. <el-button icon="el-icon-search" type="primary" @click="fetchData">查询</el-button>
  13. <table-tool
  14. :columns="columns"
  15. :show-columns.sync="showColumns"
  16. style="float: right"
  17. table-type="selectBusinessContactTable" />
  18. </el-col>
  19. </el-row>
  20. <el-table ref="contactTable" v-loading="listLoading" :data="list" @selection-change="setSelectRows">
  21. <el-table-column align="center" type="selection" />
  22. <el-table-column
  23. v-for="(item, index) in showColumns"
  24. :key="index + Math.random()"
  25. align="center"
  26. :label="item.label"
  27. :prop="item.prop"
  28. show-overflow-tooltip
  29. :sortable="item.sortable"
  30. :width="item.width">
  31. <template #default="{ row }">
  32. <span v-if="item.prop === 'isDecision'">
  33. {{ selectDictLabel(yesNoOptions, row.isDecision) }}
  34. </span>
  35. <span v-else-if="item.prop === 'cuctGender'">
  36. {{ selectDictLabel(sexOptions, row.cuctGender) }}
  37. </span>
  38. <span v-else>{{ row[item.prop] }}</span>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. <el-pagination
  43. background
  44. :current-page="queryForm.pageNum"
  45. :layout="layout"
  46. :page-size="queryForm.pageSize"
  47. :total="total"
  48. @current-change="handleCurrentChange"
  49. @size-change="handleSizeChange" />
  50. <span slot="footer">
  51. <el-button size="mini" type="primary" @click="save">保存</el-button>
  52. <el-button size="mini" @click="innerVisible = false">取消</el-button>
  53. </span>
  54. </el-dialog>
  55. </template>
  56. <script>
  57. import businessContactApi from '@/api/proj/businessContact'
  58. import TableTool from '@/components/table/TableTool'
  59. export default {
  60. name: 'SelectContact',
  61. components: {
  62. TableTool,
  63. },
  64. props: {
  65. title: {
  66. type: String,
  67. default: '选择客户联系人',
  68. },
  69. addButton: Boolean,
  70. multiple: Boolean,
  71. // 示例{ custId: custId, custName: custName}
  72. defaultCustomer: {
  73. type: Object,
  74. default() {
  75. return {}
  76. },
  77. },
  78. // 示例{ busId: busId, custId: custId}
  79. queryParams: {
  80. type: Object,
  81. default() {
  82. return {}
  83. },
  84. },
  85. },
  86. data() {
  87. return {
  88. innerVisible: false,
  89. queryForm: {
  90. keyword: '',
  91. pageNum: 1,
  92. pageSize: 10,
  93. },
  94. showColumns: [],
  95. columns: [
  96. {
  97. label: '联系人姓名',
  98. width: 'auto',
  99. prop: 'cuctName',
  100. // sortable: true,
  101. disableCheck: true,
  102. },
  103. {
  104. label: '客户名称',
  105. width: 'auto',
  106. prop: 'custName',
  107. },
  108. {
  109. label: '手机号码',
  110. width: 'auto',
  111. prop: 'telephone',
  112. },
  113. {
  114. label: '微信',
  115. width: 'auto',
  116. prop: 'wechat',
  117. },
  118. {
  119. label: '邮箱',
  120. width: 'auto',
  121. prop: 'email',
  122. },
  123. {
  124. label: '职务',
  125. width: 'auto',
  126. prop: 'postion',
  127. },
  128. {
  129. label: '关键决策人',
  130. width: 'auto',
  131. prop: 'isDecision',
  132. },
  133. {
  134. label: '性别',
  135. width: 'auto',
  136. prop: 'cuctGender',
  137. // sortable: true,
  138. },
  139. ],
  140. list: [],
  141. listLoading: true,
  142. layout: 'total, sizes, prev, pager, next, jumper',
  143. total: 0,
  144. selectRows: [],
  145. sexOptions: [],
  146. yesNoOptions: [],
  147. }
  148. },
  149. mounted() {
  150. this.getDicts('sys_sex').then((response) => {
  151. this.sexOptions = response.data.values || []
  152. })
  153. this.getDicts('sys_yes_no').then((response) => {
  154. this.yesNoOptions = response.data.values || []
  155. })
  156. },
  157. methods: {
  158. open() {
  159. this.innerVisible = true
  160. this.fetchData()
  161. },
  162. close() {
  163. this.selectRows = []
  164. this.queryForm = this.$options.data().queryForm
  165. this.$refs.contactTable.clearSelection()
  166. },
  167. save() {
  168. this.innerVisible = false
  169. this.$emit('save', this.selectRows)
  170. },
  171. async fetchData() {
  172. this.listLoading = true
  173. let query = Object.assign(this.queryForm, this.queryParams)
  174. const { data } = await businessContactApi.getList(query)
  175. if (data) {
  176. this.list = data.list
  177. this.total = data.total
  178. }
  179. this.listLoading = false
  180. },
  181. setSelectRows(val) {
  182. if (!this.multiple && val.length === this.list.length && val.length > 1) {
  183. // 返回单条数据情况下-控制全选情况下单选第一条数据
  184. this.$refs.contactTable.clearSelection()
  185. if (this.selectRows.length === 1) {
  186. return
  187. }
  188. this.$refs.contactTable.toggleRowSelection(val.shift(), true)
  189. } else if (!this.multiple && val.length > 1) {
  190. // 返回单条数据情况下-控制选择当前点击数据
  191. this.$refs.contactTable.clearSelection()
  192. this.$refs.contactTable.toggleRowSelection(val.pop(), true)
  193. } else {
  194. this.selectRows = val
  195. }
  196. },
  197. handleSizeChange(val) {
  198. this.queryForm.pageSize = val
  199. this.fetchData()
  200. },
  201. handleCurrentChange(val) {
  202. this.queryForm.pageNum = val
  203. this.fetchData()
  204. },
  205. },
  206. }
  207. </script>
  208. <style scoped></style>