Explorar o código

物资导出ex

lining %!s(int64=6) %!d(string=hai) anos
pai
achega
1027be2cd7

+ 86 - 0
src/dashoo.cn/backend/api/controllers/oilsupplier/goodsaptitude.go

@@ -2,6 +2,9 @@ package oilsupplier
 
 import (
 	"encoding/json"
+	"fmt"
+	"github.com/tealeg/xlsx"
+	"reflect"
 	"strconv"
 	"strings"
 	"time"
@@ -880,3 +883,86 @@ func (this *OilGoodsAptitudeController) GoodsChildLisByParentId() {
 	this.Data["json"] = &datainfo
 	this.ServeJSON()
 }
+
+// @Title get 导出ex
+// @Description get SampleType by token
+// @Success 200 {object} sampletype.SampleType
+// @router /exportexcelall [get]
+func (this *OilGoodsAptitudeController) ExportExcelAll() {
+	//获取分页信息
+	//page := this.GetPageInfoForm()
+	where := " 1=1 "
+	orderby := "Code"
+	asc := true
+	Order := this.GetString("Order")
+	Prop := this.GetString("Prop")
+	if Order != "" && Prop != "" {
+		orderby = Prop
+		if Order == "asc" {
+			asc = true
+		} else {
+			asc = false
+		}
+	}
+	Edition := this.GetString("Edition")
+
+	if Edition != "" {
+		where = where + " and Edition = '" + Edition + "'"
+	}
+
+	t := time.Now()
+	svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
+	var list []goodsaptitude.OilGoodsAptitudeView
+	svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, 0, 0, orderby, asc, &list, where)
+
+	var title []string
+	filetitle := "物资类"
+	//自定义显示列
+	showcolumnarr := this.GetString("showcolumnarr")
+	showcolumnnamearr := this.GetString("showcolumnnamearr")
+	titlestring := showcolumnnamearr
+	title = strings.Split(titlestring, ",")
+	f := xlsx.NewFile()
+	sheet, _ := f.AddSheet(filetitle)
+	//rowhead := sheet.AddRow()
+	//rowhead.WriteSlice(&title, -1)
+	cellname := strings.Split(showcolumnarr, ",")
+	row := sheet.AddRow()
+	row.WriteSlice(&cellname, -1)
+
+	for _, item := range list {
+		var enumModel goodsaptitude.OilGoodsAptitudeView
+		tmpModel := &item
+		enumModel = *tmpModel
+		immumodel := reflect.ValueOf(&enumModel)
+		elem := immumodel.Elem()
+		row := sheet.AddRow()
+		for _, name := range title {
+			cell := row.AddCell()
+			if strings.HasPrefix(name, "F") {
+				var val = elem.FieldByName(name).String()
+				if val == "1" {
+					cell.Value = "是"
+				} else {
+					cell.Value = ""
+				}
+			} else {
+				cell.Value = elem.FieldByName(name).String()
+			}
+		}
+	}
+
+	for c, cl := 0, len(sheet.Cols); c < cl; c++ {
+		sheet.Cols[c].Width = 20
+	}
+	//this.SaveSampleXlsx(filetitle, title, showcolumnarr, list, f)
+
+	dir := "static/file/excel/report/" + this.GetAccode()
+	SaveDirectory(dir)
+	path := dir + "/" + utils.TimeFormat(time.Now(), "200612") + filetitle + ".xlsx"
+	f.Save(path)
+	this.Data["json"] = this.Ctx.Request.Host + "/" + path
+	this.ServeJSON()
+	elapsed := time.Since(t)
+	fmt.Println(elapsed)
+}

+ 7 - 0
src/dashoo.cn/frontend_web/src/api/oilsupplier/goodsaptitude.js

@@ -71,5 +71,12 @@ export default {
       url: '/goodsaptitude/delete/' + entityId,
       method: 'delete'
     })
+  },
+  exportExcelAll (params, myAxios) {
+    return myAxios({
+      url: '/goodsaptitude/exportexcelall',
+      method: 'get',
+      params: params
+    })
   }
 }

+ 60 - 31
src/dashoo.cn/frontend_web/src/pages/oilsupplier/goodsaptitude/index.vue

@@ -4,7 +4,7 @@
       <el-breadcrumb-item :to="{ path: '/' }">平台首页</el-breadcrumb-item>
       <el-breadcrumb-item :to="{ path: '/oilsupplier/goodsaptitude' }">物资类项目与资质对照表</el-breadcrumb-item>
     </el-breadcrumb>
