index.vue 13 KB

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