provider.vue 24 KB

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