addFloorDialog.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <!-- 新增楼层文件 -->
  3. <div id="addFloorDialog">
  4. <el-dialog
  5. title="新增楼层"
  6. :visible.sync="addFloorFileVisible"
  7. width="900px"
  8. :before-close="handleClose"
  9. >
  10. <el-form ref="addfloorform" :model="form" label-width="120px">
  11. <el-form-item label="模型文件:">
  12. <el-upload
  13. class="upload-demo"
  14. ref="upload"
  15. :headers="headers"
  16. :data="updataData"
  17. action="/modelapi/model-file/upload"
  18. :on-preview="handlePreview"
  19. :on-remove="handleRemove"
  20. :file-list="fileList"
  21. :auto-upload="false"
  22. :on-change="onChangeUpLoad"
  23. :limit="1"
  24. >
  25. <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  26. </el-upload>
  27. </el-form-item>
  28. <el-form-item label="模型所属楼层:">
  29. <div class="floorModle">
  30. <el-select v-model="form.floorTypeVal" placeholder="请选择">
  31. <el-option
  32. v-for="item in floorType"
  33. :key="item.value"
  34. :label="item.label"
  35. :value="item.value"
  36. ></el-option>
  37. </el-select>
  38. <!-- 计数 -->
  39. <el-input-number
  40. style="margin-left:10px;"
  41. v-model="form.floorNum"
  42. :min="1"
  43. :disabled="form.floorTypeVal == 'RF'"
  44. @change="handleChange"
  45. ></el-input-number>
  46. <!-- 是否夹层 -->
  47. <el-checkbox style="margin:0 10px;" v-model="form.haveInterlayer">是否夹层</el-checkbox>
  48. <!-- 夹层选择 -->
  49. <el-select
  50. v-model="form.interlayerTypeVal"
  51. :disabled="!form.haveInterlayer"
  52. placeholder="请选择"
  53. >
  54. <el-option
  55. v-for="item in interlayerType"
  56. :key="item.value"
  57. :label="item.label"
  58. :value="item.value"
  59. ></el-option>
  60. </el-select>
  61. </div>
  62. </el-form-item>
  63. <el-form-item label="备注信息:">
  64. <el-input type="textarea" v-model="form.desc"></el-input>
  65. </el-form-item>
  66. <el-form-item>
  67. <el-button type="primary" @click="onSubmit">确认</el-button>
  68. <el-button @click="handleClose">取消</el-button>
  69. </el-form-item>
  70. </el-form>
  71. </el-dialog>
  72. </div>
  73. </template>
  74. <script>
  75. import request from "@/api/model/file.js";
  76. import { mapGetters } from "vuex";
  77. export default {
  78. props: {
  79. addFloorFileVisible: Boolean,
  80. FolderName: String,
  81. floorList: Array,
  82. FolderId: String
  83. },
  84. computed: {
  85. ...mapGetters("layout", ["projectId", "userInfo","userId", "secret", "uploaderList"])
  86. },
  87. data() {
  88. return {
  89. form: {
  90. desc: "", //描述
  91. floorTypeVal: "F", //楼层类型得值
  92. interlayerTypeVal: "M1", //夹层类型得值
  93. haveInterlayer: false, //是否有夹层
  94. file: null, //上传文件
  95. floorNum: 1 //楼层
  96. },
  97. fileList: [], //上传楼层列表
  98. floorType: [
  99. {
  100. value: "F",
  101. label: "正常层(F)"
  102. },
  103. {
  104. value: "RF",
  105. label: "屋顶(RF)"
  106. },
  107. {
  108. value: "B",
  109. label: "地下(B)"
  110. }
  111. ],
  112. interlayerType: [
  113. {
  114. value: "M1",
  115. label: "夹层M1"
  116. },
  117. {
  118. value: "M2",
  119. label: "夹层M2"
  120. },
  121. {
  122. value: "M3",
  123. label: "夹层M3"
  124. }
  125. ],
  126. //请求头
  127. headers: {
  128. ProjectId: ""
  129. },
  130. updataData: {
  131. model: {}
  132. }
  133. };
  134. },
  135. methods: {
  136. onSubmit() {
  137. let FloorName = null;
  138. if (this.form.file == null) {
  139. this.$message.error("模型文件不能为空!");
  140. } else if (this.uploaderList.some(item => {return item.name === this.form.file.name})) {
  141. this.$message.error("该文件在上传列表中已存在!");
  142. } else {
  143. let FloorName = null;
  144. // 根据是否有夹层拼接楼层名
  145. if (this.form.haveInterlayer) {
  146. if (this.form.floorTypeVal == "RF") {
  147. FloorName = this.form.floorTypeVal + this.form.interlayerTypeVal;
  148. } else {
  149. FloorName =
  150. this.form.floorTypeVal + this.form.floorNum + this.form.interlayerTypeVal;
  151. }
  152. } else {
  153. if (this.form.floorTypeVal == "RF") {
  154. FloorName = this.form.floorTypeVal;
  155. } else {
  156. FloorName = this.form.floorTypeVal + this.form.floorNum;
  157. }
  158. }
  159. if(this.floorList.some((item) => {return item.FloorName == FloorName})) {
  160. this.$message.error('该楼层名称已存在,请勿重复创建!');
  161. } else {
  162. let data = {
  163. FileName: this.form.file.name,
  164. FloorName: FloorName,
  165. FolderId: this.FolderId,
  166. Note: this.form.desc,
  167. ProjectId: this.projectId,
  168. ReplaceReason: null,
  169. Size: this.form.file.size,
  170. UserName: this.userInfo.userName,
  171. UserId: this.userInfo.userId
  172. };
  173. request.modelFileUpload(data, res => {
  174. // 创建成功
  175. this.$emit("finishCreateFloor", {
  176. modelId: res.ModelId,
  177. uploadId: res.UploadId,
  178. floorId: res.floorId,
  179. file: this.form.file
  180. });
  181. this.handleClose();
  182. });
  183. }
  184. }
  185. },
  186. // /上传到服务器/
  187. submitUpload(FloorModelId) {
  188. this.$refs.upload.submit();
  189. },
  190. handleClose() {
  191. this.$emit("closeAddFloorDia");
  192. },
  193. // 删除上传文件
  194. handleRemove(file, fileList) {
  195. this.fileList = []
  196. this.form.file = null;
  197. },
  198. handlePreview(file, fileList) {
  199. console.log(file, fileList);
  200. },
  201. handleChange(file, fileList) {
  202. console.log(file, fileList);
  203. },
  204. // 获取上传文件
  205. onChangeUpLoad(file, fileList) {
  206. console.log(file, fileList);
  207. if (fileList.length) {
  208. this.form.file = file;
  209. }
  210. }
  211. },
  212. watch: {
  213. addFloorFileVisible(val) {
  214. if (val) {
  215. this.handleRemove();
  216. this.form = {
  217. desc: "", //描述
  218. floorTypeVal: "F", //楼层类型得值
  219. interlayerTypeVal: "M1", //夹层类型得值
  220. haveInterlayer: false, //是否有夹层
  221. file: null, //上传文件
  222. floorNum: 1 //楼层
  223. };
  224. }
  225. }
  226. },
  227. mounted() {
  228. this.fileList = [];
  229. this.form.file = null;
  230. }
  231. };
  232. </script>
  233. <style lang="less">
  234. #addFloorDialog {
  235. .floorModle {
  236. display: flex;
  237. justify-content: left;
  238. }
  239. }
  240. </style>