index.vue 9.6 KB

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