index.vue 14 KB

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