-    <el-card class="box-card" style="height: calc(100vh - 115px);">
+    <el-card class="box-card" style="height: calc(100vh - 115px);" v-loading="loading">
       <div slot="header">
         <span>
           <i class="icon icon-table2"></i> 物资类项目与资质对照表
@@ -268,6 +268,7 @@
 
     data () {
       return {
+        loading: false,
         codeeditshow: false,
         classid: '',
         myclassid: '',
@@ -487,7 +488,9 @@
           children: 'children'
         },
         operationOrganizeData: [],
-        AuditStepOptions: []
+        AuditStepOptions: [],
+        showcolumn: [
+        ]
       }
     },
     created () {
@@ -532,47 +535,73 @@
             // 保存成功后,初始化数据,变成修改
             this.codeeditshow = false
             this.initDatas()
-          this.$message({
+            this.$message({
               type: 'success',
               message: res.data.message
             })
-
-        } else {
+          } else {
             this.$message({
               type: 'warning',
               message: res.data.message
             })
-        }
+          }
         }).catch(err => {
           console.error(err)
         })
-    },
+      },
+      // exportExcel () {
+      //   /* generate workbook object from table */
+      //   let table = document.querySelector('#rebateSetTable').cloneNode(true) // 克隆备份(原table不动)
+      //   // 因为element-ui的表格的fixed属性导致多出一个table,会下载重复内容,这里删除掉
+      //   table.removeChild(table.querySelector('.el-table__fixed-right')) // 删掉备份的子节点
+      //   let wb = XLSX.utils.table_to_book(table, {
+      //     raw: true
+      //   })
+      //   /* get binary string as output */
+      //   let wbout = XLSX.write(wb, {
+      //     bookType: 'xlsx',
+      //     bookSST: true,
+      //     type: 'array'
+      //   })
+      //   try {
+      //     FileSaver.saveAs(
+      //       new Blob([wbout], {
+      //         type: 'application/octet-stream'
+      //       }),
+      //       'Goods.xlsx'
+      //     )
+      //   } catch (e) {
+      //     if (typeof console !== 'undefined') console.log(e, wbout)
+      //   }
+      //   return wbout
+      // },
       exportExcel () {
-        /* generate workbook object from table */
-        let table = document.querySelector('#rebateSetTable').cloneNode(true) //克隆备份(原table不动)
-      // 因为element-ui的表格的fixed属性导致多出一个table,会下载重复内容,这里删除掉
-      table.removeChild(table.querySelector('.el-table__fixed-right')) // 删掉备份的子节点
-        let wb = XLSX.utils.table_to_book(table, {
-          raw: true
-        })
-      /* get binary string as output */
-      let wbout = XLSX.write(wb, {
-          bookType: 'xlsx',
-          bookSST: true,
-          type: 'array'
+        this.loading = true
+        // 显示列
+        Object.assign(this.showcolumn, this.tableColumns)
+        Object.assign(this.showcolumn, this.dynamicTableColumns)
+        let showcolumn = this.tableColumns.concat(this.dynamicTableColumns)
+        let showcolumnarr = []
+        let showcolumnnamearr = []
+
+        for (var i = 0; i < showcolumn.length; i++) {
+          showcolumnarr.push(showcolumn[i].label)
+          showcolumnnamearr.push(showcolumn[i].prop.replace(/,/g, ','))
+        }
+        let params = {
+          _currentPage: this.currentPage,
+          _size: this.size,
+          Order: this.Column.Order,
+          Prop: this.Column.Prop,
+          Edition: '1',
+          showcolumnarr: showcolumnarr + '',
+          showcolumnnamearr: showcolumnnamearr + ''
+        }
+        api.exportExcelAll(params, this.$axios).then(res => {
+          this.loading = false
+          window.location = 'http://' + res.data
         })
-      try {
-          FileSaver.saveAs(
-            new Blob([wbout], {
-              type: 'application/octet-stream'
-            }),
-            'Goods.xlsx'
-          )
-      } catch (e) {
-          if (typeof console !== 'undefined') console.log(e, wbout)
-      }
-        return wbout
-    },
+      },
       initTableHeader () {
         setapi.initGoodTableHeader(this.$axios).then(res => {
           this.dynamicTableColumns = res.data.items