ImportExcel.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <el-dialog
  3. title="上传信息"
  4. :visible="visible"
  5. width="490px"
  6. :before-close="handleClose"
  7. :close-on-click-modal="false"
  8. >
  9. <div class="popup-content">
  10. <el-form
  11. ref="postForm"
  12. :model="postForm"
  13. :rules="postFormRule"
  14. label-width="80px"
  15. @keyup.enter.native="postFormSubmit()"
  16. >
  17. <el-form-item label="运营中心" prop="operationsCenterId" v-if="userInfo.userTypeModel == 'admin'">
  18. <el-select
  19. v-model="postForm.operationsCenterId"
  20. clearable
  21. filterable
  22. placeholder="请选择运营中心"
  23. @change="onOperationsCenterChange"
  24. >
  25. <el-option v-for="item in operationsCenterList" :key="item.value" :label="item.label" :value="item.value" />
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item
  29. label="项目名称"
  30. prop="projectId"
  31. v-if="userInfo.userTypeModel == 'admin' || userInfo.userTypeModel == 'operationsCenter'"
  32. >
  33. <el-select
  34. v-model="postForm.projectId"
  35. :disabled="!postForm.operationsCenterId"
  36. filterable
  37. clearable
  38. placeholder="请选择项目"
  39. >
  40. <el-option v-for="item in projectList" :key="item.value" :label="item.label" :value="item.value" />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item label="上传文件" prop="fileList">
  44. <el-upload
  45. :file-list="postForm.fileList"
  46. ref="upload"
  47. :action="action"
  48. :multiple="false"
  49. name="file"
  50. :data="uploadData"
  51. :auto-upload="false"
  52. :on-success="handleUploadSuccess"
  53. :on-error="handleUploadError"
  54. :on-change="handleUploadChange"
  55. >
  56. <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  57. <!-- <div slot="tip" class="el-upload__tip">只能上传.xlsx, .xls, .csv文件,且不超过500kb</div> -->
  58. </el-upload>
  59. </el-form-item>
  60. </el-form>
  61. </div>
  62. <span slot="footer" class="dialog-footer">
  63. <el-button @click="handleClose">取 消</el-button>
  64. <el-button type="primary" @click="handleSubmit" :loading="loading">确 定</el-button>
  65. </span>
  66. </el-dialog>
  67. </template>
  68. <script>
  69. import { companyGetselectlist, organizationGetselectlist } from "@/api/flashdeliver/jiaoshuima";
  70. export default {
  71. props: {
  72. visible: {
  73. type: Boolean,
  74. default: false
  75. }
  76. },
  77. data() {
  78. return {
  79. loading: false,
  80. operationsCenterList: [], // 运营中心列表
  81. projectList: [], // 项目列表
  82. postForm: {
  83. operationsCenterId: "",
  84. projectId: "",
  85. fileList: []
  86. },
  87. postFormRule: {
  88. operationsCenterId: [{ required: true, message: "运营中心不能为空", trigger: "change" }],
  89. projectId: [{ required: true, message: "项目不能为空", trigger: "change" }],
  90. fileList: [
  91. {
  92. required: true,
  93. type: "array",
  94. validator: (rule, value, callback) => {
  95. if (!value.length) {
  96. return callback(new Error("上传文件不能为空"));
  97. }
  98. callback();
  99. },
  100. trigger: "change"
  101. }
  102. ]
  103. },
  104. userInfo: {},
  105. action: `${process.env.BASE_API}/organisation/customermgt/importRoomInfo`
  106. };
  107. },
  108. computed: {
  109. uploadData() {
  110. const { projectId, operationsCenterId } = this.postForm;
  111. return {
  112. compId: operationsCenterId,
  113. orgId: projectId
  114. };
  115. }
  116. },
  117. methods: {
  118. handleClose() {
  119. this.loading = false;
  120. this.$emit("update:visible", false);
  121. },
  122. handleOpen() {
  123. this.$emit("update:visible", true);
  124. },
  125. handleOpen() {
  126. this.$emit("update:visible", true);
  127. },
  128. handleSubmit() {
  129. this.$refs["postForm"].validate(valid => {
  130. if (!valid) {
  131. return;
  132. }
  133. this.loading = true;
  134. this.$refs.upload.submit();
  135. });
  136. },
  137. init() {
  138. this.getOperationsCenterList();
  139. },
  140. handleUploadChange(file, fileList) {
  141. const isExcel = /\.(xlsx|xls|csv)$/.test(file.name);
  142. const isLimit = fileList.length > 1;
  143. if (!isExcel) {
  144. this.$message.error("上传信息只能是 .xlsx, .xls, .csv格式!");
  145. fileList.splice(-1, 1);
  146. return;
  147. }
  148. if (isLimit) {
  149. this.$message({
  150. type: "error",
  151. message: `只能选择 1 个文件,当前共选择了 ${fileList.length} 个`
  152. });
  153. fileList.splice(-1, 1);
  154. return;
  155. }
  156. this.postForm.fileList = fileList;
  157. },
  158. handleUploadSuccess(res, file) {
  159. console.log("handleUploadSuccess", res, file);
  160. this.loading = false;
  161. if (Number(res.code) === 200) {
  162. this.$message({
  163. type: "success",
  164. dangerouslyUseHTMLString: true,
  165. message: res.msg,
  166. duration: 2500
  167. });
  168. this.$emit("submit");
  169. } else {
  170. this.$message({
  171. type: "error",
  172. dangerouslyUseHTMLString: true,
  173. message: res.msg,
  174. duration: 2500
  175. });
  176. }
  177. },
  178. handleUploadError(err) {
  179. console.error("handleUploadError", err);
  180. this.loading = false;
  181. this.$message({
  182. type: "error",
  183. message: `上传失败`,
  184. duration: 2500
  185. });
  186. },
  187. async getProjectList() {
  188. const params = {
  189. pageNo: 1,
  190. pageSize: 999
  191. };
  192. this.postForm.operationsCenterId && (params["conditions[companyId]"] = this.postForm.operationsCenterId);
  193. const res = await organizationGetselectlist(params);
  194. this.projectList = res.data;
  195. if (res.data && res.data.length === 1) {
  196. this.postForm.projectId = res.data[0].value;
  197. }
  198. },
  199. onOperationsCenterChange() {
  200. this.postForm.projectId = "";
  201. this.getProjectList();
  202. },
  203. async getOperationsCenterList() {
  204. const res = await companyGetselectlist();
  205. this.operationsCenterList = res.data;
  206. if (res.data && res.data.length) {
  207. const operationsCenterId = res.data[0].value;
  208. this.postForm.operationsCenterId = operationsCenterId;
  209. this.getProjectList();
  210. }
  211. }
  212. }
  213. };
  214. </script>
  215. <style lang="scss" scoped>
  216. .ul {
  217. }
  218. .li {
  219. display: flex;
  220. align-items: center;
  221. margin-bottom: 10px;
  222. &-hd {
  223. width: 100px;
  224. margin-right: 20px;
  225. }
  226. &-bd {
  227. margin-right: 20px;
  228. }
  229. &-ft {
  230. display: flex;
  231. align-items: center;
  232. &-split {
  233. padding: 0 5px;
  234. display: inline-block;
  235. color: #606266;
  236. font-size: 14px;
  237. }
  238. }
  239. /deep/ .el-date-editor.el-input,
  240. .el-date-editor.el-input__inner {
  241. width: 240px;
  242. }
  243. /deep/ .el-range-editor--mini.el-input__inner {
  244. height: 34px;
  245. }
  246. }
  247. </style>