liuyg
2021-07-16 f5641fd76ef90a66599e8ce121f3acfd97d779e8
src/views/feedbackReport/feedbackReport.vue
@@ -1,390 +1,413 @@
<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   v-if="permission.feedback_delete"
                   @click="handleDelete">删 除
        <el-button
          type="danger"
          size="small"
          icon="el-icon-delete"
          plain
          v-if="permission.feedback_delete"
          @click="handleDelete"
          >删 除
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>
<script>
  import {getListReport, getDetails, adds, updates, remove} from "@/api/feedback/feedback";
    import {getBaTree} from "@/api/client/client";
  import {mapGetters} from "vuex";
import {
  getListReport,
  getDetails,
  adds,
  updates,
  remove,
} from "@/api/feedback/feedback";
import { getBaTree } from "@/api/client/client";
import { mapGetters } from "vuex";
  export default {
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height:'auto',
          calcHeight: 54,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          labelWidth: '125',
          dialogWidth: 1150,
          border: false,
          stripe:true,
          index: true,
          viewBtn: true,
          selection: true,
          dialogClickModal: false,
          images:[],
          videos:[],
          column: [
            {
              label: "上报人姓名",
              prop: "sname",
              search:true,
              searchLabelWidth:100,
              searchSpan:5,
              addDisplay:false,
              editDisplay:false
export default {
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: "auto",
        calcHeight: 54,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        labelWidth: "125",
        dialogWidth: 1150,
        border: false,
        //stripe:true,
        index: true,
        viewBtn: true,
        selection: true,
        dialogClickModal: false,
        images: [],
        videos: [],
        column: [
          {
            label: "上报人姓名",
            prop: "sname",
            search: true,
            searchLabelWidth: 100,
            searchSpan: 5,
            addDisplay: false,
            editDisplay: false,
          },
          {
            label: "上报人姓名",
            prop: "snumber",
            type: "tree",
            dicUrl: "/api/catalogs/catalogs/getBigTree",
            props: {
              label: "title",
            },
            {
              label: "上报人姓名",
              prop: "snumber",
              type: "tree",
              dicUrl: "/api/catalogs/catalogs/getBigTree",
              props: {
                label: "title"
              },
              width: 72,
              hide: true,
              addDisplay: true,
              editDisplay: true,
              viewDisplay: false,
              rules: [{
            width: 72,
            hide: true,
            addDisplay: true,
            editDisplay: true,
            viewDisplay: false,
            rules: [
              {
                required: true,
                message: "请选择上报人",
                trigger: "blur"
              }],
            },
            {
              label: "上报地址",
              prop: "place",
              rules: [{
                trigger: "blur",
              },
            ],
          },
          {
            label: "上报地址",
            prop: "place",
            rules: [
              {
                required: true,
                message: "请输入事发地址",
                trigger: "blur"
              }]
            },
            {
              label: "备注",
              prop: "result",
              rules: [{
                trigger: "blur",
              },
            ],
          },
          {
            label: "备注",
            prop: "result",
            rules: [
              {
                required: true,
                message: "请输入处理结果",
                trigger: "blur"
              }]
            },
            {
              label: "上报时间",
              prop: "stime",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
            },
            {
              label: "上报时间",
              prop: "dateTime",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
              searchRange: true,
              search:true,
              searchLabelWidth:100,
              searchSpan: 6,
              addDisplay:false,
              viewDisplay:false,
              editDisplay:false,
              hide:true,
              rules: [{
                trigger: "blur",
              },
            ],
          },
          {
            label: "上报时间",
            prop: "stime",
            type: "datetime",
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
          },
          {
            label: "上报时间",
            prop: "dateTime",
            type: "datetime",
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            searchRange: true,
            search: true,
            searchLabelWidth: 100,
            searchSpan: 6,
            addDisplay: false,
            viewDisplay: false,
            editDisplay: false,
            hide: true,
            rules: [
              {
                required: true,
                message: "请选择上报时间",
                trigger: "blur"
              }]
                trigger: "blur",
              },
            ],
          },
          {
            label: "图片",
            prop: "images",
            dataType: "array",
            type: "upload",
            span: 24,
            hide: true,
            viewDisplay: true,
            listType: "picture-card",
            action: "/api/blade-resource/oss/endpoint/put-file",
            propsHttp: {
              res: "data",
              url: "link",
            },
            {
              label: '图片',
              prop: 'images',
              dataType: 'array',
              type: 'upload',
              span: 24,
              hide:true,
              viewDisplay:true,
              listType: 'picture-card',
              action: "/api/blade-resource/oss/endpoint/put-file",
              propsHttp: {
                res: "data",
                url: "link",
              }
          },
          {
            label: "视频",
            prop: "videos",
            dataType: "array",
            type: "upload",
            accept: "video/mp4",
            hide: true,
            viewDisplay: true,
            editDisabled: true,
            listType: "picture",
            span: 24,
            action: "http://web.byisf.com:82/blade-jfpts/depl/put-depl",
            propsHttp: {
              res: "data",
              url: "link",
            },
             {
              label: '视频',
              prop: 'videos',
              dataType: 'array',
              type: 'upload',
              accept:"video/mp4",
              hide:true,
              viewDisplay:true,
              editDisabled:true,
              listType: 'picture',
              span: 24,
              action: "http://web.byisf.com:82/blade-jfpts/depl/put-depl",
              propsHttp: {
                res: "data",
                url: "link",
              }
            },
          ]
        },
        data: []
          },
        ],
      },
      data: [],
    };
  },
  watch: {
    handler(val) {
      var that = this;
      if (val != null && val != "") {
        getBaTree(val).then((res) => {
          if (res) {
            that.form.sname = res.data.data.records[0].name;
          }
        });
      }
    },
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.feedback_add, false),
        viewBtn: this.vaildData(this.permission.feedback_view, true),
        delBtn: this.vaildData(this.permission.feedback_delete, true),
        editBtn: this.vaildData(this.permission.feedback_edit, true),
      };
    },
    watch:{
      handler(val) {
          var that = this;
          if (val != null && val !=""){
            getBaTree(val).then(res => {
              if (res) {
                that.form.sname = res.data.data.records[0].name;
              }
            });
          }
        },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.feedback_add, false),
          viewBtn: this.vaildData(this.permission.feedback_view, true),
          delBtn: this.vaildData(this.permission.feedback_delete, true),
          editBtn: this.vaildData(this.permission.feedback_edit, true)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
  },
  methods: {
    rowSave(row, done, loading) {
      var data = {
        status: 1,
        tpaddress: "",
        spaddress: "",
        sname: row.$snumber,
        snumber: row.snumber,
        stime: row.stime,
        result: row.result,
        place: row.place,
      };
      if (row.images.length > 0) {
        var imageArr = row.images;
        imageArr.forEach((image) => {
          data.tpaddress += image + ",";
        });
        return ids.join(",");
        data.tpaddress = data.tpaddress.substring(0, data.tpaddress.length - 1);
      }
    },
    methods: {
      rowSave(row, done, loading) {
        var data = {
              status:1,
              tpaddress:"",
              spaddress:"",
              sname: row.$snumber,
              snumber: row.snumber,
              stime:row.stime,
              result:row.result,
              place:row.place
          }
        if (row.images.length > 0) {
               var imageArr = row.images;
               imageArr.forEach( image =>{
              data.tpaddress += image + ",";
          })
               data.tpaddress = data.tpaddress.substring(0,data.tpaddress.length-1);
            }
            if (row.videos.length > 0) {
               //var videoArr = row.videos;
               //videoArr.forEach( video =>{
              //data.spaddress += video + ",";
          //})
               //data.spaddress = data.spaddress.substring(0,data.spaddress.length-1);
               data.spaddress = row.videos;
            }
        adds(data).then(() => {
      if (row.videos.length > 0) {
        //var videoArr = row.videos;
        //videoArr.forEach( video =>{
        //data.spaddress += video + ",";
        //})
        //data.spaddress = data.spaddress.substring(0,data.spaddress.length-1);
        data.spaddress = row.videos;
      }
      adds(data).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
            message: "操作成功!",
          });
          done();
        }, error => {
        },
        (error) => {
          loading();
          window.console.log(error);
        }
      );
    },
    rowUpdate(row, index, done, loading) {
      var data = {
        id: row.id,
        status: 1,
        tpaddress: "",
        spaddress: "",
        sname: row.$snumber,
        snumber: row.snumber,
        stime: row.stime,
        result: row.result,
        place: row.place,
      };
      if (row.images.length > 0) {
        var imageArr = row.images;
        imageArr.forEach((image) => {
          data.tpaddress += image + ",";
        });
      },
      rowUpdate(row, index, done, loading) {
        var data = {
              id:row.id,
              status:1,
              tpaddress:"",
              spaddress:"",
              sname: row.$snumber,
              snumber: row.snumber,
              stime:row.stime,
              result:row.result,
              place:row.place
          }
        if (row.images.length > 0) {
               var imageArr = row.images;
               imageArr.forEach( image =>{
              data.tpaddress += image + ",";
          })
               data.tpaddress = data.tpaddress.substring(0,data.tpaddress.length-1);
            }
            if (row.videos.length > 0) {
               //var videoArr = row.videos;
               //videoArr.forEach( video =>{
              //data.spaddress += video + ",";
          //})
               //data.spaddress = data.spaddress.substring(0,data.spaddress.length-1);
               data.spaddress = row.videos;
            }
        updates(data).then(() => {
        data.tpaddress = data.tpaddress.substring(0, data.tpaddress.length - 1);
      }
      if (row.videos.length > 0) {
        //var videoArr = row.videos;
        //videoArr.forEach( video =>{
        //data.spaddress += video + ",";
        //})
        //data.spaddress = data.spaddress.substring(0,data.spaddress.length-1);
        data.spaddress = row.videos;
      }
      updates(data).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
            message: "操作成功!",
          });
          done();
        }, error => {
        },
        (error) => {
          loading();
          console.log(error);
        }
      );
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetails(this.form.id).then(res => {
            this.form = res.data.data;
            this.images = res.data.data.images;
            this.videos = res.data.data.videos;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {status:1}) {
        const { dateTime } = this.query;
        let values = {
          ...params,
          status:1
        };
        if (dateTime) {
          values = {
            ...params,
            begTime: dateTime[0],
            endTime: dateTime[1],
            ...this.query,
          };
          values.dateTime = null;
        }
        this.loading = true;
        getListReport(page.currentPage, page.pageSize,values).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetails(this.form.id).then((res) => {
          this.form = res.data.data;
          this.images = res.data.data.images;
          this.videos = res.data.data.videos;
        });
      }
    }
  };
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = { status: 1 }) {
      const { dateTime } = this.query;
      let values = {
        ...params,
        status: 1,
      };
      if (dateTime) {
        values = {
          ...params,
          begTime: dateTime[0],
          endTime: dateTime[1],
          ...this.query,
        };
        values.dateTime = null;
      }
      this.loading = true;
      getListReport(page.currentPage, page.pageSize, values).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
  },
};
</script>
<style>