<!-- 供应商维护 -->
<template>
  <div class="container">
    <my-table :data="data" :columns="columns" :table-filter="tableFilter" :table-page="params" @event-handle="eventHandle" @on-change="changePage"></my-table>
    <my-modal-form
      v-model="show"
      :title="title"
      :isMaterial="true"
      width="800px"
      :config="formType === 'add'? formConfig: formType === 'edit'? editFormConfig : showFormConfig"
      :rule-validate="ruleValidate"
      :data="formData"
      :type="formType"
      @confirm="cfm">
    </my-modal-form>
    <provider-account-form v-model="accountShow"></provider-account-form>
  </div>
</template>

<script>
import { GetFactoryPageList, FactoryAdd, FactoryUpdate, FactoryDelete, GetMaterialCategoryZTree } from '@/api/baseData'
import { GetUserPageList } from '@/api/user'
import MyTable from '_c/my-table/my-table'
import MyModalForm from '_c/my-modal-form/my-modal-form'
import ProviderAccountForm from './provider-account-form'
export default {
  name: 'provider_maintenance',
  components: {
    MyTable,
    MyModalForm,
    ProviderAccountForm
  },
  data () {
    return {
      title: '',
      show: false,
      accountShow: false,
      data: [],
      deleteId: '',
      formType: '',
      formData: {},
      ruleValidate: {
        name123: [
          { required: true, message: '仓库名称不能为空', trigger: 'blur' }
        ]
      },
      formConfig: [
        {
          type: 'input',
          label: '供应商代码',
          key: 'code',
          disabled: true,
          placeholder: '系统自动生成',
          span: 12
        },
        // {
        //   type: 'selectSearch',
        //   label: '绑定用户',
        //   key: 'bingdUserID',
        //   list: [],
        //   placeholder: '请输入绑定用户',
        //   span: 12
        // },
        {
          type: 'input',
          label: '登录账户',
          key: 'userAccount',
          placeholder: '请输入登录账户',
          span: 12
        },
        {
          type: 'selectSearch',
          label: '物料类型',
          key: 'categoryCode',
          list: [],
          placeholder: '请选择物料类型',
          span: 12
        },
        {
          type: 'upload',
          label: '供应商名称',
          text: '上传营业执照',
          key: 'name'
        },
        {
          type: 'input',
          label: '账期',
          key: 'accountDate',
          placeholder: '请输入账期',
          span: 12
        },
        {
          type: 'input',
          label: '账期说明',
          key: 'accountDateRemark',
          placeholder: '请输入账期说明',
          span: 12
        },
        {
          type: 'input',
          comType: 'textarea',
          label: '备注',
          key: 'remark',
          placeholder: '请输入仓库说明'
        },
        {
          type: 'tabs',
          hiddenLabel: true,
          tabs: [
            {
              title: '工商信息',
              forms: [
                {
                  type: 'input',
                  label: '法定代表人',
                  key: 'legalPerson',
                  placeholder: '请输入法定代表人',
                  span: 12
                },
                {
                  type: 'input',
                  label: '社会信用代码',
                  key: 'societyCreditCode',
                  placeholder: '请输入社会信用代码',
                  span: 12
                },
                {
                  type: 'input',
                  label: '注册地址',
                  key: 'registeredAddress',
                  placeholder: '请输入注册地址'
                },
                {
                  type: 'input',
                  label: '成立日期',
                  key: 'establishDate',
                  placeholder: '请输入成立日期',
                  span: 12
                },
                {
                  type: 'input',
                  label: '注册资本',
                  key: 'registeredCapital',
                  placeholder: '请输入注册资本',
                  span: 12
                },
                {
                  type: 'input',
                  label: '企业类型',
                  key: 'enterpriseType',
                  placeholder: '请输入企业类型',
                  span: 12
                },
                {
                  type: 'input',
                  label: '营业期限',
                  key: 'businessTerm',
                  placeholder: '请输入营业期限',
                  span: 12
                },
                {
                  type: 'input',
                  comType: 'textarea',
                  label: '营业范围',
                  key: 'businessScope',
                  placeholder: '请输入营业范围'
                }
              ]
            },
            {
              title: '联系信息',
              forms: [
                {
                  type: 'input',
                  label: '联系人',
                  key: 'linkMen',
                  placeholder: '请输入联系人',
                  span: 12
                },
                {
                  type: 'input',
                  label: '手机号码',
                  key: 'mobile',
                  placeholder: '请输入手机号码',
                  span: 12
                },
                {
                  type: 'input',
                  label: '固定电话',
                  key: 'telephone',
                  placeholder: '请输入固定电话',
                  span: 12
                },
                {
                  type: 'input',
                  label: '电子邮箱',
                  key: 'email',
                  placeholder: '请输入电子邮箱',
                  span: 12
                },
                {
                  type: 'input',
                  label: '传真',
                  key: 'fax',
                  placeholder: '请输入传真',
                  span: 12
                }
              ]
            },
            {
              title: '账户信息',
              forms: [
                {
                  type: 'input',
                  label: '对公户名',
                  key: 'bankAccoutName',
                  placeholder: '请输入对公户名',
                  span: 12
                },
                {
                  type: 'input',
                  label: '开户银行',
                  key: 'openBank',
                  placeholder: '请输入开户银行',
                  span: 12
                },
                {
                  type: 'input',
                  label: '对公账号',
                  key: 'bankAccout',
                  placeholder: '请输入对公账号',
                  span: 12
                },
                {
                  type: '',
                  hiddenLabel: true
                },
                {
                  type: 'input',
                  label: '对私户名',
                  key: 'priOpenBank',
                  placeholder: '请输入对私户名',
                  span: 12
                },
                {
                  type: 'input',
                  label: '开户银行',
                  key: 'priBankAccout',
                  placeholder: '请输入开户银行',
                  span: 12
                },
                {
                  type: 'input',
                  label: '对私账号',
                  key: 'priBankAccoutName',
                  placeholder: '请输入对私账号',
                  span: 12
                }
              ]
            },
            {
              title: '维护记录',
              type: 'picList',
              key: 'facPicList'
            }
          ]
        }
      ],
      editFormConfig: [
        {
          type: 'input',
          label: '供应商代码',
          key: 'code',
          placeholder: '请输入供应商代码',
          span: 12
        },
        // {
        //   type: 'selectSearch',
        //   label: '绑定用户',
        //   key: 'bingdUserID',
        //   list: [],
        //   placeholder: '请输入绑定用户',
        //   span: 12
        // },
        {
          type: 'input',
          label: '登录账户',
          disabled: true,
          key: 'userAccount',
          placeholder: '请输入登录账户',
          span: 12
        },
        {
          type: 'selectSearch',
          label: '物料类型',
          key: 'categoryCode',
          list: [],
          placeholder: '请选择物料类型',
          span: 12
        },
        {
          type: 'upload',
          label: '供应商名称',
          text: '上传营业执照',
          key: 'name'
        },
        {
          type: 'input',
          label: '账期',
          key: 'accountDate',
          placeholder: '请输入账期',
          span: 12
        },
        {
          type: 'input',
          label: '账期说明',
          key: 'accountDateRemark',
          placeholder: '请输入账期说明',
          span: 12
        },
        {
          type: 'input',
          comType: 'textarea',
          label: '备注',
          key: 'remark',
          placeholder: '请输入仓库说明'
        },
        {
          type: 'tabs',
          hiddenLabel: true,
          tabs: [
            {
              title: '工商信息',
              forms: [
                {
                  type: 'input',
                  label: '法定代表人',
                  key: 'legalPerson',
                  placeholder: '请输入法定代表人',
                  span: 12
                },
                {
                  type: 'input',
                  label: '社会信用代码',
                  key: 'societyCreditCode',
                  placeholder: '请输入社会信用代码',
                  span: 12
                },
                {
                  type: 'input',
                  label: '注册地址',
                  key: 'registeredAddress',
                  placeholder: '请输入注册地址'
                },
                {
                  type: 'input',
                  label: '成立日期',
                  key: 'establishDate',
                  placeholder: '请输入成立日期',
                  span: 12
                },
                {
                  type: 'input',
                  label: '注册资本',
                  key: 'registeredCapital',
                  placeholder: '请输入注册资本',
                  span: 12
                },
                {
                  type: 'input',
                  label: '企业类型',
                  key: 'enterpriseType',
                  placeholder: '请输入企业类型',
                  span: 12
                },
                {
                  type: 'input',
                  label: '营业期限',
                  disabled: true,
                  key: 'businessTerm',
                  placeholder: '请输入营业期限',
                  span: 12
                },
                {
                  type: 'input',
                  comType: 'textarea',
                  label: '营业范围',
                  key: 'businessScope',
                  placeholder: '请输入营业范围'
                }
              ]
            },
            {
              title: '联系信息',
              forms: [
                {
                  type: 'input',
                  label: '联系人',
                  key: 'linkMen',
                  placeholder: '请输入联系人',
                  span: 12
                },
                {
                  type: 'input',
                  label: '手机号码',
                  key: 'mobile',
                  placeholder: '请输入手机号码',
                  span: 12
                },
                {
                  type: 'input',
                  label: '固定电话',
                  key: 'telephone',
                  placeholder: '请输入固定电话',
                  span: 12
                },
                {
                  type: 'input',
                  label: '电子邮箱',
                  key: 'email',
                  placeholder: '请输入电子邮箱',
                  span: 12
                },
                {
                  type: 'input',
                  label: '传真',
                  key: 'fax',
                  placeholder: '请输入传真',
                  span: 12
                }
              ]
            },
            {
              title: '账户信息',
              forms: [
                {
                  type: 'input',
                  label: '对公户名',
                  key: 'bankAccoutName',
                  placeholder: '请输入对公户名',
                  span: 12
                },
                {
                  type: 'input',
                  label: '开户银行',
                  key: 'openBank',
                  placeholder: '请输入开户银行',
                  span: 12
                },
                {
                  type: 'input',
                  label: '对公账号',
                  key: 'bankAccout',
                  placeholder: '请输入对公账号',
                  span: 12
                },
                {
                  type: '',
                  hiddenLabel: true
                },
                {
                  type: 'input',
                  label: '对私户名',
                  key: 'priOpenBank',
                  placeholder: '请输入对私户名',
                  span: 12
                },
                {
                  type: 'input',
                  label: '开户银行',
                  key: 'priBankAccout',
                  placeholder: '请输入开户银行',
                  span: 12
                },
                {
                  type: 'input',
                  label: '对私账号',
                  key: 'priBankAccoutName',
                  placeholder: '请输入对私账号',
                  span: 12
                }
              ]
            },
            {
              title: '维护记录',
              type: 'picList',
              key: 'facPicList'
            },
            {
              title: '主营价格',
              type: 'material'
            },
            {
              title: '采购分析',
              type: 'charts'
            }
          ]
        }
      ],
      showFormConfig: [
        {
          type: 'input',
          label: '供应商代码',
          disabled: true,
          key: 'code',
          placeholder: '请输入供应商代码',
          span: 12
        },
        // {
        //   type: 'selectSearch',
        //   label: '绑定用户',
        //   disabled: true,
        //   key: 'bingdUserID',
        //   list: [],
        //   placeholder: '请输入绑定用户',
        //   span: 12
        // },
        {
          type: 'input',
          label: '登录账户',
          disabled: true,
          key: 'userAccount',
          placeholder: '请输入登录账户',
          span: 12
        },
        {
          type: 'selectSearch',
          label: '物料类型',
          key: 'categoryCode',
          disabled: true,
          list: [],
          placeholder: '请选择物料类型',
          span: 12
        },
        {
          type: 'upload',
          label: '供应商名称',
          disabled: true,
          text: '上传营业执照',
          key: 'name'
        },
        {
          type: 'input',
          label: '账期',
          disabled: true,
          key: 'accountDate',
          placeholder: '请输入账期',
          span: 12
        },
        {
          type: 'input',
          label: '账期说明',
          disabled: true,
          key: 'accountDateRemark',
          placeholder: '请输入账期说明',
          span: 12
        },
        {
          type: 'input',
          comType: 'textarea',
          label: '备注',
          disabled: true,
          key: 'remark',
          placeholder: '请输入仓库说明'
        },
        {
          type: 'tabs',
          hiddenLabel: true,
          tabs: [
            {
              title: '工商信息',
              forms: [
                {
                  type: 'input',
                  label: '法定代表人',
                  disabled: true,
                  key: 'legalPerson',
                  placeholder: '请输入法定代表人',
                  span: 12
                },
                {
                  type: 'input',
                  label: '社会信用代码',
                  disabled: true,
                  key: 'societyCreditCode',
                  placeholder: '请输入社会信用代码',
                  span: 12
                },
                {
                  type: 'input',
                  label: '注册地址',
                  disabled: true,
                  key: 'registeredAddress',
                  placeholder: '请输入注册地址'
                },
                {
                  type: 'input',
                  label: '成立日期',
                  disabled: true,
                  key: 'establishDate',
                  placeholder: '请输入成立日期',
                  span: 12
                },
                {
                  type: 'input',
                  label: '注册资本',
                  disabled: true,
                  key: 'registeredCapital',
                  placeholder: '请输入注册资本',
                  span: 12
                },
                {
                  type: 'input',
                  label: '企业类型',
                  disabled: true,
                  key: 'enterpriseType',
                  placeholder: '请输入企业类型',
                  span: 12
                },
                {
                  type: 'input',
                  label: '营业期限',
                  disabled: true,
                  key: 'businessTerm',
                  placeholder: '请输入营业期限',
                  span: 12
                },
                {
                  type: 'input',
                  comType: 'textarea',
                  label: '营业范围',
                  disabled: true,
                  key: 'businessScope',
                  placeholder: '请输入营业范围'
                }
              ]
            },
            {
              title: '联系信息',
              forms: [
                {
                  type: 'input',
                  label: '联系人',
                  disabled: true,
                  key: 'linkMen',
                  placeholder: '请输入联系人',
                  span: 12
                },
                {
                  type: 'input',
                  label: '手机号码',
                  disabled: true,
                  key: 'mobile',
                  placeholder: '请输入手机号码',
                  span: 12
                },
                {
                  type: 'input',
                  label: '固定电话',
                  disabled: true,
                  key: 'telephone',
                  placeholder: '请输入固定电话',
                  span: 12
                },
                {
                  type: 'input',
                  label: '电子邮箱',
                  disabled: true,
                  key: 'email',
                  placeholder: '请输入电子邮箱',
                  span: 12
                },
                {
                  type: 'input',
                  label: '传真',
                  disabled: true,
                  key: 'fax',
                  placeholder: '请输入传真',
                  span: 12
                }
              ]
            },
            {
              title: '账户信息',
              forms: [
                {
                  type: 'input',
                  label: '对公户名',
                  disabled: true,
                  key: 'bankAccoutName',
                  placeholder: '请输入对公户名',
                  span: 12
                },
                {
                  type: 'input',
                  label: '开户银行',
                  disabled: true,
                  key: 'openBank',
                  placeholder: '请输入开户银行',
                  span: 12
                },
                {
                  type: 'input',
                  label: '对公账号',
                  disabled: true,
                  key: 'bankAccout',
                  placeholder: '请输入对公账号',
                  span: 12
                },
                {
                  type: '',
                  hiddenLabel: true
                },
                {
                  type: 'input',
                  label: '对私户名',
                  disabled: true,
                  key: 'priOpenBank',
                  placeholder: '请输入对私户名',
                  span: 12
                },
                {
                  type: 'input',
                  label: '开户银行',
                  disabled: true,
                  key: 'priBankAccout',
                  placeholder: '请输入开户银行',
                  span: 12
                },
                {
                  type: 'input',
                  label: '对私账号',
                  disabled: true,
                  key: 'priBankAccoutName',
                  placeholder: '请输入对私账号',
                  span: 12
                }
              ]
            },
            {
              title: '维护记录',
              type: 'picList',
              key: 'facPicList'
            },
            {
              title: '主营价格',
              type: 'material'
            },
            {
              title: '采购分析',
              type: 'charts'
            }
          ]
        }
      ],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '供应商代码',
          key: 'code',
          minWidth: 100
        },
        {
          title: '供应商名称',
          key: 'name',
          minWidth: 200
        },
        {
          title: '物料类型',
          key: 'categoryName',
          minWidth: 150
        },
        {
          title: '账期',
          key: 'accountDate',
          minWidth: 100
        },
        {
          title: '账期说明',
          key: 'accountDateRemark',
          minWidth: 100
        },
        {
          title: '联系人',
          key: 'linkMen',
          minWidth: 100
        },
        {
          title: '联系电话',
          key: 'telephone',
          minWidth: 150
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          fixed: 'right',
          width: 150,
          render: (h, params) => {
            return h('div', [
              h(
                'Icon',
                {
                  props: {
                    custom: 'iconfont icon-chakan',
                    size: '20',
                    color: '#6bc01e'
                  },
                  style: {
                    marginRight: '20px'
                  },
                  on: {
                    click: () => {
                      for (const key in params.row) {
                        this.formData[key] = params.row[key]
                      }
                      this.formType = 'form'
                      this.title = '供应商详情'
                      this.show = true
                      // GetFacKeepRecordPageList({
                      //   pageIndex: 1,
                      //   pageSize: 999,
                      //   factoryId: params.row.id
                      // }).then(res => {
                      //   if (res.code === 0) {
                      //     this.formData.facPicList = res.result.list
                      //
                      //   }
                      // })
                    }
                  }
                },
                '查看明细'
              ),
              h(
                'Icon',
                {
                  props: {
                    custom: 'iconfont icon-edit',
                    size: '20',
                    color: '#087BE1'
                  },
                  style: {
                    marginRight: '20px'
                  },
                  on: {
                    click: () => {
                      for (const key in params.row) {
                        this.formData[key] = params.row[key]
                      }
                      this.formType = 'edit'
                      this.title = '修改'
                      this.show = true
                    }
                  }
                },
                '修改'
              ),
              h(
                'Icon',
                {
                  props: {
                    custom: 'iconfont icon-delete',
                    size: '20',
                    color: 'red'
                  },
                  on: {
                    click: () => {
                      this.$MyModal.show({ text: '是否删除？' }).$on('confirm', () => {
                        FactoryDelete({
                          id: params.row.id
                        }).then(res => {
                          if (res.code === 0) {
                            this.$Message.info(res.msg)
                            this.getList()
                          }
                        })
                      })
                    }
                  }
                },
                '删除'
              )
            ])
          }
        }
      ],
      tableFilter: [
        {
          name: 'Input',
          value: 'key',
          placeholder: '请输入关键字'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '查询',
          e: 'search'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '添加',
          align: 'right',
          e: 'add'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '价格维护',
          align: 'right',
          e: 'priceHandle'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '收款账号维护',
          align: 'right',
          width: '300',
          e: 'account'
        }
      ],
      params: {
        pageIndex: 1,
        pageSize: 20,
        total: 0
      }
    }
  },
  methods: {
    cfm (type, formData) {
      if (type === 'add') {
        FactoryAdd(formData).then(res => {
          if (res.code === 0) {
            this.show = false
            this.$Message.info(res.msg)
            this.getList()
          }
        })
      } else if (type === 'edit') {
        FactoryUpdate(formData).then(res => {
          if (res.code === 0) {
            this.show = false
            this.$Message.info(res.msg)
            this.getList()
          }
        })
      }
    },
    // 检索条件事件处理
    eventHandle (option) {
      switch (option._evnet) {
        case 'search':
          this.params.pageIndex = 1
          this.params.key = option.key
          this.getList()
          break
        case 'add':
          this.formType = 'add'
          this.title = '添加供应商'
          this.show = true
          break
        case 'priceHandle':
          this.$router.push({
            name: 'provider_price_maintenance'
          })
          break
        case 'account':
          this.accountShow = true
          break
      }
    },
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    getMaterialCategoryZTree () {
      GetMaterialCategoryZTree().then(res => {
        if (res.code === 0) {
          let list = res.result.map(item => {
            return {
              label: item.name,
              value: item.value
            }
          })
          this.formConfig[2].list = list
          this.editFormConfig[2].list = list
          this.showFormConfig[2].list = list
        }
      })
    },
    getUserPageList () {
      GetUserPageList({
        pageIndex: 1,
        pageSize: 9999
      }).then(res => {
        if (res.code === 0) {
          let list = res.result.list.map(item => {
            return {
              label: item.realName,
              value: item.id
            }
          })
          this.formConfig[1].list = list
          this.editFormConfig[1].list = list
          this.showFormConfig[1].list = list
        }
      })
    },
    getList () {
      GetFactoryPageList(this.params).then(res => {
        if (res.code === 0) {
          this.data = res.result.list
          this.params.total = res.result.totalCount
        }
      })
    }
  },
  mounted () {
    this.getList()
    // this.getUserPageList()
    this.getMaterialCategoryZTree()
  }
}
</script>

<style lang="less" scoped>
.container {
  height: 100%;
  overflow: hidden;
}
</style>
