index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="公司名称" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入公司名称"
  8. clearable
  9. size="small"
  10. style="width: 240px"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  16. <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
  17. </el-form-item>
  18. </el-form>
  19. <el-row :gutter="10" class="mb8">
  20. <el-col :span="1.5">
  21. <el-button
  22. type="primary"
  23. plain
  24. icon="el-icon-plus"
  25. size="mini"
  26. @click="handleAdd"
  27. v-hasPermi="['system:admin:add']"
  28. >新增</el-button>
  29. </el-col>
  30. </el-row>
  31. <el-table v-loading="loading" :data="adminList" >
  32. <el-table-column label="公司名称" align="center" prop="name" />
  33. <el-table-column label="公司介绍" align="center" prop="introduce"/>
  34. <el-table-column label="公司LOGO">
  35. <template width="90" slot-scope="scope" >
  36. <img style="width:120px;border:none;" :src="scope.row.logo" >
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  40. <template slot-scope="scope">
  41. <span>{{ parseTime(scope.row.createTime) }}</span>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  45. <template slot-scope="scope">
  46. <el-button
  47. size="mini"
  48. type="text"
  49. icon="el-icon-edit"
  50. @click="handleUpdate(scope.row)"
  51. v-hasPermi="['system:admin:edit']"
  52. >修改</el-button>
  53. <el-button
  54. size="mini"
  55. type="text"
  56. icon="el-icon-delete"
  57. @click="handleDelete(scope.row)"
  58. v-hasPermi="['system:admin:remove']"
  59. >删除</el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <pagination
  64. v-show="total>0"
  65. :total="total"
  66. :page.sync="queryParams.current"
  67. :limit.sync="queryParams.size"
  68. @pagination="getList"
  69. />
  70. <!-- 添加或修改参数配置对话框 -->
  71. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :before-close="cancel" :close-on-click-modal="false" >
  72. <el-form ref="form" :model="form" :rules="rules" label-width="120px" >
  73. <el-form-item label="公司名称" prop="name" >
  74. <el-input v-model="form.name" placeholder="请输入公司名称" />
  75. </el-form-item>
  76. <el-form-item label="公司介绍" prop="introduce">
  77. <el-input type="textarea" :rows="4" placeholder="请输入公司介绍" v-model="form.introduce">
  78. </el-input>
  79. </el-form-item>
  80. <el-form-item label="公司LOGO" prop="logo" ref="img">
  81. <!-- <el-checkbox-group v-model="form.logo" v-show="false"></el-checkbox-group> -->
  82. <el-upload
  83. action="#"
  84. accept="image/png,image/jpg,image/jpeg"
  85. :http-request="uploadFile"
  86. :limit = limit
  87. list-type="picture-card"
  88. :file-list="fileList"
  89. style="color:#D9D9D9"
  90. on-sucsee="handSuccess"
  91. :auto-upload="true">
  92. <i slot="default" class="el-icon-plus"></i>
  93. <div slot="file" slot-scope="{file}">
  94. <img class="el-upload-list__item-thumbnail imgupload" :src="file.url" alt="" >
  95. <span class="el-upload-list__item-actions">
  96. <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
  97. <i class="el-icon-delete"></i>
  98. </span>
  99. </span>
  100. </div>
  101. </el-upload>
  102. <el-dialog :visible.sync="dialogVisible" >
  103. <img width="100%" :src="dialogImageUrl" alt="">
  104. </el-dialog>
  105. </el-form-item>
  106. </el-form>
  107. <div slot="footer" class="dialog-footer">
  108. <el-button type="primary" @click="submitForm" v-if="!loading">确 定</el-button>
  109. <el-button :loading="loading" type="primary" @click="submitForm" v-else>提交中...</el-button>
  110. <el-button @click="cancel">取 消</el-button>
  111. </div>
  112. </el-dialog>
  113. </div>
  114. </template>
  115. <script>
  116. import { addChannel, updataChannel, delChannel, listChannel, fileId, uploadFileApi, fileTakeEffect, getFile } from "@/api/system/product";
  117. export default {
  118. name: "admin",
  119. data() {
  120. return {
  121. // 遮罩层
  122. loading: true,
  123. // 导出遮罩层
  124. exportLoading: false,
  125. dialogFormVisible:false,
  126. // 选中数组
  127. ids: [],
  128. // 非单个禁用
  129. single: true,
  130. // 非多个禁用
  131. multiple: true,
  132. // 显示搜索条件
  133. showSearch: true,
  134. // 总条数
  135. total: 0,
  136. // 图片显示
  137. fileList:[{"url":''}],
  138. // 参数表格数据
  139. adminList: [],
  140. // 弹出层标题
  141. title: "",
  142. // 是否显示弹出层
  143. open: false,
  144. // 类型数据字典
  145. typeOptions: [],
  146. // 日期范围
  147. dateRange: [],
  148. // 查询参数
  149. queryParams: {
  150. current: 1,
  151. size: 10,
  152. name: undefined,
  153. aliasName: undefined,
  154. },
  155. // 表单参数
  156. form: {
  157. id:'',
  158. name:'',
  159. introduce:'',
  160. logo:"",
  161. batchNo:undefined,
  162. businessType:"产品logo",
  163. uploadType:"file"
  164. },
  165. // 表单校验
  166. rules: {
  167. name: [
  168. { required: true, message: "公司名称不能为空", trigger: "blur" }
  169. ],
  170. logo: [
  171. { required: true, message: "公司logo不能为空", trigger: "change" }
  172. ],
  173. },
  174. // 上传图片
  175. dialogImageUrl: '',
  176. dialogVisible: false,
  177. disabled: false,
  178. imageInfo: {},
  179. imageList: [],
  180. formInline: {
  181. image64: "",
  182. imageName: "",
  183. },
  184. formData:undefined,
  185. limit:100,
  186. };
  187. },
  188. created() {
  189. this.getList();
  190. },
  191. methods: {
  192. handleRemove(file) {
  193. this.form.logo = undefined
  194. // this.$nextTick(() => {
  195. // this.$refs['form'].clearValidate(['logo']);
  196. // })
  197. this.limit = 100
  198. document.getElementsByClassName("el-upload-list el-upload-list--picture-card")[0].firstChild.remove()
  199. document.getElementsByClassName("el-upload--picture-card")[0].style.display="block"
  200. },
  201. /** 查询参数列表 */
  202. getList() {
  203. this.loading = true;
  204. listChannel(this.addDateRange(this.queryParams)).then(response => {
  205. if(response.data.records.length>0){
  206. let arrBig = response.data.records
  207. let arr = []
  208. arr = response.data.records.map(item =>{
  209. return {
  210. batchNos:[item.logo]
  211. }
  212. })
  213. for(let i=1;i<response.data.records.length; i++){
  214. arr[0].batchNos.push(response.data.records[i].logo)
  215. }
  216. getFile(arr[0]).then(response =>{
  217. const reverse = response.data.reverse()
  218. for(let i=0;i<response.data.length;i++){
  219. arrBig[i].logo = reverse[i].url
  220. }
  221. })
  222. setTimeout(()=>{
  223. this.loading = false;
  224. this.adminList = arrBig;
  225. this.total = response.data.total;
  226. this.logo = arrBig.logo;
  227. },1000)
  228. }else{
  229. this.adminList = []
  230. this.loading = false;
  231. }
  232. })
  233. },
  234. // 移出图片
  235. removeImg(){
  236. this.form.logo = undefined
  237. setTimeout(()=>{
  238. this.limit = 100
  239. this.fileList=[]
  240. },1000)
  241. },
  242. // 取消按钮
  243. cancel() {
  244. this.open = false;
  245. this.reset();
  246. },
  247. // 表单重置
  248. reset() {
  249. this.form = {
  250. ids: undefined,
  251. name: undefined,
  252. aliasName: undefined,
  253. adminType: "Y",
  254. };
  255. this.fileList=[]
  256. this.resetForm("form");
  257. },
  258. /** 搜索按钮操作 */
  259. handleQuery() {
  260. this.queryParams.current = 1;
  261. this.getList();
  262. },
  263. /** 重置按钮操作 */
  264. resetQuery() {
  265. this.dateRange = [];
  266. this.resetForm("queryForm");
  267. this.handleQuery();
  268. },
  269. /** 新增按钮操作 */
  270. handleAdd() {
  271. this.form.id =undefined
  272. this.form.name =undefined
  273. this.form.introduce =undefined
  274. this.form.logo =undefined
  275. this.form.batchNo =undefined
  276. this.reset();
  277. this.open = true;
  278. this.title = "添加参数";
  279. setTimeout(()=>{
  280. document.getElementsByClassName("el-upload--picture-card")[0].style.display="block"
  281. },200)
  282. },
  283. // 多选框选中数据
  284. handleSelectionChange(selection) {
  285. this.ids = selection.map(item => item.id)
  286. this.single = selection.length!=1
  287. this.multiple = !selection.length
  288. },
  289. /** 修改按钮操作 */
  290. handleUpdate(row) {
  291. this.reset();
  292. Object.assign(this.form, row.id ? this.adminList.find(val=>val.id === row.id) : this.adminList.find(val=>val.id === this.ids[0]))
  293. this.open = true;
  294. this.title = "修改参数";
  295. setTimeout(() =>{
  296. if(this.fileList.length>0){
  297. }else{
  298. this.fileList.push([])
  299. this.fileList[0].url = row.logo
  300. }
  301. document.getElementsByClassName("el-upload--picture-card")[0].style.display="none"
  302. },100)
  303. this.limit = 1
  304. // });
  305. },
  306. // 图片上传尺寸大小检验
  307. beforeUpload (file) {
  308. const is1M = file.size / 1024 < 70; // 限制小于70kb
  309. const isSize = new Promise(function (resolve, reject) {
  310. let width = 1024; // 限制图片尺寸为1024X240
  311. let height = 640;
  312. let _URL = window.URL || window.webkitURL;
  313. let img = new Image();
  314. img.onload = function () {
  315. let valid = img.width === width && img.height === height;
  316. valid ? resolve() : reject();
  317. }
  318. img.src = _URL.createObjectURL(file);
  319. }).then(() => {
  320. return file;
  321. }, () => {
  322. this.$message.error('图片尺寸限制为1024 x 240,大小不可超过70kB')
  323. return Promise.reject();
  324. });
  325. // if (!is1M) {
  326. // this.$message.error('图片尺寸限制为1024 x 240,大小不可超过70kB')
  327. // }
  328. // return isSize&is1M
  329. },
  330. // 图片 转base64
  331. getBase64(file) {
  332. return new Promise(function (resolve, reject) {
  333. let reader = new FileReader();
  334. let imgResult = "";
  335. reader.readAsDataURL(file);
  336. reader.onload = function () {
  337. imgResult = reader.result;
  338. };
  339. reader.onerror = function (error) {
  340. reject(error);
  341. };
  342. reader.onloadend = function () {
  343. resolve(imgResult);
  344. };
  345. });
  346. },
  347. uploadFile(param){
  348. this.limit = 1
  349. document.getElementsByClassName("el-upload--picture-card")[0].style.display="none"
  350. fileId().then(res=>{
  351. this.$nextTick(() => {
  352. this.$refs['form'].clearValidate(['logo']);
  353. })
  354. this.form.batchNo = res.msg
  355. this.form.logo = res.msg
  356. this.formData = new FormData()// FormData 对象
  357. this.formData.append('files', param.file)// 文件对象
  358. })
  359. },
  360. handSuccess(){
  361. this.$refs.img.clearValidate();
  362. },
  363. //变化设置图片
  364. onChange(file, fileList) {
  365. this.form.file = fileList;
  366. },
  367. /** 提交按钮 */
  368. submitForm(row) {
  369. if(this.form.logo){
  370. }else{
  371. this.$refs.img.clearValidate();
  372. }
  373. this.$refs["form"].validate(valid => {
  374. if (valid) {
  375. this.loading = true
  376. // 上传图片
  377. uploadFileApi(this.form.batchNo,this.form.businessType,this.formData).then(response => {
  378. if(response.data.length>0){
  379. let ids = new FormData()
  380. ids.append('ids[]', response.data[0].id)
  381. // 上传图片生效
  382. fileTakeEffect(response.data[0].batchNo,ids).then(response => {
  383. // this.msgSuccess("上传成功");
  384. if (this.form.id != undefined) {
  385. updataChannel(this.form).then(response => {
  386. this.loading = false,
  387. this.msgSuccess("修改成功");
  388. this.open = false;
  389. this.getList();
  390. }).catch(()=>{
  391. this.loading = false,
  392. this.open = false
  393. })
  394. } else {
  395. addChannel(this.form).then(response => {
  396. this.loading = false,
  397. this.msgSuccess("新增成功");
  398. this.open = false;
  399. this.getList();
  400. }).catch(()=>{
  401. this.loading = false,
  402. this.open = false
  403. })
  404. }
  405. }).catch(err =>{
  406. })
  407. }
  408. })
  409. .catch((e) => {
  410. this.$message.error('上传失败')
  411. this.getList();
  412. })
  413. // this.removeImg()
  414. }
  415. });
  416. },
  417. /** 删除按钮操作 */
  418. handleDelete(row) {
  419. const ids = row.id || this.ids;
  420. this.$confirm('是否确认删除', "警告", {
  421. confirmButtonText: "确定",
  422. cancelButtonText: "取消",
  423. type: "warning"
  424. }).then(function() {
  425. return delChannel(ids);
  426. }).then(() => {
  427. this.getList();
  428. this.msgSuccess("删除成功");
  429. }).catch(() => {});
  430. },
  431. /** 刷新缓存按钮操作 */
  432. handleRefreshCache() {
  433. refreshCache().then(() => {
  434. this.msgSuccess("刷新成功");
  435. });
  436. }
  437. }
  438. };
  439. </script>
  440. <style lang="scss" scoped>
  441. // .el-button--primary{color:#50B300;border:1px solid #50B300;background: #fff;}
  442. // .el-button--primary:hover{color:#fff;border:1px solid #50B300;background: #50B300;}
  443. </style>