shuishen
2024-04-18 4522ab3fe8bd45ee753ef187448c1e884bbc601f
src/views/property/propertyCharge.vue
@@ -1,371 +1,380 @@
<template>
    <basic-container>
        <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" ref="crud" v-model="form"
            :permission="permissionList" @search-change="searchChange" @search-reset="searchReset" @row-update="rowUpdate"
            @row-save="rowSave" @row-del="rowDel" :before-open="beforeOpen" @selection-change="selectionChange"
            @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
        </avue-crud>
    </basic-container>
  <basic-container>
    <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" ref="crud" v-model="form"
      :permission="permissionList" @search-change="searchChange" @search-reset="searchReset" @row-update="rowUpdate"
      @row-save="rowSave" @row-del="rowDel" :before-open="beforeOpen" @selection-change="selectionChange"
      @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
    </avue-crud>
  </basic-container>
</template>
<script>
import { mapGetters } from "vuex"
import { getDetail, getList, add, update, remove } from "@/api/property/propertyCharge"
import website from "@/config/website"
import func from "@/util/func"
import { validatePhone } from "@/util/validate"
const searchSpan = 4
const labelWidth = 110
export default {
  import {
    mapGetters
  } from "vuex"
  import {
    getDetail,
    getList,
    add,
    update,
    remove
  } from "@/api/property/propertyCharge"
  import website from "@/config/website"
  import func from "@/util/func"
  import {
    validatePhone
  } from "@/util/validate"
  const searchSpan = 4
  const labelWidth = 110
  export default {
    name: "propertyCharge",
    data () {
        return {
            form: {},
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0,
        },
        datetime: "",
        selectionList: [],
        memberFlag: false,
        option: {
          labelWidth: 96,
          searchLabelWidth: 96,
          searchShow: true,
          searchMenuSpan: 3,
          menuWidth: 210,
          dialogMenuPosition: 'center',
          // menu: false,
          // addBtn: false,
          border: true,
          index: true,
          selection: false,
          height: "auto",
          calcHeight: 54,
          dialogWidth: 950,
          tip: false,
          //stripe:true,
          viewBtn: true,
          excelBtn: true,
          dialogClickModal: false,
          column: [{
              label: "物业公司",
              labelWidth: labelWidth,
              prop: "propertyId",
              checkStrictly: true,
              dicUrl: "/api/blade-propertyCompany/propertyCompany/getPropertyCompanyList",
              props: {
                label: "name",
                value: "deptId",
              },
              searchSpan: 4,
              search: true,
              searchLabelWidth: 76,
              disabled: false,
              type: "select",
              rules: [{
                required: true,
                message: "请选择物业公司",
                trigger: ["blur", "change"]
              }, ],
            },
            datetime: "",
            selectionList: [],
            memberFlag: false,
            option: {
                labelWidth: 96,
                searchLabelWidth: 96,
                searchShow: true,
                searchMenuSpan: 3,
                menuWidth: 210,
                // menu: false,
                // addBtn: false,
                border: true,
                index: true,
                selection: false,
                height: "auto",
                calcHeight: 54,
                dialogWidth: 950,
                tip: false,
                //stripe:true,
                viewBtn: true,
                excelBtn: true,
                dialogClickModal: false,
                column: [
                    {
                        label: "物业公司",
                        labelWidth: labelWidth,
                        prop: "propertyId",
                        checkStrictly: true,
                        dicUrl: "/api/blade-propertyCompany/propertyCompany/getPropertyCompanyList",
                        props: {
                            label: "name",
                            value: "deptId",
                        },
                        searchSpan: 4,
                        search: true,
                        searchLabelWidth: 76,
                        disabled: false,
                        type: "select",
                        rules: [{
                            required: true,
                            message: "请选择物业公司",
                            trigger: ["blur", "change"]
                        },],
                    },
                    {
                        label: "类型",
                        labelWidth: labelWidth,
                        prop: "payType",
                        checkStrictly: true,
                        dicUrl: "/api/blade-system/dict-biz/dictionary?code=payType",
                        props: {
                            label: "dictValue",
                            value: "dictKey",
                        },
                        type: "select",
                        rules: [{
                            required: true,
                            message: "请选择类型",
                            trigger: ["blur", "change"]
                        },],
                    },
                    {
                        label: "收费项名称",
                        labelWidth: labelWidth,
                        prop: "name",
                        searchSpan: searchSpan,
                        searchLabelWidth: labelWidth,
                        search: true,
                        rules: [{
                            required: true,
                            message: "请输入收费项名称",
                            trigger: ["blur", "change"]
                        },],
                    },
                    {
                        label: "计算方式",
                        labelWidth: labelWidth,
                        prop: "calculationFormula",
                        checkStrictly: true,
                        dicUrl: "/api/blade-system/dict-biz/dictionary?code=payCalculationFormula",
                        props: {
                            label: "dictValue",
                            value: "dictKey",
                        },
                        type: "select",
                        rules: [{
                            required: true,
                            message: "请选择计算方式",
                            trigger: ["blur", "change"]
                        },],
                    },
                    {
                        label: "单价(元)",
                        labelWidth: labelWidth,
                        prop: "unitPrice",
                        type: 'number',
                        precision: 2,
                        rules: [{
                            required: true,
                            message: "请输入单价",
                            trigger: ["blur", "change"]
                        }]
                    },
                    {
                        label: "缴费周期",
                        labelWidth: labelWidth,
                        placeholder: "几个月收费一次",
                        prop: "payPeriod",
                        checkStrictly: true,
                        dicUrl: "/api/blade-system/dict-biz/dictionary?code=payPeriod",
                        props: {
                            label: "dictValue",
                            value: "dictKey",
                        },
                        type: "select",
                        rules: [{
                            required: true,
                            message: "请选择缴费周期",
                            trigger: ["blur", "change"]
                        },],
                    },
                    {
                        label: "时间",
                        labelWidth: labelWidth,
                        placeholder: "时间",
                        prop: "createTime",
                        addDisplay: false,
                        editDisplay: false,
                        rules: [{
                            required: true,
                            message: "请选择缴费周期",
                            trigger: ["blur", "change"]
                        },],
                    },
                ],
            {
              label: "类型",
              labelWidth: labelWidth,
              prop: "payType",
              checkStrictly: true,
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=payType",
              props: {
                label: "dictValue",
                value: "dictKey",
              },
              type: "select",
              rules: [{
                required: true,
                message: "请选择类型",
                trigger: ["blur", "change"]
              }, ],
            },
            data: [],
        }
            {
              label: "收费项名称",
              labelWidth: labelWidth,
              prop: "name",
              searchSpan: searchSpan,
              searchLabelWidth: labelWidth,
              search: true,
              rules: [{
                required: true,
                message: "请输入收费项名称",
                trigger: ["blur", "change"]
              }, ],
            },
            {
              label: "计算方式",
              labelWidth: labelWidth,
              prop: "calculationFormula",
              checkStrictly: true,
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=payCalculationFormula",
              props: {
                label: "dictValue",
                value: "dictKey",
              },
              type: "select",
              rules: [{
                required: true,
                message: "请选择计算方式",
                trigger: ["blur", "change"]
              }, ],
            },
            {
              label: "单价(元)",
              labelWidth: labelWidth,
              prop: "unitPrice",
              type: 'number',
              precision: 2,
              rules: [{
                required: true,
                message: "请输入单价",
                trigger: ["blur", "change"]
              }]
            },
            {
              label: "缴费周期",
              labelWidth: labelWidth,
              placeholder: "几个月收费一次",
              prop: "payPeriod",
              checkStrictly: true,
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=payPeriod",
              props: {
                label: "dictValue",
                value: "dictKey",
              },
              type: "select",
              rules: [{
                required: true,
                message: "请选择缴费周期",
                trigger: ["blur", "change"]
              }, ],
            },
            {
              label: "时间",
              labelWidth: labelWidth,
              placeholder: "时间",
              prop: "createTime",
              addDisplay: false,
              editDisplay: false,
              rules: [{
                required: true,
                message: "请选择缴费周期",
                trigger: ["blur", "change"]
              }, ],
            },
          ],
        },
        data: [],
      }
    },
    watch: {},
    computed: {
        ...mapGetters(["permission", "userInfo"]),
        permissionList () {
            return {
                addBtn: this.vaildData(this.permission.gridWorkLog_add, true),
                viewBtn: this.vaildData(this.permission.gridWorkLog_view, true),
                delBtn: this.vaildData(this.permission.gridWorkLog_delete, true),
                editBtn: this.vaildData(this.permission.gridWorkLog_edit, true),
      ...mapGetters(["permission", "userInfo"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.gridWorkLog_add, true),
          viewBtn: this.vaildData(this.permission.gridWorkLog_view, true),
          delBtn: this.vaildData(this.permission.gridWorkLog_delete, true),
          editBtn: this.vaildData(this.permission.gridWorkLog_edit, true),
        }
      },
      ids() {
        let ids = []
        this.selectionList.forEach((ele) => {
          ids.push(ele.id)
        })
        return ids.join(",")
      },
      textDispose() {
        return (row, flag, type) => {
          if (row[flag] || row[type] == null) {
            return row[type]
          } else {
            if (type == 'idCard') {
              return row[type].replace(/^(.{6})(?:\d+)(.{4})$/, "$1******$2")
            } else {
              return row[type].replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2")
            }
        },
        ids () {
            let ids = []
            this.selectionList.forEach((ele) => {
                ids.push(ele.id)
            })
            return ids.join(",")
        },
        textDispose () {
            return (row, flag, type) => {
                if (row[flag] || row[type] == null) {
                    return row[type]
                } else {
                    if (type == 'idCard') {
                        return row[type].replace(/^(.{6})(?:\d+)(.{4})$/, "$1******$2")
                    } else {
                        return row[type].replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2")
                    }
                }
            }
        },
          }
        }
      },
    },
    methods: {
        showStringDispose (row, type) {
            row[type] = !row[type]
        },
        manageMember (row) {
            this.memberFlag = true
            var that = this
            this.$nextTick(() => {
                that.$refs.partyOrganizationMember.init(row)
            })
        },
        rowSave (row, done, loading) {
            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.urls.length > 0) {
                var urls = []
                var split = row.urls.split(",")
                split.forEach(url => {
                    var names = url.split("jczz/")
                    urls.push(names[1])
                })
                row.urls = 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: "操作成功!",
                    })
                })
        },
        // 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)) {
                // getDetail(this.form.id).then((res) => {
                //     this.form = res.data.data
                //     const column = this.findObject(this.option.column, "principalId")
                //     let arr = []
                //     arr.push(this.form.areaId)
                //     column.defaultExpandedKeys = arr
                // })
            }
            // //如果当前角色为物业管理员,则默认物业公司为该用户的物业公司
            // if (this.userInfo.role_name.indexOf("wygly")>-1){
            //   let column = this.findObject(this.option.column, "propertyId")
            //   column.disabled = true
            //   column.search = false
            //   this.form.propertyId = this.userInfo.dept_id
            // }
            done()
        },
        searchReset () {
            this.query = {}
      showStringDispose(row, type) {
        row[type] = !row[type]
      },
      manageMember(row) {
        this.memberFlag = true
        var that = this
        this.$nextTick(() => {
          that.$refs.partyOrganizationMember.init(row)
        })
      },
      rowSave(row, done, loading) {
        add(row).then(
          () => {
            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 = {}) {
            this.loading = true
            //如果当前角色为物业管理员,则默认筛选该物业公司
            if (this.userInfo.role_name.indexOf("wygly") > -1) {
                let column = this.findObject(this.option.column, "propertyId")
                column.disabled = true
                column.search = false
                this.form.propertyId = this.userInfo.dept_id
                params.propertyId = this.userInfo.dept_id
            }
            getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
                const data = res.data.data
                this.page.total = data.total
                this.data = data.records
                this.loading = false
                this.selectionClear()
            this.$message({
              type: "success",
              message: "操作成功!",
            })
            done()
          },
          (error) => {
            window.console.log(error)
            loading()
          }
        )
      },
      rowUpdate(row, index, done, loading) {
        if (row.urls.length > 0) {
          var urls = []
          var split = row.urls.split(",")
          split.forEach(url => {
            var names = url.split("jczz/")
            urls.push(names[1])
          })
          row.urls = 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: "操作成功!",
            })
          })
      },
      // 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)) {
          // getDetail(this.form.id).then((res) => {
          //     this.form = res.data.data
          //     const column = this.findObject(this.option.column, "principalId")
          //     let arr = []
          //     arr.push(this.form.areaId)
          //     column.defaultExpandedKeys = arr
          // })
        }
        // //如果当前角色为物业管理员,则默认物业公司为该用户的物业公司
        // if (this.userInfo.role_name.indexOf("wygly")>-1){
        //   let column = this.findObject(this.option.column, "propertyId")
        //   column.disabled = true
        //   column.search = false
        //   this.form.propertyId = this.userInfo.dept_id
        // }
        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 = {}) {
        this.loading = true
        //如果当前角色为物业管理员,则默认筛选该物业公司
        if (this.userInfo.role_name.indexOf("wygly") > -1) {
          let column = this.findObject(this.option.column, "propertyId")
          column.disabled = true
          column.search = false
          this.form.propertyId = this.userInfo.dept_id
          params.propertyId = this.userInfo.dept_id
        }
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data
          this.page.total = data.total
          this.data = data.records
          this.loading = false
          this.selectionClear()
        })
      }
    },
}
  }
</script>
<style scoped></style>
<style scoped></style>