<template>
  <div id="contextfabu">
    <el-row>
      <el-col :span="24" class="contextfabu">
        <el-row class="demandForm">
          <el-col></el-col>
          <el-form ref="forms" :model="forms" label-width="120px">
            <el-form-item label="用户名称">
              <el-input v-model="forms.name" placeholder="请输入用户名称"></el-input>
            </el-form-item>
            <el-form-item label="登录密码">
              <el-input v-model="forms.password" placeholder="请输入登录密码" show-password></el-input>
            </el-form-item>
            <el-form-item label="身份证号">
              <el-input v-model="forms.cardnumber" placeholder="请输入身份证号" :minlength="18" :maxlength="18"></el-input>
            </el-form-item>
            <el-form-item label="手机号">
              <el-input v-model="forms.phone" placeholder="请输入手机号" :minlength="11" :maxlength="11"></el-input>
            </el-form-item>
            <el-form-item label="邮箱">
              <el-input v-model="forms.email" placeholder="请输入邮箱"></el-input>
            </el-form-item>
            <el-form-item label="地址">
              <el-input v-model="forms.addr" placeholder="请输入地址"></el-input>
            </el-form-item>
            <el-form-item label="头像图片" prop="img_path">
              <upload :limit="1" :data="forms.img_path" type="img_path" :url="'/files/imgpath/upload'" @upload="uploadSuccess"></upload>
            </el-form-item>
            <el-form-item label="用户类别">
              <!-- <el-radio v-model="forms.role" label="1">管理员</el-radio> -->
              <el-radio-group v-model="forms.role" @change="setIsQy">
                <el-radio label="2">个人</el-radio>
                <el-radio label="3">企业管理员</el-radio>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="身份证正面">
              <upload :limit="1" :data="forms.cardfile_a" type="cardfile_a" :url="'/files/cardfilea/upload'" @upload="uploadSuccess"></upload>
            </el-form-item>
            <el-form-item label="身份证背面">
              <upload :limit="1" :data="forms.cardfile_b" type="cardfile_b" :url="'/files/cardfileb/upload'" @upload="uploadSuccess"></upload>
            </el-form-item>
            <el-form-item label="组织机构图片" v-if="forms.role == '3'">
              <upload :limit="1" :data="forms.img_qy" type="img_qy" :url="'/files/imgqy/upload'" @upload="uploadSuccess"></upload>
            </el-form-item>
            <el-form-item label="简介" placeholder="请输入简介">
              <el-input type="textarea" v-model="forms.resume"></el-input>
            </el-form-item>
            <el-form-item label="专业领域" placeholder="请输入专业领域">
              <el-input v-model="forms.major"></el-input>
            </el-form-item>
            <template v-if="forms.role == '3'">
              <el-form-item label="机构类型" placeholder="请输入机构类型">
                <el-input v-model="forms.institution_type"></el-input>
              </el-form-item>
              <el-form-item label="机构名称" placeholder="请输入机构名称">
                <el-input v-model="forms.institution_name"></el-input>
              </el-form-item>
              <el-form-item label="机构代码" placeholder="请输入机构代码">
                <el-input v-model="forms.institution_code"></el-input>
              </el-form-item>
              <el-form-item label="机构性质" placeholder="请输入机构性质">
                <el-input v-model="forms.institution_nature"></el-input>
              </el-form-item>
            </template>
            <el-form-item label="办公电话" placeholder="请输入办公电话">
              <el-input v-model="forms.office_phone"></el-input>
            </el-form-item>
            <el-form-item label="所属行业" placeholder="请输入所属行业">
              <el-input v-model="forms.profession"></el-input>
            </el-form-item>
            <el-col :span="24" class="loginSubmit"><el-button type="primary" @click="registerSubmit">注册</el-button></el-col>
            <el-row class="demandBtn">
              <el-button type="primary" @click="demandBtn()">产品发布</el-button>
            </el-row>
          </el-form>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import _ from 'lodash';
