<template>
  <div class="product">
      <el-container class="product-container">
          <!--搜索栏-->
          <el-aside class="product-container-left">
               <el-row :gutter="10" class="product-container-left-row">
                    <el-col :span="24" class="mt10 mb10">
                      <el-divider content-position="left" class="product-container-left-row-title">产品类别</el-divider>
                    </el-col>
                    <el-col :span="24">
                        <div class="product-container-left-row-content" v-loading="typeLoading">
                            <ul class="product-container-left-row-content-typelist">
                              <li
                                v-for="(item,index) in typeList"
                                @click="selMenu(item,index)"
                                :class="{active:typeIndex == index}"
                                :key="index">
                                {{item.typeName}}
                              </li>
                            </ul>
                        </div>
                    </el-col>
                </el-row>
          </el-aside>
          <!--主体内容区域-->
          <el-main class="product-container-right">
              <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
                <el-form-item prop="phonenumber">
                  <el-input
                    v-model="queryParams.farmerName"
                    placeholder="产品名称"
                    clearable
                    size="small"
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-form>
              <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                  <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                  >新增</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
              </el-row>
              <el-table v-loading="loading" :data="list">
                <el-table-column label="序号" type="index" width="50" align="center" />
                <el-table-column label="产品编码" align="center" prop="productCode" />
                <el-table-column label="产品名称" align="center" prop="productName" />
                <el-table-column label="归属区域" align="center">
                  <template slot-scope="scope">
                    {{scope.row.povertyArea === null ? '-' : scope.row.povertyArea.povertyAreaName}}
                  </template>
                </el-table-column>
                <el-table-column label="归属主体" align="center">
                  <template slot-scope="scope">
                    {{scope.row.productBelongs.length == 0 ? '-' : scope.row.productBelongs[0].farmerName}}
                  </template>
                </el-table-column>
                <el-table-column label="创建人" align="center" prop="createUserName"/>
                <el-table-column label="创建时间" align="center" prop="createTime"/>
                <el-table-column
                  label="操作"
                  align="center"
                  width="280"
                  class-name="small-padding fixed-width"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      v-if="scope.row.isEnable === 1"
                      type="warning"
                      icon="el-icon-s-check"
                      @click="handleExportPd(scope.row)"
                    >生成商品</el-button>
                    <el-button
                      size="mini"
                      v-if="scope.row.isEnable === 2"
                      icon="el-icon-s-check"
                      type="info"
                    >商品已生成</el-button>
                    <el-button
                      size="mini"
                      type="primary"
                      icon="el-icon-view"
                      @click="handleView(scope.row)"
                    >查看</el-button>
                    <el-button
                      size="mini"
                      type="success"
                      icon="el-icon-edit"
                      @click="handleEdit(scope.row)"
                    >编辑</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNo"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
          </el-main>
      </el-container>
      <!--crud弹窗口-->
      <add-mobiel
      			v-if="modal.crud.visibleModal"
      			:title="modal.crud.title"
      			:action="modal.crud.action"
      			:visible="modal.crud.visibleModal"
      			:selectRow="modal.crud.selectRow"
            :fkProductTypeId="fkProductType"
      			@closecrudmodal="closecrudmodal">
      		</add-mobiel>
      <!--产品生成弹窗口-->
      <export-product
        v-if="modal.export.visibleModal"
        :title="modal.export.title"
        :visible="modal.export.visibleModal"
        :selectRow="modal.export.selectRow"
        @closeexportmodal="closeexportmodal"
      ></export-product>
  </div>
