RightBox.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <!--
  2. * @Descripttion: 右边盒子
  3. * @Author: sujunling
  4. * @Date: 2025-05-20 10:16:56
  5. -->
  6. <template>
  7. <transition
  8. appear
  9. name="animate__animated animate__move"
  10. enter-active-class="animate__slideInRight"
  11. leave-active-class="animate__slideOutRight"
  12. >
  13. <div class="widget-ProjectProgress">
  14. <div class="head">
  15. <div class="title">
  16. <div class="icon"></div>
  17. <span class="site-info">施工进度控制模型参数</span>
  18. <div class="addDiv" @click="addPlanDate"></div>
  19. </div>
  20. </div>
  21. <div class="bodyBox">
  22. <div class="inputStopDate" v-if="planDateList.length">
  23. <template v-for="(item, index) in planDateList">
  24. <div :key="'inputStopDate_' + index" class="dateTimeDiv">
  25. <div class="itemTitle" v-if="index" @click="changeTab(item)">施工调整开始时间</div>
  26. <div class="itemTitle" v-else @click="changeTab(item)">施工计划开始时间</div>
  27. <el-date-picker
  28. format="yyyy-MM-dd HH:mm:ss"
  29. value-format="yyyy-MM-dd HH:mm:ss"
  30. v-model="item.value"
  31. type="date"
  32. placeholder="请选择时间"
  33. ></el-date-picker>
  34. <div class="removeDiv" @click="removePlanDate(index)" v-if="index">
  35. <i class="removeDate el-icon-remove-outline" style="color: #78b6e7"></i>
  36. </div>
  37. <div class="addFileDiv">
  38. <input
  39. type="file"
  40. id="excelFile"
  41. accept=".xlsx, .xls"
  42. @change="handleFileChange($event, item, index)"
  43. class="file-input"
  44. />
  45. <i class="addFile el-icon-download" style="color: #78b6e7"></i>
  46. </div>
  47. </div>
  48. </template>
  49. </div>
  50. <div class="tableBox tableBoxRight" v-if="tableData.length">
  51. <el-table :data="tableData" size="mini" height="250">
  52. <el-table-column prop="step" label="序号"> </el-table-column>
  53. <el-table-column prop="area" label="标识"> </el-table-column>
  54. <el-table-column prop="total_volume" label="任务量"> </el-table-column>
  55. <el-table-column prop="machine_count" label="机械数量"> </el-table-column>
  56. </el-table>
  57. </div>
  58. </div>
  59. </div>
  60. </transition>
  61. </template>
  62. <script>
  63. import XLSX from 'xlsx'
  64. export default {
  65. data() {
  66. return {
  67. //施工计划时间段
  68. planDateList: [
  69. ],
  70. tableData: []
  71. }
  72. },
  73. mounted() {
  74. window.l = this.planDateList
  75. },
  76. methods: {
  77. updateFile(f, item, k) {
  78. const formData = new FormData()
  79. formData.append('file', f)
  80. formData.append('name', k ? 'construction_data_2' : 'construction_data_1')
  81. fetch('http://127.0.0.1:8000/upload-file', {
  82. method: 'POST',
  83. body: formData
  84. })
  85. .then((response) => response.json())
  86. .then((r) => {
  87. if (r && r.code == 1) {
  88. this.$message.success(k ? '施工调整表格数据上传成功!' : '施工计划表格数据上传成功!')
  89. item.file = r.result
  90. }
  91. })
  92. },
  93. handleFileChange(event, item, index) {
  94. console.log(event, item)
  95. this.resetState()
  96. const file = event.target.files[0]
  97. if (!file) return
  98. this.updateFile(file, item, index)
  99. this.fileName = file.name
  100. this.isLoading = true
  101. const reader = new FileReader()
  102. reader.onload = (e) => {
  103. try {
  104. const data = new Uint8Array(e.target.result)
  105. this.processExcelData(data, item, index)
  106. } catch (err) {
  107. this.error = '文件处理失败: ' + err.message
  108. console.error(err)
  109. } finally {
  110. this.isLoading = false
  111. }
  112. }
  113. reader.onerror = () => {
  114. this.error = '文件读取失败'
  115. this.isLoading = false
  116. }
  117. reader.readAsArrayBuffer(file)
  118. },
  119. processExcelData(data, item, index) {
  120. try {
  121. const workbook = XLSX.read(data, { type: 'array' })
  122. const firstSheetName = workbook.SheetNames[0]
  123. const worksheet = workbook.Sheets[firstSheetName]
  124. const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 })
  125. if (jsonData.length === 0) {
  126. this.error = 'Excel文件中没有数据'
  127. return
  128. }
  129. this.headers = jsonData[0]
  130. this.data = jsonData.slice(1).filter((row) => row.length > 0)
  131. if (this.data.length === 0) {
  132. this.error = 'Excel文件中没有有效数据'
  133. }
  134. var data = {
  135. headers: this.headers,
  136. data: this.data,
  137. fileName: this.fileName
  138. }
  139. item.table = data
  140. if (!index) {
  141. this.tableData = this.transformData(data)
  142. }
  143. console.log('data', data)
  144. } catch (err) {
  145. this.error = 'Excel文件解析失败: ' + err.message
  146. }
  147. },
  148. transformData(originalData) {
  149. const { headers, data } = originalData
  150. return data.map((row) => {
  151. const obj = {}
  152. headers.forEach((header, index) => {
  153. obj[header] = row[index]
  154. })
  155. return obj
  156. })
  157. },
  158. changeTab(i) {
  159. if (i.table) {
  160. this.tableData = this.transformData(i.table)
  161. }
  162. },
  163. resetState() {
  164. this.headers = []
  165. this.data = []
  166. this.error = ''
  167. this.isLoading = false
  168. },
  169. /**
  170. *添加时间段
  171. */
  172. addPlanDate() {
  173. if (this.planDateList.length < 2) {
  174. const item = {
  175. value: ''
  176. }
  177. this.planDateList.push(item)
  178. }
  179. },
  180. /**
  181. *删除时间段
  182. */
  183. removePlanDate(index) {
  184. if (this.planDateList.length > 1) {
  185. if (index == -1) {
  186. this.planDateList = []
  187. } else {
  188. this.planDateList.splice(index, 1)
  189. }
  190. }
  191. },
  192. changeTable(r) {
  193. if (r.start_date) {
  194. this.planDateList.push({
  195. value: r.start_date
  196. })
  197. }
  198. if (r.conversion_date) {
  199. this.planDateList.push({
  200. value: r.conversion_date
  201. })
  202. }
  203. }
  204. }
  205. }
  206. </script>
  207. <style>
  208. .dateTimeDiv .el-date-editor {
  209. background-color: rgba(255, 255, 255, 0);
  210. border-radius: 2px;
  211. height: 30px;
  212. border: 1px solid #216294;
  213. }
  214. .dateTimeDiv .el-date-editor input.el-input__inner {
  215. height: 30px;
  216. line-height: 30px;
  217. border-radius: 2px;
  218. background-color: rgba(255, 255, 255, 0);
  219. border: 1px solid rgba(255, 255, 255, 0);
  220. color: #fff !important;
  221. }
  222. .dateTimeDiv input.el-range-input {
  223. background-color: rgba(255, 255, 255, 0);
  224. color: #fff;
  225. }
  226. .dateTimeDiv .el-date-editor .el-input__prefix .el-input__icon {
  227. line-height: 30px;
  228. }
  229. .tableBoxRight .el-table th.el-table__cell > .cell {
  230. background: rgba(43, 167, 255, 0.16);
  231. color: #2ba7ff;
  232. }
  233. </style>
  234. <style lang='scss' scoped>
  235. .removeDiv, .addFileDiv {
  236. width: 24px !important;
  237. height: 24px !important;
  238. cursor: pointer !important;
  239. }
  240. .tableBox {
  241. margin-top: 20px;
  242. }
  243. .removeDiv,
  244. .addFileDiv {
  245. cursor: pointer;
  246. }
  247. .addFileDiv input {
  248. position: absolute;
  249. width: 24px;
  250. height: 24px;
  251. opacity: 0.01;
  252. cursor: pointer;
  253. }
  254. .dateTimeDiv {
  255. .el-date-editor {
  256. input.el-input__inner {
  257. height: 30px;
  258. line-height: 30px;
  259. border-radius: 2px;
  260. background-color: rgba(255, 255, 255, 0);
  261. border: 1px solid rgba(255, 255, 255, 0);
  262. color: #ffffff;
  263. }
  264. }
  265. }
  266. .bodyBox,
  267. .content-info {
  268. padding: 15px;
  269. }
  270. .dateTimeDiv .el-date-editor.el-input {
  271. width: 145px;
  272. border-radius: 2px;
  273. margin: 0 5px;
  274. }
  275. .dateTimeDiv .itemTitle {
  276. font-weight: 400;
  277. font-size: 14px;
  278. letter-spacing: -1px;
  279. color: #ffffff;
  280. cursor: pointer;
  281. }
  282. .dateTimeDiv {
  283. display: flex;
  284. height: 30px;
  285. line-height: 30px;
  286. margin-top: 10px;
  287. }
  288. .addDiv {
  289. color: #9bd2fa;
  290. font-size: 14px;
  291. font-weight: normal;
  292. cursor: pointer;
  293. background: url('~@/assets/images/jczc/add.png') no-repeat center;
  294. background-size: 100% 100%;
  295. width: 40px;
  296. height: 22px;
  297. }
  298. .animate__slideInRight,
  299. .animate__slideOutRight {
  300. animation-duration: 3s; //动画持续时间
  301. animation-delay: 0s; //动画延迟时间
  302. }
  303. .widget-ProjectProgress {
  304. $size10: 0.052083rem /* 10/192 */;
  305. $size20: 0.104167rem /* 20/192 */;
  306. z-index: 2;
  307. //position
  308. top: 0.505208rem /* 10/192 */;
  309. margin-right: $size20 /* 20/192 */;
  310. right: 0;
  311. position: absolute;
  312. //size
  313. height: calc(100% - 1.57292rem - 115px);
  314. width: 2.083333rem /* 400/192 */;
  315. color: #eee;
  316. overflow: hidden;
  317. background: linear-gradient(0deg, rgba(14, 167, 255, 0.24) 0%, rgba(14, 167, 255, 0.05) 100%);
  318. .head {
  319. height: 0.166667rem /* 32/192 */;
  320. width: 100%;
  321. background: linear-gradient(-90deg, rgba(43, 167, 255, 0.2) 0%, rgba(43, 167, 255, 0.08) 100%);
  322. font-family: Source Han Sans CN-HEAVY;
  323. .title {
  324. width: 100%;
  325. height: 100%;
  326. display: flex;
  327. font-weight: 400;
  328. align-items: center;
  329. .icon {
  330. height: 0.166667rem /* 32/192 */;
  331. width: 0.34375rem /* 66/192 */;
  332. background: url('~@/views/groupPage/images/模块图标/项目进展.png') no-repeat center center;
  333. background-size: 100% 100%;
  334. }
  335. span {
  336. flex: 1;
  337. font-weight: bold;
  338. font-size: 0.083333rem /* 16/192 */;
  339. color: #ffffff;
  340. padding: 0.041667rem /* 8/192 */;
  341. background: linear-gradient(0deg, #9bd2fa 0%, #ffffff 100%);
  342. background-clip: text;
  343. -webkit-text-fill-color: transparent;
  344. }
  345. }
  346. }
  347. }
  348. </style>