index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <div class="height_100">
  3. <el-container>
  4. <el-header>
  5. <!-- <div>
  6. <mySearch style="width: 500px" :SearchFields="searchFiled" @search="search" :searchValue="searchOption">
  7. </mySearch>
  8. </div>
  9. <div v-if="!choseClient">
  10. <el-button type="primary" size="small" @click="handleAdd()"> 新增 </el-button>
  11. </div> -->
  12. <el-form :inline="true">
  13. <el-form-item label="用户名">
  14. <el-input v-model="queryParams.name" size="small" placeholder="请输入用户名"></el-input>
  15. </el-form-item>
  16. <el-form-item>
  17. <el-button type="" size="small" @click="getList">查询</el-button>
  18. <el-button type="primary" size="small" @click="handleAdd()" v-if="!choseClient">新增</el-button>
  19. </el-form-item>
  20. </el-form>
  21. </el-header>
  22. <el-main>
  23. <div class="height_100">
  24. <el-table v-loading="loading" :data="tableData" border header-row-class-name="custom-table-header">
  25. <el-table-column type="index" label="#" width="55" align="center">
  26. <template slot-scope="scope">
  27. <span>{{ (scope.$index + 1) + ((queryParams.current - 1) * queryParams.size) }}</span>
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="name" label="客户名称" align="center" show-overflow-tooltip>
  31. <template slot-scope="scope">
  32. <div>
  33. <div v-if="!choseClient">{{ scope.row.name }}</div>
  34. <div v-else>
  35. <el-link type="primary" @click.native="getClient(scope.row)">{{ scope.row.name }}</el-link>
  36. </div>
  37. </div>
  38. </template>
  39. </el-table-column>
  40. <!-- <template >
  41. <div> -->
  42. <el-table-column v-show="!choseClient" prop="personnelName" label="客户对接人" align="center" show-overflow-tooltip></el-table-column>
  43. <el-table-column v-show="!choseClient" prop="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
  44. <el-table-column v-show="!choseClient" label="操作" align="center" width="150">
  45. <template slot-scope="scope">
  46. <el-dropdown split-button type="primary" size="small" @click="handleEdit(scope.row)">
  47. <span>编辑</span>
  48. <el-dropdown-menu slot="dropdown" class="text-align_center">
  49. <el-dropdown-item class="color-red" @click.native="handleDelete(scope.row)" divided>删除</el-dropdown-item>
  50. </el-dropdown-menu>
  51. </el-dropdown>
  52. </template>
  53. </el-table-column>
  54. <!-- </div>
  55. </template> -->
  56. </el-table>
  57. </div>
  58. </el-main>
  59. <el-footer>
  60. <div class="pagination">
  61. <el-pagination :current-page.sync="queryParams.current" :page-size="queryParams.size" :total="total"
  62. @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper" background></el-pagination>
  63. </div>
  64. </el-footer>
  65. </el-container>
  66. <el-dialog :title="title" :visible.sync="visible" width="500px" :before-close="close" :append-to-body="true" :close-on-click-modal="false">
  67. <el-form v-if="visible" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" label-position="left">
  68. <el-form-item label="客户名称" prop="name">
  69. <el-autocomplete style="width:100%" v-model="ruleForm.name" :fetch-suggestions="querySearch" @input="input"
  70. placeholder="请输入客户名称" :trigger-on-focus="false" @select="handleChange">
  71. </el-autocomplete>
  72. </el-form-item>
  73. <el-form-item label="对接人" prop="person">
  74. <el-select style="width:100%" v-model="ruleForm.personnelId" filterable placeholder="请选择">
  75. <el-option v-for="item in personnelList" :key="item.id" :label="item.name" :value="item.id">
  76. </el-option>
  77. </el-select>
  78. </el-form-item>
  79. <el-form-item label="备注" prop="remark">
  80. <el-input v-model="ruleForm.remark" placeholder="请输入备注" type="textarea"></el-input>
  81. </el-form-item>
  82. </el-form>
  83. <div slot="footer" class="dialog-footer">
  84. <el-button @click="close">取 消</el-button>
  85. <el-button type="primary" @click="submit" :loading="btnLoading">确 定</el-button>
  86. </div>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script>
  91. export default {
  92. components: {},
  93. props: {
  94. name: '',
  95. choseClient: false
  96. },
  97. data() {
  98. return {
  99. //弹窗显示标识
  100. visible: false,
  101. //加载
  102. loading: false,
  103. //按钮加载
  104. btnLoading: false,
  105. //人员列表
  106. personnelList: [],
  107. //总客户数
  108. total: 0,
  109. //客户列表数据
  110. tableData: [],
  111. //弹窗标题
  112. title: '',
  113. //分页信息
  114. queryParams: {
  115. size: 10,
  116. current: 1,
  117. },
  118. //表单信息
  119. ruleForm: {},
  120. //表单规则
  121. rules: {
  122. name: [{ required: true, message: '请输入客户名称', trigger: 'blur' },],
  123. },
  124. //租户列表
  125. tenantList: [],
  126. //检索字段
  127. searchFiled: [
  128. {
  129. label: '客户名称名称',
  130. value: 'name',
  131. type: 1,
  132. placeholder: '请输入客户名称'
  133. }
  134. ],
  135. //检索条件
  136. searchOption: {
  137. name: this.name
  138. },
  139. };
  140. },
  141. watch: {},
  142. computed: {},
  143. created() { },
  144. mounted() {
  145. this.getList()
  146. //获取客户信息(建议改成远程搜索,或者懒加载)
  147. this.getPersonnelList()
  148. //去除获取所有租户的方法以及相关信息
  149. this.getAllTenantList()
  150. },
  151. methods: {
  152. //检索
  153. search() {
  154. },
  155. //改为通过接口获取数据
  156. querySearch(queryString, cb) {
  157. var tenantList = this.tenantList;
  158. var results = (queryString ? tenantList.filter(this.createFilter(queryString)) : tenantList).map(item => {
  159. return {
  160. value: item.name,
  161. name: item.name,
  162. id: item.id
  163. }
  164. });
  165. // 调用 callback 返回建议列表的数据
  166. cb(results);
  167. },
  168. createFilter(queryString) {
  169. return (tenantList) => {
  170. return (tenantList.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
  171. };
  172. },
  173. //获取所有租户信息
  174. getAllTenantList() {
  175. this.$api.getAllTenantList().then(response => {
  176. this.tenantList = response.data
  177. })
  178. },
  179. //输入事件
  180. input() {
  181. this.$set(this.ruleForm, 'tenantId', null)
  182. },
  183. //切换选择客户名称
  184. handleChange(row) {
  185. this.$set(this.ruleForm, 'tenantId', row.id)
  186. this.$set(this.ruleForm, 'name', row.name)
  187. },
  188. //打开新增客户弹窗
  189. handleAdd() {
  190. this.title = '新增客户'
  191. this.visible = true
  192. this.ruleForm = {}
  193. },
  194. //打开编辑客户弹窗
  195. handleEdit(row) {
  196. this.title = '编辑客户'
  197. this.visible = true
  198. this.ruleForm = { ...row }
  199. },
  200. //关闭弹窗
  201. close() {
  202. this.$refs.ruleForm.resetFields()
  203. this.visible = false
  204. },
  205. //获取所有人员信息(最好使用远程搜索)
  206. getPersonnelList() {
  207. this.$api.getPermissionPersonnelList().then((response) => {
  208. this.personnelList = response.data
  209. })
  210. },
  211. //获取客户信息
  212. getList() {
  213. this.loading = true
  214. this.$api.getAdminClientList(this.queryParams).then(response => {
  215. this.tableData = response.data.records
  216. this.total = response.data.total
  217. this.loading = false
  218. }).catch(error => {
  219. this.loading = false
  220. })
  221. },
  222. //分页
  223. handleCurrentChange(val) {
  224. this.queryParams.current = val;
  225. this.getList();
  226. },
  227. //提交信息
  228. submit() {
  229. this.$refs.ruleForm.validate((valid) => {
  230. if (valid) {
  231. this.btnLoading = true
  232. if (this.ruleForm.id) {
  233. this.$api.editAdminClient(this.ruleForm).then(response => {
  234. this.$message.success('编辑成功')
  235. this.btnLoading = false
  236. this.getList()
  237. this.close()
  238. }).catch(error => {
  239. this.btnLoading = false
  240. })
  241. } else {
  242. this.$api.addAdminClient(this.ruleForm).then(response => {
  243. this.$message.success('新增成功')
  244. this.btnLoading = false
  245. this.getList()
  246. this.close()
  247. }).catch(error => {
  248. this.btnLoading = false
  249. })
  250. }
  251. } else {
  252. // console.log('error submit!!');
  253. return false;
  254. }
  255. });
  256. },
  257. //删除客户
  258. handleDelete(row) {
  259. this.$confirm('确认删除本条数据吗?', '提示', {
  260. confirmButtonText: '确定',
  261. cancelButtonText: '取消',
  262. type: 'warning'
  263. }).then(() => {
  264. this.loading = true
  265. this.$api.deleteAdminClient({ id: row.id }).then(response => {
  266. this.$message.success('删除成功')
  267. this.loading = false
  268. this.getList()
  269. }).catch(error => {
  270. this.loading = false
  271. })
  272. })
  273. },
  274. //选择客户
  275. getClient(row) {
  276. this.$emit('getClient', row)
  277. },
  278. }
  279. };
  280. </script>
  281. <style lang="scss" scoped></style>