index.vue 12 KB

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