index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <template>
  2. <div class="app-container">
  3. <!-- 导入弹窗 start-->
  4. <el-dialog
  5. :title="upload.title"
  6. :visible.sync="upload.open"
  7. width="400px"
  8. append-to-body
  9. >
  10. <el-upload
  11. ref="upload"
  12. :limit="1"
  13. accept=".xlsx, .xls"
  14. :headers="upload.headers"
  15. :action="upload.url"
  16. v-loading="upload.isUploading"
  17. :disabled="upload.isUploading"
  18. :on-progress="handleFileUploadProgress"
  19. :on-success="handleFileSuccess"
  20. :auto-upload="false"
  21. drag
  22. >
  23. <i class="el-icon-upload"></i>
  24. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  25. <div class="el-upload__tip text-center" slot="tip">
  26. <!-- <div class="el-upload__tip" slot="tip">-->
  27. <!-- <el-checkbox v-model="upload.updateSupport"/>-->
  28. <!-- 是否更新已经存在的用户数据-->
  29. <!-- </div>-->
  30. <span>仅允许导入xls、xlsx格式文件。</span>
  31. <el-link
  32. type="primary"
  33. :underline="false"
  34. style="font-size: 12px; vertical-align: baseline"
  35. @click="importTemplate"
  36. >下载模板
  37. </el-link>
  38. </div>
  39. </el-upload>
  40. <div slot="footer" class="dialog-footer">
  41. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  42. <el-button @click="upload.open = false">取 消</el-button>
  43. </div>
  44. </el-dialog>
  45. <!-- 导入弹窗 end-->
  46. <el-form
  47. :model="queryParams"
  48. ref="queryForm"
  49. size="small"
  50. :inline="true"
  51. v-show="showSearch"
  52. label-width="68px"
  53. >
  54. <el-form-item label="超级查询" prop="queryParam">
  55. <el-input
  56. v-model="queryParams.queryParam"
  57. placeholder=""
  58. clearable
  59. @keyup.enter.native="handleQuery"
  60. />
  61. </el-form-item>
  62. <el-form-item>
  63. <el-button
  64. type="primary"
  65. icon="el-icon-search"
  66. size="mini"
  67. @click="handleQuery"
  68. >搜索</el-button
  69. >
  70. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  71. >重置</el-button
  72. >
  73. </el-form-item>
  74. </el-form>
  75. <el-row :gutter="10" class="mb8">
  76. <el-col :span="1.5">
  77. <el-button
  78. type="primary"
  79. plain
  80. icon="el-icon-plus"
  81. size="mini"
  82. @click="handleAdd"
  83. v-hasPermi="['huaxian:xsglkhgl:INSERT']"
  84. >新增</el-button
  85. >
  86. </el-col>
  87. <!-- <el-col :span="1.5">
  88. <el-button
  89. type="success"
  90. plain
  91. icon="el-icon-edit"
  92. size="mini"
  93. :disabled="single"
  94. @click="handleUpdate"
  95. v-hasPermi="['system:customer:edit']"
  96. >修改</el-button
  97. >
  98. </el-col> -->
  99. <el-col :span="1.5">
  100. <el-button
  101. type="danger"
  102. plain
  103. icon="el-icon-delete"
  104. size="mini"
  105. :disabled="multiple"
  106. @click="handleDelete"
  107. v-hasPermi="['huaxian:xsglkhgl:DELETE']"
  108. >删除</el-button
  109. >
  110. </el-col>
  111. <el-col :span="1.5">
  112. <el-button
  113. type="success"
  114. plain
  115. icon="el-icon-edit"
  116. size="mini"
  117. @click="upload.open = true"
  118. v-hasPermi="['system:customer:IMPORT']"
  119. >导入</el-button
  120. >
  121. </el-col>
  122. <el-col :span="1.5">
  123. <el-button
  124. type="warning"
  125. plain
  126. icon="el-icon-download"
  127. size="mini"
  128. @click="handleExport"
  129. v-hasPermi="['huaxian:xsglkhgl:EXPORT']"
  130. >导出</el-button
  131. >
  132. </el-col>
  133. <right-toolbar
  134. :showSearch.sync="showSearch"
  135. @queryTable="getList"
  136. ></right-toolbar>
  137. </el-row>
  138. <el-table
  139. v-loading="loading"
  140. :data="customerList"
  141. @selection-change="handleSelectionChange"
  142. >
  143. <el-table-column type="selection" width="55" align="center" />
  144. <!-- <el-table-column label="主键" align="center" prop="id" /> -->
  145. <el-table-column label="客户编号" align="center" prop="customNo" />
  146. <el-table-column label="客户名称" align="center" prop="customName" />
  147. <el-table-column
  148. label="手机号码"
  149. align="center"
  150. prop="customPhoneNumber"
  151. />
  152. <el-table-column label="座机号码" align="center" prop="customLandine" />
  153. <el-table-column label="邮件地址" align="center" prop="customMail" />
  154. <el-table-column label="客户类型" align="center" prop="customType">
  155. <template slot-scope="scope">{{
  156. getDictLabel(scope.row.customType, "customer_type")
  157. }}</template>
  158. </el-table-column>
  159. <el-table-column label="客户等级" align="center" prop="customGrade">
  160. <template slot-scope="scope">{{
  161. getDictLabel(scope.row.customGrade, "customer_level")
  162. }}</template>
  163. </el-table-column>
  164. <el-table-column label="地址信息" align="center" prop="customAddress" />
  165. <el-table-column
  166. label="客户国别"
  167. align="center"
  168. prop="customCountryType"
  169. />
  170. <el-table-column label="客户地区" align="center" prop="customDistrict" />
  171. <el-table-column label="销售员" align="center" prop="salesman" />
  172. <el-table-column label="联系人" align="center" prop="contactPerson" />
  173. <el-table-column label="备注" align="center" prop="remark" />
  174. <el-table-column label="累计欠款" align="center" prop="amounts">
  175. <template slot-scope="scope">
  176. <span :style="{color: scope.row.amounts > 0 ? 'red' : 'black'}">
  177. {{ scope.row.amount }}
  178. </span>
  179. </template>
  180. </el-table-column>
  181. <el-table-column
  182. label="操作"
  183. align="center"
  184. class-name="small-padding fixed-width"
  185. >
  186. <template slot-scope="scope">
  187. <el-dropdown>
  188. <el-button type="warning" plain size="small">
  189. 处理<i class="el-icon-arrow-down el-icon--right"></i>
  190. </el-button>
  191. <el-dropdown-menu slot="dropdown">
  192. <el-dropdown-item>
  193. <el-button
  194. size="mini"
  195. type="text"
  196. icon="el-icon-edit"
  197. @click="handleUpdate(scope.row)"
  198. v-hasPermi="['huaxian:xsglkhgl:UPDATE']"
  199. >修改</el-button
  200. >
  201. </el-dropdown-item>
  202. <el-dropdown-item>
  203. <el-button
  204. size="mini"
  205. type="text"
  206. icon="el-icon-delete"
  207. @click="handleDelete(scope.row)"
  208. v-hasPermi="['huaxian:xsglkhgl:DELETE']"
  209. >删除</el-button
  210. >
  211. </el-dropdown-item>
  212. </el-dropdown-menu>
  213. </el-dropdown>
  214. </template>
  215. </el-table-column>
  216. </el-table>
  217. <pagination
  218. v-show="total > 0"
  219. :total="total"
  220. :page.sync="queryParams.pageNum"
  221. :limit.sync="queryParams.pageSize"
  222. @pagination="getList"
  223. />
  224. <!-- 添加或修改客户对话框 -->
  225. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  226. <el-row :gutter="20">
  227. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  228. <el-col :span="12">
  229. <el-form-item label="客户编号" prop="customNo">
  230. <el-input v-model="form.customNo" placeholder="请输入客户编号" disabled="true"/>
  231. </el-form-item>
  232. </el-col>
  233. <el-col :span="12">
  234. <el-form-item label="客户名称" prop="customName">
  235. <el-input
  236. v-model="form.customName"
  237. placeholder="请输入客户名称"
  238. />
  239. </el-form-item>
  240. </el-col>
  241. <el-col :span="12">
  242. <el-form-item label="手机号码" prop="customPhoneNumber">
  243. <el-input
  244. v-model="form.customPhoneNumber"
  245. placeholder="请输入手机号码(+86/其他国外)"
  246. />
  247. </el-form-item>
  248. </el-col>
  249. <el-col :span="12">
  250. <el-form-item label="客户类型" prop="customType">
  251. <!-- <el-input
  252. v-model="form.customType"
  253. placeholder="请输入客户名称"
  254. /> -->
  255. <el-select
  256. v-model="form.customType"
  257. placeholder="请选择客户类型"
  258. clearable
  259. filterable
  260. >
  261. <el-option
  262. v-for="item in dict.type.customer_type"
  263. :key="item.value"
  264. :label="item.label"
  265. :value="item.value"
  266. >
  267. </el-option>
  268. </el-select>
  269. </el-form-item>
  270. </el-col>
  271. <el-col :span="12">
  272. <el-form-item label="座机号码" prop="customLandine">
  273. <el-input
  274. v-model="form.customLandine"
  275. placeholder="请输入座机号码"
  276. />
  277. </el-form-item>
  278. </el-col>
  279. <el-col :span="12">
  280. <el-form-item label="邮件地址" prop="customMail">
  281. <el-input
  282. v-model="form.customMail"
  283. placeholder="请输入邮件地址"
  284. />
  285. </el-form-item>
  286. </el-col>
  287. <el-col :span="12">
  288. <el-form-item label="客户等级" prop="customGrade">
  289. <!-- <el-input
  290. v-model="form.customGrade"
  291. placeholder="请输入客户等级"
  292. /> -->
  293. <el-select
  294. v-model="form.customGrade"
  295. placeholder="请选择客户等级"
  296. clearable
  297. filterable
  298. >
  299. <el-option
  300. v-for="item in dict.type.customer_level"
  301. :key="item.value"
  302. :label="item.label"
  303. :value="item.value"
  304. >
  305. </el-option>
  306. </el-select>
  307. </el-form-item>
  308. </el-col>
  309. <el-col :span="12">
  310. <el-form-item label="地址信息" prop="customAddress">
  311. <el-input
  312. v-model="form.customAddress"
  313. placeholder="请输入地址信息"
  314. />
  315. </el-form-item>
  316. </el-col>
  317. <el-col :span="12">
  318. <el-form-item label="客户国别" prop="customCountryType">
  319. <el-input
  320. v-model="form.customCountryType"
  321. placeholder="请输入客户国别"
  322. />
  323. </el-form-item>
  324. </el-col>
  325. <el-col :span="12">
  326. <el-form-item label="客户地区" prop="customDistrict">
  327. <el-input
  328. v-model="form.customDistrict"
  329. placeholder="请输入客户地区"
  330. />
  331. </el-form-item>
  332. </el-col>
  333. <el-col :span="12">
  334. <el-form-item label="销售员" prop="salesman">
  335. <el-input v-model="form.salesman" placeholder="请输入销售员" />
  336. </el-form-item>
  337. </el-col>
  338. <el-col :span="12">
  339. <el-form-item label="联系人" prop="contactPerson">
  340. <el-input
  341. v-model="form.contactPerson"
  342. placeholder="请输入联系人"
  343. />
  344. </el-form-item>
  345. </el-col>
  346. <el-col :span="12">
  347. <el-form-item label="备注" prop="remark">
  348. <el-input v-model="form.remark" placeholder="请输入备注" />
  349. </el-form-item>
  350. </el-col>
  351. </el-form>
  352. </el-row>
  353. <div slot="footer" class="dialog-footer">
  354. <el-button type="primary" @click="submitForm">确 定</el-button>
  355. <el-button @click="cancel">取 消</el-button>
  356. </div>
  357. </el-dialog>
  358. </div>
  359. </template>
  360. <script>
  361. import {
  362. listCustomer,
  363. getCustomer,
  364. delCustomer,
  365. addCustomer,
  366. updateCustomer,
  367. checkCustomerNo,
  368. } from "@/api/system/customer";
  369. import { getToken } from "@/utils/auth";
  370. export default {
  371. name: "Customer",
  372. dicts: ["customer_type", "customer_level"],
  373. data() {
  374. return {
  375. // 遮罩层
  376. loading: true,
  377. // 选中数组
  378. ids: [],
  379. // 非单个禁用
  380. single: true,
  381. // 非多个禁用
  382. multiple: true,
  383. // 显示搜索条件
  384. showSearch: true,
  385. // 总条数
  386. total: 0,
  387. // 客户表格数据
  388. customerList: [],
  389. // 弹出层标题
  390. title: "",
  391. // 是否显示弹出层
  392. open: false,
  393. //
  394. clientId:'',
  395. // 查询参数
  396. queryParams: {
  397. pageNum: 1,
  398. pageSize: 10,
  399. queryParam: "",
  400. },
  401. // 表单参数
  402. form: {},
  403. // 表单校验
  404. rules: {
  405. customName: [
  406. { required: true, message: "客户名称不能为空", trigger: "blur" },
  407. ],
  408. customNo: [
  409. { required: true, message: "客户编号不能为空", trigger: "blur" },
  410. {
  411. validator: this.checkCustomerNoHandler,
  412. trigger: "blur",
  413. },
  414. ],
  415. customPhoneNumber: [
  416. { required: true, message: "手机号不能为空", trigger: "blur" },
  417. ],
  418. },
  419. // excel共通导入数据
  420. upload: {
  421. // 是否显示弹出层
  422. open: false,
  423. // 弹出层标题(
  424. title: "",
  425. // 是否禁用上传
  426. isUploading: false,
  427. // 是否更新已经存在的数据
  428. updateSupport: 0,
  429. // 设置上传的请求头部
  430. headers: { Authorization: "Bearer " + getToken() },
  431. // 上传的地址
  432. url: process.env.VUE_APP_BASE_API1 + "system/customer/importData",
  433. },
  434. };
  435. },
  436. created() {
  437. this.getList();
  438. },
  439. methods: {
  440. generateClientId() {
  441. // 获取当前日期,格式化为YYYYMMDD
  442. const currentDate = new Date().toISOString().slice(0, 10).replace(/-/g, '');
  443. // 获取当前时间的小时和分钟,格式化为HHMM,并确保小时和分钟都是两位数
  444. const currentTime = ('0' + new Date().getHours()).slice(-2) + ('0' + new Date().getMinutes()).slice(-2);
  445. // 获取当前时间的时间戳,取最后六位
  446. const timestampSixDigits = Math.floor(Date.now() / 100).toString().slice(-5);
  447. // 拼接字符串
  448. const customId = `CN-${currentDate}${currentTime}${timestampSixDigits}`;
  449. return customId;
  450. },
  451. // 文件上传成功处理
  452. handleFileSuccess(response, file, fileList) {
  453. this.upload.open = false;
  454. this.upload.isUploading = false;
  455. this.$refs.upload.clearFiles();
  456. this.$alert(
  457. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  458. response.msg +
  459. "</div>",
  460. "导入结果",
  461. { dangerouslyUseHTMLString: true }
  462. );
  463. this.getList();
  464. },
  465. // 文件上传中处理
  466. handleFileUploadProgress(event, file, fileList) {
  467. this.upload.isUploading = true;
  468. },
  469. /** 下载模板操作 */
  470. importTemplate() {
  471. this.download(
  472. "system/customer/importTemplate",
  473. {},
  474. `customer_template_${new Date().getTime()}.xlsx`
  475. );
  476. },
  477. // 提交上传文件
  478. submitFileForm() {
  479. this.$refs.upload.submit();
  480. this.upload.open = false;
  481. this.getList();
  482. },
  483. // 校验客户编码
  484. async checkCustomerNoHandler(rule, value, callback) {
  485. try {
  486. console.log(value);
  487. let payload = {
  488. customerNo: value,
  489. };
  490. if (this.form.id) {
  491. payload.id = this.form.id;
  492. }
  493. console.log(payload);
  494. let res = await checkCustomerNo(payload);
  495. if (res.code == 200) {
  496. if (res.data) {
  497. callback();
  498. } else {
  499. callback(new Error("客户编号已存在!"));
  500. }
  501. } else {
  502. callback(new Error(res.msg));
  503. }
  504. } catch (error) {
  505. console.log(error);
  506. callback(new Error("校验失败,请稍后再试"));
  507. }
  508. },
  509. // 根据字典value获取字典label
  510. getDictLabel(value, dict) {
  511. return (
  512. this.dict.type[dict].find((item) => {
  513. return item.value === value;
  514. })?.label || ""
  515. );
  516. },
  517. /** 查询客户列表 */
  518. getList() {
  519. this.loading = true;
  520. listCustomer(this.queryParams).then((response) => {
  521. this.customerList = response.rows;
  522. this.total = response.total;
  523. this.loading = false;
  524. });
  525. },
  526. // 取消按钮
  527. cancel() {
  528. this.open = false;
  529. this.reset();
  530. },
  531. // 表单重置
  532. reset() {
  533. this.form = {
  534. id: null,
  535. customNo: null,
  536. customName: null,
  537. customPhoneNumber: null,
  538. customLandine: null,
  539. customMail: null,
  540. customType: null,
  541. customGrade: null,
  542. customAddress: null,
  543. customCountryType: null,
  544. customDistrict: null,
  545. salesman: null,
  546. contactPerson: null,
  547. remark: null,
  548. createById: null,
  549. createBy: null,
  550. createTime: null,
  551. updateById: null,
  552. updateBy: null,
  553. updateTime: null,
  554. delFlag: null,
  555. taskProcessKey: null,
  556. taskNodeKey: null,
  557. };
  558. this.resetForm("form");
  559. },
  560. /** 搜索按钮操作 */
  561. handleQuery() {
  562. this.queryParams.pageNum = 1;
  563. this.getList();
  564. },
  565. /** 重置按钮操作 */
  566. resetQuery() {
  567. this.resetForm("queryForm");
  568. this.handleQuery();
  569. },
  570. // 多选框选中数据
  571. handleSelectionChange(selection) {
  572. this.ids = selection.map((item) => item.id);
  573. this.single = selection.length !== 1;
  574. this.multiple = !selection.length;
  575. },
  576. /** 新增按钮操作 */
  577. handleAdd() {
  578. this.reset();
  579. this.open = true;
  580. this.title = "添加客户";
  581. this.form.customNo=this.generateClientId();
  582. },
  583. /** 修改按钮操作 */
  584. handleUpdate(row) {
  585. this.reset();
  586. const id = row.id || this.ids;
  587. getCustomer(id).then((response) => {
  588. this.form = response.data;
  589. this.open = true;
  590. this.title = "修改客户";
  591. });
  592. },
  593. /** 提交按钮 */
  594. submitForm() {
  595. this.$refs["form"].validate((valid) => {
  596. if (valid) {
  597. if (this.form.id != null) {
  598. updateCustomer(this.form).then((response) => {
  599. this.$modal.msgSuccess("修改成功");
  600. this.open = false;
  601. this.getList();
  602. });
  603. } else {
  604. addCustomer(this.form).then((response) => {
  605. this.$modal.msgSuccess("新增成功");
  606. this.open = false;
  607. this.getList();
  608. });
  609. }
  610. }
  611. });
  612. },
  613. /** 删除按钮操作 */
  614. handleDelete(row) {
  615. const ids = row.id || this.ids;
  616. this.$modal
  617. .confirm('是否确认删除客户编号为"' + ids + '"的数据项?')
  618. .then(function () {
  619. return delCustomer(ids);
  620. })
  621. .then(() => {
  622. this.getList();
  623. this.$modal.msgSuccess("删除成功");
  624. })
  625. .catch(() => {});
  626. },
  627. /** 导出按钮操作 */
  628. handleExport() {
  629. this.download(
  630. "system/customer/export",
  631. {
  632. ...this.queryParams,
  633. },
  634. `customer_${new Date().getTime()}.xlsx`
  635. );
  636. },
  637. },
  638. };
  639. </script>