shuishen
2024-04-18 4522ab3fe8bd45ee753ef187448c1e884bbc601f
src/views/article/rotation.vue
@@ -1,336 +1,521 @@
<!-- 走访日志 -->
<!-- 轮播图 -->
<template>
    <basic-container>
        <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" ref="crud" @row-del="rowDel"
            v-model="form" :permission="permissionList" @row-update="rowUpdate" @row-save="rowSave"
            :before-open="beforeOpen" @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 size="small" icon="el-icon-delete" plain v-if="permission.article_delete" @click="handleDelete">删
                    除
                </el-button>
            </template>
        </avue-crud>
    </basic-container>
  <basic-container>
    <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" ref="crud" @row-del="rowDel"
      v-model="form" :permission="permissionList" @row-update="rowUpdate" @row-save="rowSave" :before-open="beforeOpen"
      @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 size="small" icon="el-icon-delete" plain v-if="permission.article_delete" @click="handleDelete">删
          除
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>
<script>
import { getList, remove, update, add, getRotation } from "@/api/rotation/rotation"
import { mapGetters } from "vuex"
import website from '@/config/website'
  import {
    getList,
    remove,
    update,
    add,
    getRotation
  } from "@/api/rotation/rotation"
  import {
    getDistrictTree
  } from "@/api/district/index"
  import {
    mapGetters
  } from "vuex"
  import website from '@/config/website'
