index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <div>
  3. <basic-container v-if="!basic">
  4. <avue-crud :data="data" ref="crud" :option="option" :key="key" @resetColumn="resetColumn"
  5. @saveColumn="saveColumn">
  6. <template slot="menuLeft">
  7. <el-button type="primary" size="small" icon="el-icon-edit" @click="addDetail" :disabled="disabled"
  8. v-if="display">上传
  9. </el-button>
  10. <slot name="c_button"></slot>
  11. </template>
  12. <template slot="url" slot-scope="{ row }">
  13. <el-input placeholder="请输入内容" size="small" v-if="row.$cellEdit" v-model="row.url" class="input-with-select">
  14. <el-button slot="append" @click="singleLineUpload(row)">附件</el-button>
  15. </el-input>
  16. <span v-else>{{ row.url }}</span>
  17. </template>
  18. <template slot-scope="scope" slot="menu">
  19. <el-button icon="el-icon-download" :size="scope.size" :type="scope.type" @click="download(scope)">查看
  20. </el-button>
  21. <el-button :type="scope.type" :size="scope.size" icon="el-icon-edit"
  22. @click.stop="rowCell(scope.row, scope.index)" :disabled="disabled">
  23. {{ scope.row.$cellEdit ? "保存" : "修改" }}
  24. </el-button>
  25. <el-button :type="scope.type" :size="scope.size" icon="el-icon-delete"
  26. @click.stop="rowDel(scope.row, scope.index)" :disabled="disabled">删除
  27. </el-button>
  28. </template>
  29. </avue-crud>
  30. <el-dialog title="上传附件" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false"
  31. v-dialog-drag>
  32. <el-upload class="upload-demo" drag style="text-align: center" ref="upload"
  33. :action="incomingAction ? incomingAction : action" :headers="headers" :on-success="onSuccess" multiple
  34. :before-upload="beforeUpload">
  35. <i class="el-icon-upload"></i>
  36. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  37. <div class="el-upload__tip" slot="tip">
  38. 如上传文件过大,请耐心等待上传成功
  39. </div>
  40. </el-upload>
  41. </el-dialog>
  42. <el-dialog title="修改附件" append-to-body :visible.sync="excelTwo" width="555px" :close-on-click-modal="false"
  43. v-dialog-drag>
  44. <el-upload class="upload-demo" drag style="text-align: center"
  45. :action="incomingAction ? incomingAction : action" :headers="headers" :show-file-list="false"
  46. :on-success="onSuccessTwo" :before-upload="beforeUpload">
  47. <i class="el-icon-upload"></i>
  48. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  49. <div class="el-upload__tip" slot="tip">
  50. 如上传文件过大,请耐心等待上传成功
  51. </div>
  52. </el-upload>
  53. </el-dialog>
  54. <el-dialog width="80%" title="附件" :visible.sync="innerVisible" :close-on-click-modal="false" append-to-body>
  55. <div style="width: 50%;height: 50%;margin: 0 auto">
  56. <img :src="imgUrl" alt="" style="width: 100%;height: 100%;" />
  57. </div>
  58. </el-dialog>
  59. </basic-container>
  60. <span v-else-if="true">
  61. <avue-crud :data="data" ref="crud" :option="option" :key="key" @resetColumn="resetColumn"
  62. @saveColumn="saveColumn">
  63. <template slot="menuLeft">
  64. <el-button type="primary" size="small" icon="el-icon-edit" @click="addDetail" :disabled="disabled">上传
  65. </el-button>
  66. </template>
  67. <template slot="url" slot-scope="{ row }">
  68. <el-input placeholder="请输入内容" size="small" v-if="row.$cellEdit" v-model="row.url" class="input-with-select">
  69. <el-button slot="append" @click="singleLineUpload(row)">附件</el-button>
  70. </el-input>
  71. <span v-else>{{ row.url }}</span>
  72. </template>
  73. <template slot-scope="scope" slot="menu">
  74. <el-button icon="el-icon-download" :size="scope.size" :type="scope.type" @click="download(scope)">查看
  75. </el-button>
  76. <el-button :type="scope.type" :size="scope.size" icon="el-icon-edit"
  77. @click.stop="rowCell(scope.row, scope.index)" :disabled="disabled">
  78. {{ scope.row.$cellEdit ? "保存" : "修改" }}
  79. </el-button>
  80. <el-button :type="scope.type" :size="scope.size" icon="el-icon-delete"
  81. @click.stop="rowDel(scope.row, scope.index)" :disabled="disabled">删除
  82. </el-button>
  83. </template>
  84. </avue-crud>
  85. <el-dialog title="上传附件" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false"
  86. v-dialog-drag>
  87. <el-upload class="upload-demo" drag style="text-align: center" ref="upload" :action="action" :headers="headers"
  88. :on-success="onSuccess" multiple :before-upload="beforeUpload">
  89. <i class="el-icon-upload"></i>
  90. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  91. <div class="el-upload__tip" slot="tip">
  92. 如上传文件过大,请耐心等待上传成功
  93. </div>
  94. </el-upload>
  95. </el-dialog>
  96. <el-dialog title="修改附件" append-to-body :visible.sync="excelTwo" width="555px" :close-on-click-modal="false"
  97. v-dialog-drag>
  98. <el-upload class="upload-demo" drag style="text-align: center"
  99. :action="incomingAction ? incomingAction : action" :headers="headers" :show-file-list="false"
  100. :on-success="onSuccessTwo" :before-upload="beforeUpload">
  101. <i class="el-icon-upload"></i>
  102. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  103. <div class="el-upload__tip" slot="tip">
  104. 如上传文件过大,请耐心等待上传成功
  105. </div>
  106. </el-upload>
  107. </el-dialog>
  108. <el-dialog width="80%" title="附件" :visible.sync="innerVisible" :close-on-click-modal="false" append-to-body>
  109. <div style="width: 50%;height: 50%;margin: 0 auto">
  110. <img :src="imgUrl" alt="" style="width: 100%;height: 100%;" />
  111. </div>
  112. </el-dialog>
  113. </span>
  114. </div>
  115. </template>
  116. <script>
  117. import { getToken } from "@/util/auth";
  118. import { LTfujianDelete, sharedDeletion } from "@/api/user";
  119. import option from "@/views/exportTrade/customerInquiry/config/mainList.json";
  120. import { gainUser } from "@/api/basicData/customerInquiry";
  121. import { updateListRemove } from "@/api/uploadFile/upload-file";
  122. export default {
  123. name: "index",
  124. props: {
  125. data: {
  126. type: Object
  127. },
  128. incomingAction: {
  129. type: String
  130. },
  131. deleteUrl: {
  132. type: String
  133. },
  134. enumerationValue: {
  135. type: Number
  136. },
  137. typeUpload: {
  138. type: String
  139. },
  140. disabled: {
  141. type: Boolean
  142. },
  143. display: {
  144. type: Boolean
  145. },
  146. basic: {
  147. type: Boolean
  148. }
  149. },
  150. data() {
  151. return {
  152. excelBox: false,
  153. excelTwo: false,
  154. innerVisible: false,
  155. form: {},
  156. imgUrl: "",
  157. action: "/api/blade-resource/oss/endpoint/put-file",
  158. headers: { "Blade-Auth": "Bearer " + getToken() },
  159. option: {},
  160. key: 0,
  161. originalOptions: {
  162. dialogDrag: true,
  163. index: true,
  164. refreshBtn: false,
  165. cellBtn: false,
  166. cancelBtn: false,
  167. delBtn: false,
  168. editBtn: false,
  169. addBtn: false,
  170. align: "center",
  171. column: [
  172. {
  173. label: "文件名称",
  174. prop: "fileName",
  175. index: 1,
  176. width: 140,
  177. cell: true,
  178. overHidden: true
  179. },
  180. {
  181. label: "文件地址",
  182. prop: "url",
  183. index: 2,
  184. overHidden: true
  185. }, {
  186. type: "select",
  187. dicUrl: "/api/blade-system/dict-biz/dictionary?code=facility_img",
  188. props: {
  189. label: "dictValue",
  190. value: "dictValue"
  191. },
  192. label: "文件属性",
  193. prop: "paymentType",
  194. search: false,
  195. index: 3,
  196. width: 140,
  197. overHidden: true,
  198. cell: true
  199. },
  200. {
  201. label: "备注",
  202. prop: "remarks",
  203. index: 4,
  204. cell: true,
  205. overHidden: true
  206. }
  207. ]
  208. },
  209. originalOptionsTwo: {
  210. dialogDrag: true,
  211. index: true,
  212. refreshBtn: false,
  213. cellBtn: false,
  214. cancelBtn: false,
  215. delBtn: false,
  216. editBtn: false,
  217. addBtn: false,
  218. align: "center",
  219. column: [
  220. {
  221. label: "文件名称",
  222. prop: "fileName",
  223. index: 1,
  224. width: 140,
  225. cell: true,
  226. overHidden: true
  227. },
  228. {
  229. label: "文件地址",
  230. prop: "url",
  231. index: 2,
  232. overHidden: true
  233. }, {
  234. type: "select",
  235. dicUrl: "/api/blade-system/dict-biz/dictionary?code=facility_img",
  236. props: {
  237. label: "dictValue",
  238. value: "dictKey"
  239. },
  240. label: "文件属性",
  241. prop: "version",
  242. search: false,
  243. index: 3,
  244. width: 140,
  245. overHidden: true,
  246. cell: true
  247. },
  248. {
  249. label: "备注",
  250. prop: "remarks",
  251. index: 4,
  252. cell: true,
  253. overHidden: true
  254. }
  255. ]
  256. },
  257. originalOptionsThree: {
  258. dialogDrag: true,
  259. index: true,
  260. refreshBtn: false,
  261. cellBtn: false,
  262. cancelBtn: false,
  263. delBtn: false,
  264. editBtn: false,
  265. addBtn: false,
  266. align: "center",
  267. column: [
  268. {
  269. label: "文件名称",
  270. prop: "fileName",
  271. index: 1,
  272. width: 140,
  273. cell: true,
  274. overHidden: true
  275. },
  276. {
  277. label: "文件地址",
  278. prop: "url",
  279. index: 2,
  280. overHidden: true
  281. },
  282. {
  283. label: "备注",
  284. prop: "remarks",
  285. index: 4,
  286. cell: true,
  287. overHidden: true
  288. }
  289. ]
  290. },
  291. uploadCount: 0
  292. };
  293. },
  294. async created() {
  295. console.log(this.enumerationValue)
  296. /**
  297. * 已定义全局方法,直接使用,getColumnData获取列数据,参数传值(表格名称,引入的本地JSON的数据定义的名称)
  298. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  299. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  300. */
  301. if (this.enumerationValue === 160) {
  302. this.option = await this.getColumnData(this.getColumnName(this.enumerationValue), this.originalOptionsTwo);
  303. } else if (this.enumerationValue === 107.1) {
  304. this.option = await this.getColumnData(this.getColumnName(this.enumerationValue), this.originalOptionsTwo);
  305. } else if (this.enumerationValue > 230) {
  306. this.option = await this.getColumnData(this.getColumnName(this.enumerationValue), this.originalOptionsTwo);
  307. } else if (this.enumerationValue === 35.1) {
  308. this.option = await this.getColumnData(this.getColumnName(this.enumerationValue), this.originalOptionsThree);
  309. } else {
  310. this.option = await this.getColumnData(this.getColumnName(this.enumerationValue), this.originalOptions);
  311. // this.getWorkDicts("picture_type").then(res => {
  312. // if (this.findObject(this.option.column, "version").dicData) {
  313. // this.findObject(this.option.column, "version").dicData = res.data.data;
  314. // }
  315. // });
  316. }
  317. this.key++
  318. },
  319. methods: {
  320. //自定义列保存
  321. async saveColumn() {
  322. /**
  323. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  324. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  325. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  326. */
  327. const inSave = await this.saveColumnData(this.getColumnName(this.enumerationValue), this.option);
  328. if (inSave) {
  329. this.$message.success("保存成功");
  330. //关闭窗口
  331. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  332. }
  333. },
  334. //自定义列重置
  335. async resetColumn() {
  336. if (this.enumerationValue === 160) {
  337. this.option = this.originalOptionsTwo;
  338. const inSave = await this.delColumnData(this.getColumnName(this.enumerationValue), this.originalOptionsTwo);
  339. if (inSave) {
  340. this.$message.success("重置成功");
  341. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  342. }
  343. } else if (this.enumerationValue === 107.1) {
  344. this.option = this.originalOptionsTwo;
  345. const inSave = await this.delColumnData(this.getColumnName(this.enumerationValue), this.originalOptionsTwo);
  346. if (inSave) {
  347. this.$message.success("重置成功");
  348. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  349. }
  350. } else if (this.enumerationValue > 230) {
  351. this.option = this.originalOptionsTwo;
  352. const inSave = await this.delColumnData(this.getColumnName(this.enumerationValue), this.originalOptionsTwo);
  353. if (inSave) {
  354. this.$message.success("重置成功");
  355. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  356. }
  357. } else if (this.enumerationValue === 35.1) {
  358. this.option = this.originalOptionsThree;
  359. const inSave = await this.delColumnData(this.getColumnName(this.enumerationValue), this.originalOptionsThree);
  360. if (inSave) {
  361. this.$message.success("重置成功");
  362. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  363. }
  364. } else {
  365. this.option = this.originalOptions;
  366. const inSave = await this.delColumnData(this.getColumnName(this.enumerationValue), this.originalOptions);
  367. if (inSave) {
  368. this.$message.success("重置成功");
  369. this.getWorkDicts("facility_img").then(res => {
  370. this.findObject(this.option.column, "version").dicData = res.data.data;
  371. });
  372. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  373. }
  374. }
  375. },
  376. beforeUpload(file) {
  377. if (file.type == "image/jpeg" || file.type == "image/png" || file.type == "image/bmp") {
  378. const fileSize = file.size / 1024 / 1024
  379. if (fileSize > 5) {
  380. this.$message.error("请上传不能超过5M的图片");
  381. return false;
  382. }
  383. } else {
  384. const fileSize = file.size / 1024 / 1024
  385. if (fileSize > 10) {
  386. this.$message.error("请上传不能超过10M的文件");
  387. return false;
  388. }
  389. }
  390. },
  391. //新增上传成功
  392. onSuccess(response, file, fileList) {
  393. this.$refs.crud.rowCellAdd({
  394. fileName: response.data.originalName,
  395. url: response.data.link
  396. });
  397. this.uploadCount++;
  398. if (this.uploadCount === fileList.length) {
  399. this.$refs.upload.clearFiles();
  400. this.excelBox = false;
  401. this.uploadCount = 0;
  402. }
  403. },
  404. //修改上传成功
  405. onSuccessTwo(response) {
  406. this.form.fileName = response.data.originalName;
  407. this.form.url = response.data.link;
  408. this.data[this.form.$index] = this.form;
  409. this.excelTwo = false;
  410. },
  411. //单行上传
  412. singleLineUpload(row) {
  413. this.form = row;
  414. this.excelTwo = true;
  415. },
  416. //开启批量上传
  417. addDetail() {
  418. this.excelBox = true;
  419. },
  420. //下载附件
  421. download(scope) {
  422. if (scope.row.url) {
  423. if (
  424. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  425. ".jpg" ||
  426. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  427. ".png" ||
  428. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  429. ".JPG" ||
  430. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  431. ".PNG"
  432. ) {
  433. this.imgUrl = scope.row.url;
  434. this.innerVisible = true;
  435. } else {
  436. window.open(scope.row.url);
  437. }
  438. } else {
  439. this.$message.error("请上传附件");
  440. }
  441. },
  442. //修改触发
  443. rowCell(row, index) {
  444. if (row.$cellEdit == true) {
  445. this.$set(row, "$cellEdit", false);
  446. } else {
  447. this.$set(row, "$cellEdit", true);
  448. }
  449. // this.$refs.crud.rowCell(row, index)
  450. },
  451. rowDel(row, index) {
  452. this.$confirm("确定将选择数据删除?", {
  453. confirmButtonText: "确定",
  454. cancelButtonText: "取消",
  455. type: "warning"
  456. }).then(() => {
  457. if (row.id) {
  458. if (this.typeUpload == "CK") {
  459. updateListRemove(row.id, this.deleteUrl).then(res => {
  460. if (res.data.success) {
  461. this.$message.success("操作成功!");
  462. this.data.splice(index, 1);
  463. }
  464. });
  465. } else if (this.typeUpload == "LT") {
  466. LTfujianDelete({ ids: row.id }).then(res => {
  467. if (res.data.success) {
  468. this.$message.success("操作成功!");
  469. this.data.splice(index, 1);
  470. }
  471. })
  472. } else {
  473. sharedDeletion(this.deleteUrl, row.id).then(res => {
  474. if (res.data.success) {
  475. this.$message.success("操作成功!");
  476. this.data.splice(index, 1);
  477. }
  478. });
  479. }
  480. } else {
  481. this.data.splice(index, 1);
  482. }
  483. });
  484. }
  485. }
  486. };
  487. </script>
  488. <style scoped></style>