<template>
  <div class="app-container">
    <div v-if="isShow">
      <!-- 筛选条件 -->
      <div>
        <el-form
          ref="screenForm"
          :model="screenForm"
          label-width="70px"
          size="mini"
          label-position="left"
        >
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="名称" prop="keyword">
                <el-input
                  v-model="screenForm.keyword"
                  placeholder="请输入名称"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="物料编码" prop="number">
                <el-input
                  v-model="screenForm.number"
                  placeholder="请输入物料编码"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="金蝶编码" prop="oldNumber">
                <el-input
                  v-model="screenForm.oldNumber"
                  placeholder="请输入金蝶编码"
                />
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :lg="6" class="tr">
              <el-form-item label="">
                <el-button size="mini" @click="resetScreenForm"
                  >清空</el-button
                >
                <el-button size="mini" type="primary" @click="submitScreenForm"
                  >搜索</el-button
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="mymain-container">
        <div class="table">
          <el-table
            v-loading="listLoading"
            :data="dataList"
            element-loading-text="Loading"
            border
            fit
            highlight-current-row
            stripe
          >
            <!-- <el-table-column
              type="selection"
              align="left"
              min-width="100"
            ></el-table-column> -->
            <el-table-column
              align="left"
              label="使用组织"
              prop="useOrgName"
              min-width="200"
              show-overflow-tooltip
            />
            <el-table-column
              align="left"
              label="物料编码"
              prop="number"
              min-width="200"
              label-class-name="bianma"
              class-name="fontstyle"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
              <CopyButton :copyText="scope.row.number" />
              <span>{{scope.row.number}}</span>
            </template>
            </el-table-column>

            <el-table-column
              align="left"
              label="产品名称"
              prop="name"
              min-width="200"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <CopyButton :copyText="scope.row.name" />
                <span>{{scope.row.name}}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="规格型号"
              prop="specification"
              min-width="200"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <CopyButton :copyText="scope.row.specification" />
                <span>{{scope.row.specification}}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="数据状态"
              prop="forbidStatus"
              min-width="100"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-tag size="mini" v-if="scope.row.forbidStatus == 'A'" type="success"
                  >正常</el-tag
                >
                <el-tag size="mini" v-else type="danger">禁用</el-tag>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="金蝶编码"
              prop="oldNumber"
              min-width="160"
              show-overflow-tooltip
            />
            <el-table-column
              align="left"
              label="是否维护商城资料"
              prop="maintainData"
              min-width="100"
              show-overflow-tooltip
            />
<!--            <el-table-column-->
<!--              align="left"-->
<!--              label="是否维护内外机档案"-->
<!--              prop="maintainFiles"-->
<!--              min-width="100"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <el-tag v-if="scope.row.isSheath == true" type="success"-->
<!--                  >是</el-tag-->
<!--                >-->
<!--                <el-tag v-else type="danger">否</el-tag>-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column
              align="left"
              label="基本单位"
              prop="baseUnitId"
              min-width="100"
              show-overflow-tooltip
            />
            <el-table-column
              align="left"
              label="已使用"
              prop="used"
              min-width="100"
              show-overflow-tooltip
            />
            <el-table-column
              align="center"
              fixed="right"
              label="操作"
              prop="caozuo"
              min-width="160"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-button
                  type="text"
                  class="textColor"
                  @click="hanleDetail(scope.row.id)"
                  >详情</el-button
                >
                <!-- <el-button type="text" class="textColor">删除</el-button> -->
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="fr">
          <el-pagination
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="listTotal"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <MaterialListDetail v-else :detail="detail" />
  </div>
</template>

<script>
import Mixin from '@/mixin/index'
import { getMaterialDetail, getMaterialList } from '@/api/basic_data/material'
import MaterialListDetail from './components/material_list-detail.vue'

export default {
  components: { MaterialListDetail },
  mixins: [Mixin],
  data() {
    return {
      isShow: true,
      screenForm: {
        // 筛选表单数据
        keyword: "", // 名称
        number: "",
        oldNumber: "",
      },
    };
  },
    activated() {
    // 页面重回
    console.log(545);
},
deactivated() {
    // 页面离开
      console.log(777878);
},
  methods: {
    hanleDetail(id) {
      getMaterialDetail({ id }).then((res) => {
        console.log(res);
        this.detail = res.data;
        this.isShow = false;
      });
    },
    getList() {
      this.listLoading = true;
      const params = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        keyword: this.screenForm.keyword,
        number: this.screenForm.number,
        oldNumber: this.screenForm.oldNumber,
      };
      getMaterialList(params).then((res) => {
        this.dataList = res.data.records;
        this.listTotal = res.data.total;
        this.listLoading = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
// ::v-deep .fontstyle {
//   color: #0909ff;
// }
// ::v-deep .bianma {
//   color: #409eff;
// }
</style>
