list.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item :label="$t('clientlist')">
  7. </el-form-item>
  8. <el-form-item >
  9. <div>
  10. <el-input style="float:left;" v-model="keyword" class="input-with-select" :placeholder="$t('pleaseenterthecustomernamekeyword')" @keyup.enter.native="searchList()" clearable="true">
  11. <el-button slot="append" @click="searchList" icon="el-icon-search"></el-button>
  12. </el-input>
  13. </div>
  14. </el-form-item>
  15. <el-form-item style="float:right;">
  16. <el-link type="primary" :underline="false" @click="handleAdd(-1,null)">{{ $t('newcustomer') }}</el-link>
  17. <el-link type="primary" :underline="false" @click="intocustomerRatio">{{ $t('importingCustomersinBatches') }}</el-link>
  18. <el-link type="primary" :underline="false" @click="exportData()">{{ $t('export.export') }}</el-link>
  19. </el-form-item>
  20. </el-form>
  21. </el-col>
  22. <!--列表-->
  23. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;" @selection-change="selectionChange" @sort-change="tableSort">
  24. <el-table-column type="selection" width="60">
  25. <!-- <template slot-scope="scope" >
  26. {{scope.$index+1+(page-1)*size}}
  27. </template> -->
  28. </el-table-column>
  29. <el-table-column prop="customerCode" :label="$t('clientcode')" width="160" sortable="custom"></el-table-column>
  30. <el-table-column prop="customerName" :label="$t('customername')" >
  31. </el-table-column>
  32. <el-table-column prop="contactName" :label="$t('contact')" width="120">
  33. </el-table-column>
  34. <el-table-column prop="contactPhone" :label="$t('contactphonenumber')" width="150">
  35. </el-table-column>
  36. <el-table-column prop="email" :label="$t('email')" width="180">
  37. </el-table-column>
  38. <el-table-column prop="address" :label="$t('address')" sortable="custom">
  39. </el-table-column>
  40. <el-table-column :label="$t('operation')" width="150">
  41. <template slot-scope="scope">
  42. <el-button size="mini" type="primary" @click="handleAdd(scope.$index, scope.row)">{{ $t('bian-ji') }}</el-button>
  43. <el-button size="mini" @click="deletePro(scope.$index, scope.row)">{{ $t('btn.delete') }}</el-button>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <!--工具条-->
  48. <el-col :span="24" class="toolbar">
  49. <el-button type="primary" size="small" @click="batchDelete" :loading="delLoading">{{ $t('Batchdelete') }}</el-button>
  50. <el-pagination
  51. @size-change="handleSizeChange"
  52. @current-change="handleCurrentChange"
  53. :page-sizes="[20 , 50 , 80 , 100]"
  54. :page-size="20"
  55. layout="total, sizes, prev, pager, next"
  56. :total="total"
  57. style="float:right;"
  58. ></el-pagination>
  59. </el-col>
  60. <!--新增界面-->
  61. <el-dialog :title="title" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth" width="800px">
  62. <el-form ref="form1" :model="addForm" :rules="rules" label-width="120px">
  63. <el-form-item :label="$t('ustomernumber')" >
  64. <el-input v-model="addForm.customerCode" :max="20" :placeholder="$t('peaseenterthe')" clearable></el-input>
  65. </el-form-item>
  66. <el-form-item :label="$t('customername')" prop="customerName">
  67. <el-input v-model="addForm.customerName" :max="20" :placeholder="$t('peaseenterthe')" clearable></el-input>
  68. </el-form-item>
  69. <el-form-item :label="$t('contact')" prop="contactName">
  70. <el-input v-model="addForm.contactName" :max="20" :placeholder="$t('peaseenterthe')" clearable></el-input>
  71. </el-form-item>
  72. <el-form-item :label="$t('contactphonenumber')" prop="contactPhone">
  73. <el-input v-model="addForm.contactPhone" :max="20" :placeholder="$t('peaseenterthe')" clearable></el-input>
  74. </el-form-item>
  75. <el-form-item :label="$t('email')" prop="email">
  76. <el-input v-model="addForm.email" :max="25" :placeholder="$t('peaseenterthe')" clearable></el-input>
  77. </el-form-item>
  78. <el-form-item :label="$t('address')" prop="address">
  79. <el-input v-model="addForm.address" :max="50" :placeholder="$t('peaseenterthe')" clearable></el-input>
  80. </el-form-item>
  81. </el-form>
  82. <div slot="footer" class="dialog-footer;">
  83. <el-button @click.native="addFormVisible = false">{{ $t('btn.cancel') }}</el-button>
  84. <el-button type="primary" @click="submitInsert" :loading="addLoading">{{ $t('btn.submit') }}</el-button>
  85. </div>
  86. </el-dialog>
  87. <!-- 导入结果说明 -->
  88. <el-dialog :title="$t('importingtheallocationratio')" v-if="showImportResult" :visible.sync="showImportResult" customClass="customWidth" width="500px">
  89. <div>
  90. <span>{{importResultMsg}}</span>
  91. </div>
  92. <span slot="footer" class="dialog-footer">
  93. <el-button type="primary" @click="showImportResult=false">{{ $t('btn.determine') }}</el-button>
  94. </span>
  95. </el-dialog>
  96. <el-dialog :title="$t('importingCustomerData')" v-if="intocustomerDialog" :visible.sync="intocustomerDialog" customClass="customWidth" width="500px">
  97. <p>1. {{ $t('other.download') }}
  98. <el-link type="primary" style="margin-left:5px;" :underline="false" :href="'./upload/'+$t('customerimporttemplatisadded')+'.xlsx'" :download="$t('customerimporttemplatisadded')+'.xlsx'">{{$t('customerimporttemplatisadded')}}.xlsx</el-link>
  99. </p>
  100. <!-- <p>2. 填写excel模板,请确保模板中的项目和人员已添加到系统中。</p> -->
  101. <p style="display: flex;justify-content: center;padding:1em 0">
  102. <el-upload ref="upload" action="#" :limit="1" :http-request="batchImportData" :show-file-list="false">
  103. <el-button type="primary" :underline="false" :loading="importingData">{{ $t('other.startImporting') }}</el-button>
  104. </el-upload>
  105. </p>
  106. </el-dialog>
  107. </section>
  108. </template>
  109. <style scoped>
  110. .input-with-select .el-input-group__prepend {
  111. background-color: #fff;
  112. }
  113. .line {
  114. padding:10px;
  115. }
  116. .line span{
  117. font-size:15px;
  118. }
  119. .line span:nth-child(even){
  120. float:right;
  121. }
  122. </style>
  123. <script>
  124. import util from "../../common/js/util";
  125. export default {
  126. data() {
  127. return {
  128. roleArray:[this.$t('role.ordinaryEmployees'),this.$t('role.superAdministrator'), this.$t('role.systemAdministrator'), this.$t('role.companyTop'),this.$t('role.financialAdministrator'), this.$t('role.projectManager')],
  129. status:null,
  130. statusTxt:["-",this.$t('ongoing'),this.$t('state.completed'),this.$t('state.undone')],
  131. importanceList:[{id:1,label:this.$t('zheng-chang')},{id:2,label:this.$t('jin-ji')},{id:3,label:this.$t('zhong-yao')},{id:4,label:this.$t('zhong-yao-qie-jin-ji')}],
  132. searchField:null,
  133. keyword:null,
  134. user: JSON.parse(sessionStorage.getItem("user")),
  135. userDetailVisible: false,
  136. userDetail:{},
  137. date: new Date(),
  138. users: [],
  139. participator:[],
  140. tableHeight: 0,
  141. listLoading: false,
  142. total: 0,
  143. page: 1,
  144. size: 20,
  145. list: [],
  146. subProjectVisible: false,
  147. subProjectList: [],//子项目列表
  148. currentProject:{},
  149. addSubProject: false,
  150. addFormVisible: false,
  151. addLoading: false,
  152. addUp: 0, // 合计
  153. title: "",
  154. addForm: {
  155. name: '',
  156. userId: [],
  157. level:1,
  158. },
  159. rules: {
  160. customerName: [{ required: true, message: this.$t('pleaseenterthecustomername'), trigger: "blur" }],
  161. },
  162. intocustomerDialog:false,
  163. importingData: false,
  164. importResultMsg:null,
  165. showImportResult:false,
  166. selectArr: [],
  167. delLoading: false,
  168. sortOrder: null,
  169. sortProp: ''
  170. };
  171. },
  172. // 过滤器
  173. filters: {
  174. numberToCurrency(value) {
  175. if (!value) return '0.00'
  176. // 将数值截取,保留两位小数
  177. value = value.toFixed(2)
  178. // 获取整数部分
  179. const intPart = Math.trunc(value)
  180. // 整数部分处理,增加,
  181. const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
  182. // 预定义小数部分
  183. let floatPart = '.00'
  184. // 将数值截取为小数部分和整数部分
  185. const valueArray = value.toString().split('.')
  186. if (valueArray.length === 2) { // 有小数部分
  187. floatPart = valueArray[1].toString() // 取得小数部分
  188. return intPartFormat + '.' + floatPart
  189. }
  190. return intPartFormat + floatPart
  191. }
  192. },
  193. methods: {
  194. // 批量删除
  195. selectionChange(selection){
  196. console.log('sel',selection);
  197. this.selectArr = selection
  198. },
  199. batchDelete(){
  200. if(this.selectArr.length == 0){
  201. this.$message(this.$t('selecttheustomerdatayouwanttodelete'))
  202. return
  203. }else{
  204. let nametext = ''
  205. for(let i in this.selectArr){
  206. nametext += this.selectArr[i].customerName + '、'
  207. }
  208. nametext = nametext.substring(0,nametext.length - 1)
  209. this.$confirm(this.$t('determinethatyouwantodelete') +":" + nametext + "\u3000"+this.$t('ma')+"?",this.$t('deleteCustomer'), {
  210. confirmButtonText: this.$t('btn.determine'),
  211. cancelButtonText: this.$t('btn.cancel'),
  212. type: "warning"
  213. }).then(()=>{
  214. this.delLoading = true
  215. let batchIds = ''
  216. for(let m in this.selectArr){
  217. batchIds += this.selectArr[m].id + ','
  218. }
  219. batchIds = batchIds.substring(0,batchIds.length - 1)
  220. this.http.post('/customer-info/batchDelete',{
  221. batchIds
  222. },res => {
  223. this.delLoading = false
  224. if(res.code == 'ok'){
  225. this.$message({
  226. message: this.$t('message.successfullyDeleted'),
  227. type: 'success'
  228. })
  229. this.getList()
  230. }else {
  231. this.$message({
  232. message: res.msg,
  233. type: 'error'
  234. })
  235. }
  236. },err => {
  237. this.delLoading = false
  238. this.$message({
  239. message: res.msg,
  240. type: 'error'
  241. })
  242. })
  243. })
  244. }
  245. },
  246. intocustomerRatio(){
  247. this.intocustomerDialog=true;
  248. },
  249. batchImportData(item) {
  250. //首先判断文件类型
  251. let str = item.file.name.split(".");
  252. let format = str[str.length - 1];
  253. if (format != "xls" && format != "xlsx") {
  254. this.$message({
  255. message: this.$t('other.PleaseselecttheXLSorXLSXfile'),
  256. type: "error"
  257. });
  258. } else {
  259. this.importingData = true;
  260. let formData = new FormData();
  261. formData.append("file", item.file);
  262. this.http.uploadFile('/customer-info/importData', formData,
  263. res => {
  264. this.$refs.upload.clearFiles();
  265. this.importingData = false;
  266. this.showImportResult = true;
  267. if (res.code == "ok") {
  268. //换成弹出框,以免有人等了半天回来啥也没看到
  269. this.importResultMsg = this.$t('importedupdatedsuccessfully')+res.data+this.$t('customerdata')+(res.msg?res.msg:"");
  270. this.getList();
  271. } else {
  272. this.importResultMsg = this.$t('export.Importfailure')+":"+res.msg;
  273. }
  274. },
  275. error => {
  276. this.$refs.upload.clearFiles();
  277. this.importingData = false;
  278. this.$message({
  279. message: error,
  280. type: "error"
  281. });
  282. });
  283. }
  284. },
  285. importProject(item) {
  286. //首先判断文件类型
  287. let str = item.file.name.split(".");
  288. let format = str[str.length - 1];
  289. if (format != "xls" && format != "xlsx") {
  290. this.$message({
  291. message: this.$t('other.PleaseselecttheXLSorXLSXfile'),
  292. type: "error"
  293. });
  294. } else {
  295. this.listLoading = true;
  296. let formData = new FormData();
  297. formData.append("file", item.file);
  298. formData.append("userId", this.user.id);
  299. this.http.uploadFile('/project/importData', formData,
  300. res => {
  301. this.$refs.upload.clearFiles();
  302. this.listLoading = false;
  303. if (res.code == "ok") {
  304. this.$message({
  305. message: this.$t('other.importSuccess'),
  306. type: "success"
  307. });
  308. this.getList();
  309. } else {
  310. this.$message({
  311. message: res.msg,
  312. type: "error"
  313. });
  314. }
  315. },
  316. error => {
  317. this.$refs.upload.clearFiles();
  318. this.listLoading = false;
  319. this.$message({
  320. message: error,
  321. type: "error"
  322. });
  323. });
  324. }
  325. },
  326. number(){
  327. //     this.addForm.budget = this.addForm.budget.replace(/[^\.\d]/g,'');
  328. // this.addForm.budget = this.addForm.budget.replace('.','');
  329. },
  330. deleteSubPro(subProject) {
  331. this.$confirm(this.$t('makesuretodeletethesubproject') + subProject.name + this.$t('ma'),this.$t('deletesubproject'), {
  332. confirmButtonText: this.$t('btn.determine'),
  333. cancelButtonText: this.$t('btn.cancel'),
  334. type: "warning"
  335. })
  336. .then(() => {
  337. this.listLoading = true;
  338. this.http.post('/sub-project/deleteProject',{
  339. id: subProject.id
  340. },
  341. res => {
  342. this.listLoading = false;
  343. if (res.code == "ok") {
  344. this.$message({
  345. message: this.$t('message.successfullyDeleted'),
  346. type: "success"
  347. });
  348. this.subProject(this.currentProject);
  349. } else {
  350. this.$message({
  351. message: res.msg,
  352. type: "error"
  353. });
  354. }
  355. },
  356. error => {
  357. this.listLoading = false;
  358. this.$message({
  359. message: error,
  360. type: "error"
  361. });
  362. }
  363. );
  364. })
  365. .catch(() => {});
  366. },
  367. searchList() {
  368. this.page = 1;
  369. this.getList();
  370. },
  371. addNewSubProject(subProject) {
  372. console.log(123);
  373. if (subProject == null) {
  374. this.addForm = {projectId: this.currentProject.id, level:1}
  375. } else {
  376. this.addForm = subProject;
  377. }
  378. this.addSubProject = true;
  379. },
  380. //显示子项目
  381. subProject(item) {
  382. this.subProjectVisible = true;
  383. this.currentProject = item;
  384. this.http.post('/sub-project/list', {
  385. projectId: item.id
  386. },
  387. res => {
  388. if (res.code == "ok") {
  389. this.subProjectList = res.data;
  390. } else {
  391. this.$message({
  392. message: res.msg,
  393. type: "error"
  394. });
  395. }
  396. },
  397. error => {
  398. this.$message({
  399. message: error,
  400. type: "error"
  401. });
  402. });
  403. },
  404. //显示用户详情
  405. showUser(userId) {
  406. this.userDetailVisible = true;
  407. this.http.post(this.port.manage.userDetail, {
  408. userId: userId
  409. },
  410. res => {
  411. if (res.code == "ok") {
  412. this.userDetail = res.data;
  413. } else {
  414. this.$message({
  415. message: res.msg,
  416. type: "error"
  417. });
  418. }
  419. },
  420. error => {
  421. this.$message({
  422. message: error,
  423. type: "error"
  424. });
  425. });
  426. },
  427. //分页
  428. handleCurrentChange(val) {
  429. this.page = val;
  430. this.getList();
  431. },
  432. handleSizeChange(val) {
  433. this.size = val;
  434. this.getList();
  435. },
  436. tableSort({column, prop, order}){
  437. if(prop == 'customerCode' || prop == 'address'){
  438. this.sortOrder = order
  439. this.sortProp = prop
  440. this.getList()
  441. }
  442. },
  443. //获取项目列表
  444. getList() {
  445. this.listLoading = true;
  446. let parameter = {
  447. pageIndex: this.page,
  448. pageSize: this.size,
  449. keyword:this.keyword
  450. }
  451. if(this.sortOrder){
  452. if(this.sortProp == 'customerCode'){
  453. parameter.sortProp = 'customer_code'
  454. }else if(this.sortProp == 'address'){
  455. parameter.sortProp = 'address'
  456. }
  457. if(this.sortOrder == 'descending'){
  458. parameter.sortOrder = 0
  459. }else if(this.sortOrder == 'ascending'){
  460. parameter.sortOrder = 1
  461. }
  462. }
  463. this.http.post('/customer-info/list', parameter,
  464. res => {
  465. this.listLoading = false;
  466. if (res.code == "ok") {
  467. var list = res.data.records;
  468. this.list = list;
  469. this.total = res.data.total;
  470. } else {
  471. this.$message({
  472. message: res.msg,
  473. type: "error"
  474. });
  475. }
  476. },
  477. error => {
  478. this.listLoading = false;
  479. this.$message({
  480. message: error,
  481. type: "error"
  482. });
  483. });
  484. },
  485. //显示新增界面
  486. handleAdd(i, item) {
  487. if(i == -1) {
  488. this.title = this.$t('newcustomer');
  489. this.addForm = {
  490. }
  491. } else {
  492. this.title = this.$t('modifythecustomer');
  493. this.addForm = JSON.parse(JSON.stringify(item));
  494. }
  495. this.addFormVisible = true;
  496. },
  497. submitInsert() {
  498. this.$refs.form1.validate(valid => {
  499. if (valid) {
  500. this.addLoading = true;
  501. this.http.post('/customer-info/addOrMod', this.addForm,
  502. res => {
  503. this.addLoading = false;
  504. if (res.code == "ok") {
  505. this.addFormVisible = false;
  506. this.getList();
  507. } else {
  508. this.$message({
  509. message: res.msg,
  510. type: "error"
  511. });
  512. }
  513. },
  514. error => {
  515. this.addLoading = false;
  516. this.$message({
  517. message: error,
  518. type: "error"
  519. });
  520. });
  521. }
  522. });
  523. },
  524. // 删除
  525. deletePro(i, item) {
  526. this.$confirm(this.$t('makeuretodeletethecustomer') + item.customerName + this.$t('ma'),this.$t('deleteCustomer'), {
  527. confirmButtonText: this.$t('btn.determine'),
  528. cancelButtonText: this.$t('btn.cancel'),
  529. type: "warning"
  530. })
  531. .then(() => {
  532. this.listLoading = true;
  533. this.http.post('/customer-info/delete',{
  534. id: item.id
  535. },
  536. res => {
  537. this.listLoading = false;
  538. if (res.code == "ok") {
  539. this.$message({
  540. message: this.$t('message.successfullyDeleted'),
  541. type: "success"
  542. });
  543. this.getList();
  544. } else {
  545. this.$message({
  546. message: res.msg,
  547. type: "error"
  548. });
  549. }
  550. },
  551. error => {
  552. this.listLoading = false;
  553. this.$message({
  554. message: error,
  555. type: "error"
  556. });
  557. }
  558. );
  559. })
  560. .catch(() => {});
  561. },
  562. exportData(){
  563. this.http.post('/customer-info/exportData', {},
  564. res => {
  565. if (res.code == "ok") {
  566. var filePath = res.data;
  567. const a = document.createElement('a'); // 创建a标签
  568. a.setAttribute('download', this.$t('keHuLieBiaoXlsx'));// download属性
  569. a.setAttribute('href', filePath);// href链接
  570. a.click(); //自执行点击事件
  571. a.remove();
  572. } else {
  573. this.$message({
  574. message: res.msg,
  575. type: "error"
  576. });
  577. }
  578. },
  579. error => {
  580. this.$message({
  581. message: error,
  582. type: "error"
  583. });
  584. });
  585. },
  586. },
  587. created() {
  588. let height = window.innerHeight;
  589. this.tableHeight = height - 195;
  590. const that = this;
  591. window.onresize = function temp() {
  592. that.tableHeight = window.innerHeight - 195;
  593. };
  594. },
  595. mounted() {
  596. this.getList();
  597. }
  598. };
  599. </script>
  600. <style lang="scss" scoped>
  601. .rg_span{
  602. display: inline-block;
  603. }
  604. .rg_span span {
  605. text-align: right;
  606. box-sizing: border-box;
  607. padding-right: 10px;
  608. }
  609. .el-dialog__title {
  610. display: inline-table;
  611. margin-top: 20px;
  612. }
  613. </style>