import upload from '@/components/upload.vue';
export default {
  name: 'contextfabu',
  props: {
    forms: null,
    columnList: null,
    totaltype: null,
  },
  components: {
    upload,
  },
  data: () => ({
    options: [
      {
        value: 'totaltype',
        label: '产品类型',
        disabled: true,
      },
      {
        value: 'name',
        label: '产品名称',
        disabled: true,
      },
      {
        value: 'contact_user',
        label: '联系人',
        disabled: true,
      },

      {
        value: 'contact_tel',
        label: '联系人电话',
        disabled: true,
      },

      {
        value: 'description',
        label: '产品描述',
      },
      {
        value: 'product_type_id',
        label: '类型',
      },
      {
        value: 'phase',
        label: '研发阶段',
      },
      {
        value: 'introduction',
        label: '产品简介',
        disabled: true,
      },

      {
        value: 'price',
        label: '产品单价',
      },
      {
        value: 'priceunit',
        label: '产品单位',
      },

      {
        value: 'image',
        label: '产品图片',
      },
      {
        value: 'product_args',
        label: '产品参数',
      },
      {
        value: 'field',
        label: '应用领域',
      },

      {
        value: 'prospect',
        label: '市场前景',
      },
      {
        value: 'contract',
        label: '电子合同',
      },
      {
        value: 'gxtype',
        label: '供给类型',
      },
      {
        value: 'scope',
        label: '服务范围',
      },

      {
        value: 'property',
        label: '知识产权',
      },

      {
        value: 'business',
        label: '交易方式',
      },
    ],

    option2: [
      {
        value: 'totaltype',
        label: '产品类型',
        disabled: true,
      },
      {
        value: 'name',
        label: '产品名称',
        disabled: true,
      },
      {
        value: 'contact_user',
        label: '联系人',
        disabled: true,
      },

      {
        value: 'contact_tel',
        label: '联系人电话',
        disabled: true,
      },

      {
        value: 'description',
        label: '产品描述',
      },
      {
        value: 'product_type_id',
        label: '类型',
      },

      {
        value: 'introduction',
        label: '产品简介',
        disabled: true,
      },

      {
        value: 'price',
        label: '产品单价',
      },
      {
        value: 'priceunit',
        label: '产品单位',
      },

      {
        value: 'image',
        label: '产品图片',
      },
      {
        value: 'product_args',
        label: '产品参数',
      },

      {
        value: 'contract',
        label: '电子合同',
      },
      {
        value: 'gxtype',
        label: '供给类型',
      },
      {
        value: 'scope',
        label: '服务范围',
      },

      {
        value: 'property',
        label: '知识产权',
      },

      {
        value: 'business',
        label: '交易方式',
      },
    ],

    option3: [
      {
        value: 'totaltype',
        label: '产品类型',
        disabled: true,
      },
      {
        value: 'name',
        label: '产品名称',
        disabled: true,
      },
      {
        value: 'contact_user',
        label: '联系人',
        disabled: true,
      },

      {
        value: 'contact_tel',
        label: '联系人电话',
        disabled: true,
      },

      {
        value: 'description',
        label: '产品描述',
      },
      {
        value: 'product_type_id',
        label: '类型',
      },

      {
        value: 'introduction',
        label: '产品简介',
        disabled: true,
      },

      {
        value: 'price',
        label: '产品单价',
      },
      {
        value: 'priceunit',
        label: '产品单位',
      },

      {
        value: 'image',
        label: '产品图片',
      },

      {
        value: 'field',
        label: '应用领域',
      },

      {
        value: 'prospect',
        label: '市场前景',
      },
      {
        value: 'contract',
        label: '电子合同',
      },
      {
        value: 'gxtype',
        label: '供给类型',
      },
      {
        value: 'scope',
        label: '服务范围',
      },

      {
        value: 'property',
        label: '知识产权',
      },

      {
        value: 'business',
        label: '交易方式',
      },
    ],
    is_display: [],
    value1: [],
    value2: [],

    activeName: 'first',
    priceunit_list: [
      {
        name: '公斤',
      },
      {
        name: '套',
      },
      {
        name: '件',
      },
    ],
    product_args: [],
    selectlistRow: [],
    rowNum: 1,
    totaltype_list: [
      { name: '技术', value: '0' },
      { name: '产品', value: '1' },
      { name: '服务', value: '2' },
    ],
  }),
  created() {},

  computed: {},
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    demandBtn() {
      console.log(this.demandForm);

      this.$emit('demandSubmit', { data: this.demandForm, id: this.demandForm.id });
    },
    selectChild(product_type_id) {
      let res = this.columnList.filter(fil => fil.id === product_type_id);
      if (res.length > 0) {
        console.log(res[0].name);
        this.$set(this.demandForm, `product_type_name`, res[0].name);
      }
      this.$forceUpdate();
    },
    uploadSuccess({ type, data }) {
      let arr = _.get(this.demandForm, type);
      if (_.isArray(arr)) {
        let datas = { name: data.name, url: data.uri };
        this.demandForm[type].push({ name: data.name, url: data.uri });
      } else {
        let newArr = [{ name: data.name, url: data.uri }];
        this.$set(this.demandForm, `${type}`, newArr);
      }
    },

    // 获取表格选中时的数据
    selectRow(val) {
      this.selectlistRow = val;
    },
    addRow() {
      var list = {
        rowNum: this.rowNum,
      };
      // let tableData = this.emandForm.product_args;
      this.product_args.unshift(list);
      this.rowNum += 1;
    },

    uploadDelete(index) {
      console.log(index);

      this.demandForm.image.splice(index, 1);
    },
    selectType(item) {
      this.$emit('changeType', item);
      // this.$set(this, `totaltype`, item);
      console.log(item);
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-tabs--card > .el-tabs__header {
  border-bottom: 1px solid #215299;
}
/deep/.el-tabs__item {
  height: 50px;
  line-height: 50px;
  font-size: 16px;
}
/deep/.el-tabs__item.is-active {
  color: #ffff;
  background: #215299;
}
.demandForm {
  padding: 0 20px;
}
.demandBtn {
  text-align: center;
}
/deep/.demandBtn .el-button {
  background-color: #ff7814;
  border: none;
}
/deep/.el-table td {
  padding: 0;
}
/deep/.el-table th {
  padding: 0;
  background-color: #f3f3f3;
}
</style>
