index.vue 14 KB

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