<template>
  <div>
    <div class="sty">
      <el-page-header content="详情" @back="goBack" />
    </div>
    <el-form :model="infoList" label-width="130px" size="small" label-position="right">
      <el-card class="">
        <div slot="header" class="clearfix">
          <strong>客户</strong>
        </div>
        <div>
          <!-- <el-form label-width="130px" size="small" label-position="right"> -->
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="创建组织" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="客户编码" prop="">
                <el-input v-model="infoList.number" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="使用组织" prop="">
                <el-input v-model="infoList.useOrgName" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="简称" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- </el-form> -->
        </div>
      </el-card>
      <br>
      <el-card class="">
        <div slot="header" class="clearfix">
          <strong>基本信息</strong>
        </div>
        <span>地址</span>
        <el-divider />
        <div>
          <!-- <el-form label-width="130px" size="small" label-position="right"> -->
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="国家" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="地区" prop="">
                <el-input v-model="infoList.region" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="省份" prop="">
                <el-input v-model="infoList.province" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="城市" prop="">
                <el-input v-model="infoList.city" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="通信地址" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="邮政编码" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="公司网址" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="商城订单对应组织" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="联系邮箱" prop="">
                <el-input v-model="infoList.email" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- </el-form> -->
        </div>
        <span>管理</span>
        <el-divider />
        <div>
          <!-- <el-form label-width="130px" size="small" label-position="right"> -->
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="联系电话" prop="">
                <el-input v-model="infoList.mobile" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="传真" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="公司类别" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="公司性质" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="公司规模" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- </el-form> -->
        </div>
        <span>相关</span>
        <el-divider />
        <div>
          <!-- <el-form label-width="130px" size="small" label-position="right"> -->
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="对应供应商" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="对应集团客户" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="客户类别" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="客户分组" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="集团客户" prop="">
                <el-checkbox disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="默认付款方" prop="">
                <el-checkbox disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="不校验可发量" prop="">
                <el-checkbox disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="对应组织" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="备注" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- </el-form> -->
        </div>
        <span>开票信息</span>
        <el-divider />
        <div>
          <!-- <el-form label-width="130px" size="small" label-position="right"> -->
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="发票抬头" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="纳税登记号" prop="">
                <el-input disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="开户银行" prop="">
                <el-input v-model="infoList.bank" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="银行账号" prop="">
                <el-input v-model="infoList.bankAccount" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="开票联系电话" prop="">
                <el-input v-model="infoList.invoicePhone" disabled />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="开票通讯地址" prop="">
                <el-input v-model="infoList.invoiceAddress" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- </el-form> -->
        </div>
        <span>智慧订货</span>
        <el-divider />
        <div>
          <!-- <el-form label-width="130px" size="small" label-position="right"> -->
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="允许对接智慧订单" prop="">
                <el-checkbox disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- </el-form> -->
        </div>
      </el-card>
    </el-form>
    <br>
    <el-card>
      <div slot="header" class="clearfix">
        <strong>售后系统关联信息</strong>
      </div>
      <el-row :gutter="20" class="flex">
        <el-col :span="4">售后系统销售编号</el-col>
        <el-col :span="4"> <el-input v-model="infoList.afterNumber" disabled placeholder="" size="mini" /></el-col>
        <el-col :span="4">售后系统绑定状态</el-col>
        <el-col :span="10">{{ infoList.binding === 'YES' ? '是' : '否' }}</el-col>
      </el-row>
      <el-row :gutter="20" class="flex">
        <el-col :span="8">
          <el-radio-group v-model="infoList.afterType" disabled>
            <el-radio v-for="item in afterTypeList" :key="item.value" :label="item.value">{{
              item.label
            }}</el-radio>
          </el-radio-group>
        </el-col>
        <el-col :span="2"> 绑定时间 </el-col>
        <el-col :span="4"> {{ infoList.bindingTime }}</el-col>
        <el-col :span="2"> 绑定人 </el-col>
        <el-col :span="4"> {{ infoList.bindingName }} </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import { getKingDeeCategory } from '@/api/basic_data/material'
import { getStageCustomerDetail, updateCustomer, updatePick } from '@/api/basic_data/dealer'

export default {
  props: {
    detailsId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      infoList: {},
      dataList: [],
      radio: [],
      isFront: false,
      isPick: false,
      pickCategory: [],
      frontCategory: [],
      categoryArr: [],
      code: '',
      afterTypeList: [
        { label: '绑定上级商户销售编号', value: 'CHARGE' },
        { label: '绑定二级商户编号', value: 'STAGE' }
      ]
    }
  },

  async created() {
    await this.getDataList()
    const res = await getStageCustomerDetail({ id: this.detailsId })
    // this.isFront = res.data.isFront
    // this.isPick = res.data.isPick
    if (res.data.kingDeeCustomerCategoriesFront && res.data.kingDeeCustomerCategoriesFront.length) {
      this.frontCategory = res.data.kingDeeCustomerCategoriesFront.map(k => {
        return k.categoryId
      })
    }
    if (res.data.kingDeeCustomerCategories && res.data.kingDeeCustomerCategories.length) {
      this.pickCategory = res.data.kingDeeCustomerCategories.map(k => {
        return k.categoryId
      })
    }
    this.frontCategory.forEach(k => {
      this.dataList.forEach(i => {
        if (i.id === k) {
          i.isFront = true
        }
      })
    })
    this.pickCategory.forEach(k => {
      this.dataList.forEach(i => {
        if (i.id === k) {
          i.isPick = true
        }
      })
    })
    this.categoryArr = [...new Set([...this.frontCategory, ...this.pickCategory])]
    this.infoList = res.data
  },
  methods: {
    goBack() {
      this.$emit('close')
    },
    // 金蝶存货类别列表
    async getDataList() {
      const res = await getKingDeeCategory()
      res.data.forEach(k => {
        k.isFront = false
        k.isPick = false
      })
      this.dataList = res.data
    },

    handelSubmit() {
      updateCustomer({
        id: this.infoList.id,
        isFront: this.infoList.isFront
      }).then(res => {
        this.$successMsg(this.infoList.isFront ? '已更改为前置仓' : '已更改为经销商自有仓库')
      })
    },
    onSubmit() {
      this.pickCategory = []
      this.frontCategory = []
      this.dataList.map(k => {
        this.categoryArr.map(i => {
          if (i === k.id) {
            if (k.isFront) {
              this.frontCategory.push(i)
            }
            if (k.isPick) {
              this.pickCategory.push(i)
            }
          } else {
            this.$errorMsg('必须选择产品类别')
            return
          }
        })
      })

      updatePick({
        id: this.detailsId,
        isFront: !!this.frontCategory.length,
        isPick: !!this.pickCategory.length,
        pickCategory: this.pickCategory.length ? this.pickCategory.join(',') : '',
        frontCategory: this.frontCategory.length ? this.frontCategory.join(',') : ''
      }).then(res => {
        this.$successMsg('保存成功')
        this.$emit('close')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.sty {
  margin-bottom: 20px;
}

::v-deep .diy-table-1 {
  width: 50%;

  .xyed {
    border-top: 1px solid #ebeef5;

    .item {
      margin-bottom: 18px;
    }
  }
}
.pick {
  width: 600px;
  border: 1px solid #ebeef5;
  border-bottom: none;
  &-item {
    height: 40px;
    border-bottom: 1px solid #ebeef5;
    &-category {
      border-right: 1px solid #ebeef5;
    }
    &-category,
    &-way {
      padding: 0 20px;
    }
  }
}
.flex {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.tagStyle {
  margin: 0 18px;
}
</style>