</template>
<script>
import { listType , listProduct } from "@/api/productManage/productInfo";
import addMobiel from './modal/addMobiel'
import exportProduct from "./modal/exportProduch"
export default {
  name: "productInfo",
  components: {
    addMobiel,
    exportProduct
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      typeLoading:true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //种类类型
      typeList:null,
      typeIndex:null,
      // 表格数据
      list: null,
      // 表单参数
      form: {},
      //弹出层
      modal:{
        crud:{
          action:'',
          title:'',
          visibleModal:false,
          selectRow:null
        },
        export:{
          title:'',
          visibleModal:false,
          selectRow:null
        }
      },
      //类型id
      fkProductType:'',
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  created() {
    this.getTypelist();
    this.getList();
  },
  methods: {
    //菜单加载
    getTypelist(){
        let params = {
          state:1
        }
        listType(params).then(res => {
            this.typeLoading = false;
            if(res.retHead.errCode == 0){
              this.typeList = res.retBody
            }
          }
        );
    },
    //菜单选择
    selMenu(item,i){
      this.queryParams.fkProductType = item.guid
      this.fkProductType = item.guid
      this.typeIndex = i
      this.getList()
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listProduct(this.queryParams).then(res => {
          if(res.retHead.errCode == 0){
            this.list = res.retBody
          }
          this.total = res.retHead.total;
          this.loading = false;
        }
      );
    },
    //产品生成
    handleExportPd(item){
      this.modal.export.visibleModal = true
      this.modal.export.title = '生成商品'
      this.modal.export.selectRow = item
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.queryParams.condition = this.queryParams.farmerName
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.condition = "";
      this.queryParams.farmerName = "";
      this.queryParams.fkProductType = ""
      this.typeIndex = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
        this.modal.crud.visibleModal = true
        this.modal.crud.title = '新增产品信息'
        this.modal.crud.action = 'add'
    },
    /** 查看按钮操作 */
    handleView(item){
        this.modal.crud.visibleModal = true
        this.modal.crud.title = '产品信息详情'
        this.modal.crud.action = 'view'
        this.modal.crud.selectRow = item
    },
    /** 查看按钮操作 */
    handleEdit(item){
        this.modal.crud.visibleModal = true
        this.modal.crud.title = '编辑产品信息'
        this.modal.crud.action = 'edit'
        this.modal.crud.selectRow = item
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          // return delUser(userIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    //增加编辑窗口关闭
    closecrudmodal(flag = false){
      this.modal.crud.visibleModal = false
      flag && this.getList()
    },
    //产品生成窗口关闭
    closeexportmodal(flag = false){
      this.modal.export.visibleModal = false
      flag && this.getList()
    }
  }
};
</script>
<style scoped lang="scss">
  .product {
    width: 100%;
    height: 100%;
    margin: 10px 10px 0 0;
    padding: 0 10px 0 0;
    &-container {
      width: 100%;
      height: 100%;
      &-left {
        background: #fff;
        padding: 0 20px;
        width: 280px !important;
        min-height: 850px;
        height: auto;
        &-row {
          margin: 0 !important;
          &-title .el-divider__text {
            font-size: 18px;
            font-weight: 700;
            font-style: normal;
          }
          &-content{
            &-typelist{
              list-style:none;
              margin:0;
              padding:0;
              li{
                display:block;
                height:50px;
                line-height:50px;
                padding:0 15px;
                border: 1px solid #e6e6e6;
                background-color: #f2f2f2;
                margin-bottom:10px;
                cursor:pointer;
                font-size:14px;
                &:hover{
                    border: 1px solid #2B2F3B;
                    background-color: #304156;
                    color:#fff;
                }
              }
              li.active{
                  border: 1px solid #2B2F3B;
                  background-color: #304156;
                  color:#fff;
              }
            }
          }
        }
      }
      &-switch {
        font-size: 28px;
        cursor: pointer;
        color: #1890ff;
        &-leftbtn {
          position: absolute;
          top: 50%;
          left: 325px;
          cursor: pointer;
        }
        &-rightbtn {
          position: absolute;
          top: 50%;
          left: -5px;
          cursor: pointer;
        }
      }
      &-right {
        padding:20px;
        &-main {
          background: #fff;
          height: auto;
          min-height: 850px;
          &-defaultMl {
            margin-left: 10px;
          }
          &-nodefaultMl {
            margin-left: 0;
          }
        }
      }
    }
  }

</style>
