| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <template>
- <el-dialog append-to-body :title="title" :visible.sync="innerVisible" @close="close">
- <el-row v-if="add" style="margin-top: -30px">
- <el-col :span="24">
- <div style="float: right">
- <el-button size="mini" type="primary" @click="handleAdd">新建客户</el-button>
- <!-- <el-dropdown style="margin-left: 10px" trigger="click">-->
- <!-- <el-button icon="el-icon-more" size="mini" />-->
- <!-- <el-dropdown-menu slot="dropdown">-->
- <!-- <el-dropdown-item icon="el-icon-upload2">导入</el-dropdown-item>-->
- <!-- <el-dropdown-item icon="el-icon-download">导出</el-dropdown-item>-->
- <!-- </el-dropdown-menu>-->
- <!-- </el-dropdown>-->
- </div>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="24">
- <el-input
- v-model="queryForm.custName"
- clearable
- placeholder="客户名称"
- style="width: 30%; margin-right: 10px"
- suffix-icon="el-icon-search" />
- <!-- <span>显示:</span>-->
- <!-- <el-radio-group v-model="queryForm.type">-->
- <!-- <el-radio-button label="全部客户" />-->
- <!-- <el-radio-button label="我负责的客户" />-->
- <!-- </el-radio-group>-->
- <table-tool :check-list.sync="checkList" :columns="columns" style="float: right" />
- </el-col>
- </el-row>
- <el-table ref="customerTable" v-loading="listLoading" :data="list" @selection-change="setSelectRows">
- <el-table-column align="center" type="selection" />
- <el-table-column
- v-for="(item, index) in finallyColumns"
- :key="index"
- align="center"
- :label="item.label"
- :prop="item.prop"
- show-overflow-tooltip
- :sortable="item.sortable"
- :width="item.width">
- <template #default="{ row }">
- <span v-if="item.prop === 'custStatus'">
- {{ row.custStatus == 10 ? '正常' : '异常' }}
- </span>
- <span v-else-if="item.prop === 'createdTime'">
- {{ parseTime(row.createdTime, '{y}-{m}-{d} {h}:{i}') }}
- </span>
- <span v-else>{{ row[item.prop] }}</span>
- </template>
- </el-table-column>
- </el-table>
- <el-pagination
- background
- :current-page="queryForm.pageNum"
- :layout="layout"
- :page-size="queryForm.pageSize"
- :total="total"
- @current-change="handleCurrentChange"
- @size-change="handleSizeChange" />
- <span slot="footer">
- <el-button size="mini" type="primary" @click="save">保存</el-button>
- <el-button size="mini" @click="innerVisible = false">取消</el-button>
- </span>
- <!-- 新增编辑客户弹窗 -->
- <customer-edit ref="edit" @createContact="createContact" @customerSave="fetchData" />
- <!-- 新建联系人弹窗 -->
- <customer-contact ref="contact" @contactSave="fetchData" />
- </el-dialog>
- </template>
- <script>
- import customerApi from '@/api/customer/index'
- import TableTool from '@/components/table/TableTool'
- import CustomerEdit from '@/views/customer/components/Edit'
- import CustomerContact from '@/views/customer/components/Contact'
- export default {
- name: 'SelectCustomer',
- components: {
- TableTool,
- CustomerEdit,
- CustomerContact,
- },
- props: {
- title: {
- type: String,
- default: '选择客户',
- },
- add: Boolean,
- multiple: Boolean,
- queryParams: {
- type: Object,
- default() {
- return {}
- },
- },
- },
- data() {
- return {
- innerVisible: false,
- queryForm: {
- custName: '',
- pageNum: 1,
- pageSize: 10,
- },
- checkList: [],
- columns: [
- {
- label: '客户名称',
- width: 'auto',
- prop: 'custName',
- // sortable: true,
- disableCheck: true,
- },
- {
- label: '助记名',
- width: 'auto',
- prop: 'abbrName',
- },
- {
- label: '所在地区',
- width: 'auto',
- prop: 'custLocation',
- },
- {
- label: '客户行业',
- width: 'auto',
- prop: 'custIndustry',
- },
- {
- label: '客户级别',
- width: 'auto',
- prop: 'custLevel',
- },
- {
- label: '客户状态',
- width: 'auto',
- prop: 'custStatus',
- },
- {
- label: '创建人',
- width: 'auto',
- prop: 'createdName',
- },
- {
- label: '创建时间',
- width: 'auto',
- prop: 'createdTime',
- // sortable: true,
- },
- ],
- list: [],
- listLoading: true,
- layout: 'total, sizes, prev, pager, next, jumper',
- total: 0,
- selectRows: [],
- }
- },
- computed: {
- finallyColumns() {
- return this.columns.filter((item) => this.checkList.includes(item.label))
- },
- },
- mounted() {
- // this.fetchData()
- },
- methods: {
- open() {
- this.innerVisible = true
- this.fetchData()
- },
- close() {
- this.selectRows = []
- this.$refs.customerTable.clearSelection()
- },
- save() {
- this.innerVisible = false
- this.$emit('save', this.selectRows)
- },
- handleAdd() {
- this.$refs.edit.init()
- },
- // 联系人弹窗
- async createContact(res) {
- this.$refs.contact.contactForm.custId = res.id
- this.$refs.contact.contactForm.custName = res.name
- this.$refs.contact.contactVisible = true
- },
- async fetchData() {
- this.listLoading = true
- let query = Object.assign(this.queryForm, this.queryParams)
- const {
- data: { list, total },
- } = await customerApi.getList(query)
- this.list = list
- this.total = total
- this.listLoading = false
- },
- setSelectRows(val) {
- if (!this.multiple && val.length === this.list.length && val.length > 1) {
- // 返回单条数据情况下-控制全选情况下单选第一条数据
- if (this.selectRows.length === 1) {
- this.$refs.customerTable.clearSelection()
- return
- }
- this.$refs.customerTable.clearSelection()
- this.$refs.customerTable.toggleRowSelection(val.shift(), true)
- } else if (!this.multiple && val.length > 1) {
- // 返回单条数据情况下-控制选择当前点击数据
- this.$refs.customerTable.clearSelection()
- this.$refs.customerTable.toggleRowSelection(val.pop(), true)
- } else {
- this.selectRows = val
- }
- },
- handleSizeChange(val) {
- this.queryForm.pageSize = val
- this.fetchData()
- },
- handleCurrentChange(val) {
- this.queryForm.pageNum = val
- this.fetchData()
- },
- },
- }
- </script>
- <style scoped></style>
|