export default {
    data () {
        return {
            form: {},
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
  export default {
    data() {
      return {
        form: {
          publicFlag: 2
        },
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0,
        },
        datetime: "",
        selectionList: [],
        option: {
          labelWidth: 66,
          searchLabelWidth: 66,
          searchShow: true,
          searchMenuSpan: 3,
          menuWidth: 210,
          height: "auto",
          calcHeight: 54,
          dialogWidth: 950,
          tip: false,
          border: true,
          //stripe:true,
          index: true,
          viewBtn: true,
          selection: true,
          excelBtn: true,
          dialogClickModal: false,
          column: [{
              label: "名称",
              prop: "name",
              span: 12,
              searchSpan: 4,
              search: true,
              searchLabelWidth: 46,
              labelWidth: 100,
            },
            datetime: "",
            selectionList: [],
            option: {
                height: "auto",
                calcHeight: 54,
                dialogWidth: 950,
                tip: false,
                searchShow: true,
                searchMenuSpan: 3,
                menuWidth: 350,
                border: false,
                //stripe:true,
                index: true,
                viewBtn: true,
                selection: true,
                excelBtn: true,
                dialogClickModal: false,
                column: [
                    {
                        label: "名称",
                        prop: "name",
                        span: 12,
                        searchSpan: 4,
                        search: true,
                    },
                    {
                        label: "类型",
                        prop: "type",
                        span: 12,
                        searchSpan: 4,
                        search: true,
                        type: "select",
                        dicData: [
                            {
                                label: "系统",
                                value: "1"
                            },
                            {
                                label: "社区",
                                value: "2"
                            }
                        ]
                    },
                    {
                        width: 156,
                        overHidden: true,
                        label: "所属社区",
                        parent: false,
                        prop: "communityCode",
                        search: true,
                        searchSpan: 4,
                        searchType: 'input',
                        type: "tree",
                        dicUrl: "/api/blade-system/region/tree",
                        props: {
                            label: "name",
                            value: "id"
                        },
                        rules: [
                            {
                                required: true,
                                message: "请选择所属社区",
                                trigger: "blur",
                            },
                        ],
                    },
                    {
                        label: "跳转地址",
                        prop: "junpUrl",
                        span: 12,
                    },
                    {
                        label: "图片",
                        prop: "url",
                        type: "upload",
                        width: 80,
                        listType: "picture-img",
                        action: "/api/blade-resource/oss/endpoint/put-file",
                        propsHttp: {
                            res: "data",
                            name: 'name',
                            url: "link",
                        },
                        span: 24,
                    },
                    {
                        label: "时间",
                        prop: "createTime",
                        width: 160,
                        addDisplay: false,
                        editDisplay: false,
                        type: "date",
                        format: "yyyy-MM-dd HH:mm:ss",
                        valueFormat: "yyyy-MM-dd HH:mm:ss",
                    }
                ],
            {
              width: 110,
              labelWidth: 100,
              label: "类型",
              prop: "type",
              span: 12,
              searchSpan: 4,
              search: true,
              cascader: ["communityCode"],
              type: "select",
              dicData: [{
                  label: "系统",
                  value: 3
                },
                {
                  label: "公安",
                  value: 1
                },
                {
                  label: "综治",
                  value: 2
                }
              ],
              rules: [{
                required: true,
                message: "请选择类型",
                trigger: "blur",
              }, ],
            }, {
              width: 110,
              labelWidth: 100,
              label: "是否公开",
              prop: "publicFlag",
              span: 12,
              searchSpan: 4,
              type: "select",
              type: "select",
              dicData: [{
                  label: "公开",
                  value: 2
                }, {
                  label: "限定公开",
                  value: 1
                },
              ]
            },
            data: [],
        }
            {
              width: 156,
              labelWidth: 100,
              overHidden: true,
              label: "所属社区",
              // parent: false,
              prop: "communityCode",
              multiple: true,
              tags: true,
              hide: true,
              dataType: "string",
              addDisplay: false,
              editDisplay: false,
              type: "tree",
              dicUrl: "/api/blade-system/region/tree?deptNature={{type}}",
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择所属社区",
                trigger: "blur",
              }, ],
            },
            {
              label: "公开范围",
              prop: "rotationRange",
              width: 156,
              labelWidth: 100,
              tags: true,
              type: "tree",
              multiple: true,
              // dateType: "string",
              dataType: "string",
              editDisplay: false,
              addDisplay: false,
              cascader: ['articleId'],
              dicUrl: "/api/blade-district/district/getDistrictTree?filterFlag=1",
              rules: [{
                required: true,
                message: "请选择范围",
                trigger: "blur",
              }, ],
              props: {
                label: "name",
                value: 'id'
              },
            },
            {
              hide: true,
              parent: false,
              label: "文章",
              prop: "articleId",
              search: false,
              viewDisabled: false,
              editDisplay: false,
              addDisplay: false,
              type: 'select',
              dicUrl: `/api/blade-article/article/getArticleByDistrictId?type=4&eventType=1&districtId={{rotationRange}}`,
              formslot: true,
              // cascader: ['vote'],
              props: {
                label: "title",
                value: "id"
              },
              width: 156,
              labelWidth: 100,
              // rules: [{
              //   required: true,
              //   message: "请选择议事文章",
              //   trigger: "blur",
              // }, ],
              change: (val) => {
                console.log("val===>", val)
                // console.log("form===>",this.form)
                if (val.value && !this.form.id) {
                  this.articleRange = val.articleRange;
                  // this.showDialog = true;
                  // this.getDetail(val.value, val.articleRange)
                }
              }
            },
            {
              label: "跳转地址",
              prop: "junpUrl",
              span: 12,
              labelWidth: 100,
            },
            {
              width: 110,
              labelWidth: 100,
              label: "图片",
              prop: "url",
              type: "upload",
              listType: "picture-img",
              action: "/api/blade-resource/oss/endpoint/put-file",
              propsHttp: {
                res: "data",
                name: 'name',
                url: "link",
              },
              span: 24,
            },
            {
              width: 144,
              labelWidth: 100,
              label: "时间",
              prop: "createTime",
              addDisplay: false,
              editDisplay: false,
              type: "date",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
            }
          ],
        },
        data: [],
      }
    },
    watch: {
      'form.publicFlag': {
        handler(newData) {
          const column = this.findObject(this.option.column, "rotationRange")
          if (newData == 1) {
            column.editDisplay = true
            column.addDisplay = true
          } else {
            column.editDisplay = false
            column.addDisplay = false
          }
          const column2 = this.findObject(this.option.column, "articleId")
          if (newData == 1) {
            column2.editDisplay = true
            column2.addDisplay = true
          } else {
            column2.editDisplay = false
            column2.addDisplay = false
          }
        },
      },
      'form.type': {
        handler(newData) {
          const column = this.findObject(this.option.column, "communityCode")
          if (newData != 3) {
            column.editDisplay = true
            column.addDisplay = true
          } else {
            column.editDisplay = false
            column.addDisplay = false
          }
        },
      },
    },
    computed: {
        ...mapGetters(["permission", "userInfo"]),
        permissionList () {
            return {
                addBtn: this.vaildData(this.permission.rotation_add, true),
                viewBtn: this.vaildData(this.permission.rotation_view, true),
                delBtn: this.vaildData(this.permission.rotation_delete, true),
                editBtn: this.vaildData(this.permission.rotation_edit, true),
            }
        },
        ids () {
            let ids = []
            this.selectionList.forEach((ele) => {
                ids.push(ele.id)
            })
            return ids.join(",")
        },
      ...mapGetters(["permission", "userInfo"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.rotation_add, true),
          viewBtn: this.vaildData(this.permission.rotation_view, true),
          delBtn: this.vaildData(this.permission.rotation_delete, true),
          editBtn: this.vaildData(this.permission.rotation_edit, true),
        }
      },
      ids() {
        let ids = []
        this.selectionList.forEach((ele) => {
          ids.push(ele.id)
        })
        return ids.join(",")
      },
    },
    methods: {
        rowSave (row, done, loading) {
            if (row.url.length > 0) {
                var urls = []
                var split = row.url.split(",")
                split.forEach(url => {
                    var names = url.split("jczz/")
                    urls.push(names[1])
                })
                row.url = urls.join(",")
            }
            add(row).then(
                () => {
                    this.onLoad(this.page)
                    this.$message({
                        type: "success",
                        message: "操作成功!",
                    })
                    done()
                },
                (error) => {
                    window.console.log(error)
                    loading()
                }
            )
        },
        rowUpdate (row, index, done, loading) {
            if (row.url.length > 0) {
                var urls = []
                var split = row.url.split(",")
                split.forEach(url => {
                    var names = url.split("jczz/")
                    urls.push(names[1])
                })
                row.url = urls.join(",")
            }
            update(row).then(
                () => {
                    this.onLoad(this.page)
                    this.$message({
                        type: "success",
                        message: "操作成功!",
                    })
                    done()
                },
                (error) => {
                    window.console.log(error)
                    loading()
                }
            )
        },
        rowDel (row) {
            this.$confirm("确定将选择数据删除?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    return remove(row.id)
                })
                .then(() => {
                    this.onLoad(this.page)
                    this.$message({
                        type: "success",
                        message: "操作成功!",
                    })
                })
        },
        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()
        },
        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)) {
                getRotation(this.form.id).then((res) => {
                    this.form = res.data.data
                    if (this.form.url.length > 0) {
                        var urls = []
                        var names = this.form.url.split(",")
                        names.forEach(name => {
                            urls.push(website.minioUrl + name)
                        })
                        this.form.url = urls.join(",")
                    }
                })
            }
            // con
            done()
        },
        currentChange (currentPage) {
            this.page.currentPage = currentPage
        },
        sizeChange (pageSize) {
            this.page.pageSize = pageSize
        },
        refreshChange () {
            this.onLoad(this.page, this.query)
        },
        onLoad (page, params = {}) {
            const { dateTime, communityCode } = this.query
            let values = {
                ...params,
            }
            if (dateTime) {
                values = {
                    ...params,
                    startTime: dateTime[0],
                    endTime: dateTime[1],
                    ...this.query,
                }
                values.dateTime = null
            }
            if (communityCode) {
                values = {
                    ...values,
                    communityName: communityCode
                }
                delete values.communityCode
            }
            this.loading = true
            getList(page.currentPage, page.pageSize, values).then((res) => {
                const data = res.data.data
                this.page.total = data.total
                this.data = data.records
                this.data.forEach(item => {
                    if (item.url.length > 0) {
                        var urls = []
                        var names = item.url.split(",")
                        names.forEach(name => {
                            urls.push(website.minioUrl + name)
                        })
                        item.url = urls.join(",")
                    }
                })
                this.loading = false
                this.selectionClear()
            })
      rowSave(row, done, loading) {
        // if (row.rotationRange) {
        //   row.rotationRange = JSON.stringify(row.rotationRange)
        // }
        if (row.communityCode) {
          row.communityCode = JSON.stringify(row.communityCode)
        }
        if (row.publicFlag == 2) {
          row.rotationRange = ''
          // row.rotationRange = JSON.stringify(row.rotationRange)
        }
        if (row.url.length > 0) {
          var urls = []
          var split = row.url.split(",")
          split.forEach(url => {
            var names = url.split("jczz/")
            urls.push(names[1])
          })
          row.url = urls.join(",")
        }
        add(row).then(
          () => {
            this.onLoad(this.page)
            this.$message({
              type: "success",
              message: "操作成功!",
            })
            done()
          },
          (error) => {
            window.console.log(error)
            loading()
          }
        )
      },
      rowUpdate(row, index, done, loading) {
        // if (row.rotationRange) {
        //   row.rotationRange = JSON.stringify(row.rotationRange)
        // }
        if (row.communityCode) {
          row.communityCode = JSON.stringify(row.communityCode)
        }
        if (row.publicFlag == 2) {
          row.rotationRange = ''
          // row.rotationRange = JSON.stringify(row.rotationRange)
        }
        if (row.url.length > 0) {
          var urls = []
          var split = row.url.split(",")
          split.forEach(url => {
            var names = url.split("jczz/")
            urls.push(names[1])
          })
          row.url = urls.join(",")
        }
        update(row).then(
          () => {
            this.onLoad(this.page)
            this.$message({
              type: "success",
              message: "操作成功!",
            })
            done()
          },
          (error) => {
            window.console.log(error)
            loading()
          }
        )
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
          .then(() => {
            return remove(row.id)
          })
          .then(() => {
            this.onLoad(this.page)
            this.$message({
              type: "success",
              message: "操作成功!",
            })
          })
      },
      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()
      },
      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)) {
          getRotation(this.form.id).then((res) => {
            this.form = res.data.data
            // if (this.form.rotationRange) {
            //   this.form.rotationRange = JSON.parse(this.form.rotationRange)
            // }
            // if (this.form.communityCode) {
            //   this.form.communityCode = JSON.parse(this.form.communityCode)
            // }
            if (this.form.url.length > 0) {
              var urls = []
              var names = this.form.url.split(",")
              names.forEach(name => {
                urls.push(website.minioUrl + name)
              })
              this.form.url = urls.join(",")
            }
          })
        }
        // con
        done()
      },
      currentChange(currentPage) {
        this.page.currentPage = currentPage
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize
      },
      refreshChange() {
        this.onLoad(this.page, this.query)
      },
      onLoad(page, params = {}) {
        const {
          dateTime,
          communityCode
        } = this.query
        let values = {
          ...params,
        }
        if (dateTime) {
          values = {
            ...params,
            startTime: dateTime[0],
            endTime: dateTime[1],
            ...this.query,
          }
          values.dateTime = null
        }
        if (communityCode) {
          values = {
            ...values,
            communityName: communityCode
          }
          delete values.communityCode
        }
        this.loading = true
        getList(page.currentPage, page.pageSize, values).then((res) => {
          const data = res.data.data
          this.page.total = data.total
          this.data = data.records
          this.data.forEach(item => {
            // if (item.rotationRange) {
            //   item.rotationRange = JSON.parse(item.rotationRange)
            // }
            // if (item.communityCode) {
            //   item.communityCode = JSON.parse(item.communityCode)
            // }
            if (item.url.length > 0) {
              var urls = []
              var names = item.url.split(",")
              names.forEach(name => {
                urls.push(website.minioUrl + name)
              })
              item.url = urls.join(",")
            }
          })
          this.loading = false
          this.selectionClear()
        })
        getDistrictTree(params = {
          filterFlag: 1
        }).then((res) => {
          const data = res.data.data
          this.districtTree = data
          const column = this.findObject(this.option.column, "articleList")
          column.dicData = res.data.data
          this.loading = false
        })
      }
    },
}
  }
</script>
<style>
.avue-upload__icon {
  .avue-upload__icon {
    line-height: 6;
}
</style>
  }
</style>