<template>
  <basic-container>
    <avue-form :option="option"
               v-model = "form"
               @submit="addBills">
    </avue-form>
    <el-dialog title="缴费项">
      <BillsItem></BillsItem>
    </el-dialog>
  </basic-container>
</template>

<script>
  import {getList, getDetail, add, update, remove} from "@/api/estate/bills";
  import BillsItem from "@/components/bills-comp/bills-item"
  import {mapGetters} from "vuex";

  export default {
    name:'bills-add',
    components:{BillsItem},
    data() {
      return {
        pidprop:'',
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height:'auto',
          calcHeight: 30,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          dialogClickModal: false,
          column: [
            {
              label: "所属社区",
              prop: "agencyId",
              slot: true,
              search: true,
              cascaderItem: ['residentialId'],
              type: "select",
              remote: true,
              dicUrl: "/api/cyzh-community/agency/list",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择所属社区",
                trigger: "blur"
              }]
            },
            {
              label: "所属小区",
              prop: "residentialId",
              slot: true,
              type: "select",
              search: true,
              cascaderItem: ['buildingId'],
              dicUrl: "/api/cyzh-community/residential/list?agencyId={{key}}",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择所属小区",
                trigger: "blur"
              }]
            },
            {
              label: "所属楼栋",
              prop: "buildingId",
              slot: true,
              type: "select",
              search: true,
              cascaderItem: ['unitId'],
              dicUrl: `/api/cyzh-community/building/list?residentialId={{key}}`,
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请输入楼栋Id",
                trigger: "blur"
              }]
            },
            {
              label: "所属单元",
              prop: "unitId",
              slot: true,
              type: "select",
              search: true,
              cascaderItem: ['floorId'],
              dicUrl: "/api/cyzh-community/unit/list?buildingId={{key}}",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请输入单元Id",
                trigger: "blur"
              }]
            },
            {
              label: "所属楼层",
              prop: "floorId",
              slot: true,
              type: "select",
              search: true,
              cascaderItem: ['roomId'],
              dicUrl: "/api/cyzh-community/floor/list?unitId={{key}}",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请输入楼层Id",
                trigger: "blur"
              }]
            },
            {
              label: "所属房间",
              prop: "roomId",
              slot: true,
              type: "select",
              search: true,
              dicUrl: "/api/cyzh-community/room/list?floorId={{key}}",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请输入房间Id",
                trigger: "blur"
              }]
            },
            {
              label: "资源路径",
              prop: "orgPosition",
              hide:true,
              display:false,
              rules: [{
                required: true,
                message: "请输入资源路径",
                trigger: "blur"
              }]
            },
            {
              label: "账单日期",
              prop: "billsDate",
              rules: [{
                required: true,
                message: "请输入账单日期",
                trigger: "blur"
              }]
            },
            {
              label: "账单总费用(元)",
              prop: "totalFee",
              rules: [{
                required: true,
                message: "请输入账单总费用",
                trigger: "blur"
              }]
            },
            {
              label: "物业公司",
              prop: "estateCompany",
              rules: [{
                required: true,
                message: "请输入物业公司",
                trigger: "blur"
              }]
            },
            // {
            //   label: "物业公司Id",
            //   prop: "estateCompanyId",
            //   hide:true,
            //   rules: [{
            //     required: true,
            //     message: "请输入物业公司Id",
            //     trigger: "blur"
            //   }]
            // },
            {
              label: "缴费方式",
              prop: "payWay",
              type:"select",
              dicData: [
                {
                  label:'微信支付',
                  value:1
                },{
                  label:'其他方式',
                  value:2
                }
              ],
              rules: [{
                required: true,
                message: "请输入缴费方式",
                trigger: "blur"
              }]
            },
            // {
            //   label: "支付流水",
            //   prop: "payId",
            //   rules: [{
            //     required: true,
            //     message: "请输入支付流水",
            //     trigger: "blur"
            //   }]
            // },
            {
              label: "支付状态",
              prop: "payStatus",
              type:'select',
              dicData:[
                {
                  label: '未支付',
                  value: 1
                },{
                  label: '已支付',
                  value: 2
                }
              ],
              rules: [{
                required: true,
                message: "请选择支付状态",
                trigger: "blur"
              }]
            },
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.bills_add, false),
          viewBtn: this.vaildData(this.permission.bills_view, false),
          delBtn: this.vaildData(this.permission.bills_delete, false),
          editBtn: this.vaildData(this.permission.bills_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      addBills(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, 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: "操作成功!"
            });
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      onLoad(page, params = {}) {
        this.loading = true;
        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>
</style>
