<template>
  <div class="page_consumables">
    <div style="display:flex;justify-content: space-between;width:100%;margin-bottom:20px;">
      <div class="cell clearfix" style="margin-bottom:0;">
        <el-input style="width: 180px;margin-right:10px;" @keyup.enter.native='searchAction' v-model="keywords"
                  class="filter-item"/>
        <el-button style="margin-right:10px;" class="filter-item" type="primary" icon="el-icon-search"
                   @click="searchAction">搜索
        </el-button>
        <label class="title"><span class="name">是否停用</span> : </label>
        <el-select v-model="is_use" style="width:140px;margin-right:10px;" placeholder="请选择" @change="changeUser">
          <el-option
            v-for="(item,z) in options"
            :key="z"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <label class="title"><span class="name">生产厂商</span> : </label>
        <el-select v-model="manufacturer" style="width:140px;margin-right:10px;" placeholder="请选择" @change="changeManufacture">
          <el-option
            v-for="(item,y) in manufacturers"
            :key="y"
            :label="item.manufacturer_name"
            :value="item.id">
          </el-option>
        </el-select>
        <span style="color: #909399;font-size:14px;">备案 : &nbsp;</span>
        <el-select v-model="is_record" style="width:140px;margin-right:10px;" placeholder="请选择" @change="changeRecord">
          <el-option
            v-for="(item,index) in optionOne"
            :key="index"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <span style="color: #909399;font-size:14px;">耗材类型 : &nbsp;</span>
        <el-select v-model="is_type" style="width:140px;margin-right:10px;" placeholder="请选择" @change="changeTypeList">
          <el-option
            v-for="(item,index) in goodTypeList"
            :key="index"
            :label="item.type_name"
            :value="item.id">
          </el-option>
        </el-select>

      </div>
      <div>
        <el-button type="primary" @click="openForm()">新增</el-button>
      </div>

    </div>

     <div style="display:flex; align-items:center;margin-bottom:10px;">
        <!--<el-button type="primary" size="mini" @click="BatchDelete()" v-if="$store.getters.xt_user.org_id == 9504 || $store.getters.xt_user.org_id == 10028 || $store.getters.xt_user.org_id == 10138">批量备案</el-button>-->
        <!--<el-button type="primary" size="mini">批量备案</el-button>-->
        <el-link target="_blank" href="https://kuyi.shengws.com/stockTemplateTwo.xlsx" :underline="false"
                 style="margin-left:15px">
          <el-button
            class="filter-item"
            type="primary"
            size="small"
          >下载模版
          </el-button>
        </el-link>
        <good-excel :on-success='handleSuccess'></good-excel>
        <el-button
          style="margin-left:10px;"
          @click="generateLog()"
          class="filter-item"
          type="primary"
          size="small"
        >下载日志
        </el-button>
        <el-button
          style="margin-left:10px;"
          @click="exportList()"
          class="filter-item"
          type="primary"
          size="small"
        >点击导出
        </el-button>

       <!-- <el-button
          style="margin-left:10px;"
          @click="jiaoBen()"
          class="filter-item"
          type="primary"
          size="small"
        >脚本
        </el-button>  -->
      </div>

    <el-table
      border style="width: 100%" :row-style="{ color: '#303133' }"
      :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)', color: '#606266'}"
      :data="goodInfo.goodInfoData"
      v-loading="goodInfo.loading"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
          align="center"
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column type="index" label="序号" width="60px" align="center"></el-table-column>
      <el-table-column label="耗材ID号" align="center">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="耗材名称" align="center">
        <template slot-scope="scope">
          {{ scope.row.good_name }}
        </template>
      </el-table-column>
      <el-table-column prop="date" label="规格型号" align="center">
        <template slot-scope="scope">
        {{ scope.row.specification_name }}
        </template>

      </el-table-column>
      <el-table-column prop="date" label="耗材类型" width="140" align="center">
        <template slot-scope="scope">
          {{ getGoodTypeByID(scope.row.good_type_id) }}
        </template>
      </el-table-column>
      <el-table-column label="注册证号" width="140" align="center">
        <template slot-scope="scope">
          {{ scope.row.register_number }}
        </template>
      </el-table-column>

      <el-table-column label="注册证名称" width="140" align="center">
        <template slot-scope="scope">
          {{ scope.row.register_number_name }}
        </template>
      </el-table-column>

      <!-- <el-table-column label="最小单位" width="60" align="center">
        <template slot-scope="scope">
          {{ getGoodUnit(scope.row.good_unit) }}
        </template>
      </el-table-column> -->

      <el-table-column label="进货价" width="100" align="center">
        <template slot-scope="scope">
          {{ scope.row.buy_price }}
        </template>
      </el-table-column>
      <el-table-column label="零售价" width="100" align="center">
        <template slot-scope="scope">
          {{ scope.row.packing_price }}
        </template>
      </el-table-column>
       <el-table-column label="国家编码" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.social_security_directory_code }}
        </template>
      </el-table-column>
      <el-table-column label="生产厂家" width="140" align="center">
        <template slot-scope="scope">
          {{ getManufactur(scope.row.manufacturer) }}
        </template>
      </el-table-column>
      <el-table-column label="状态" width="60" align="center">
        <template slot-scope="scope">
        <!--{{ scope.row.good_status}}-->
          <div>{{scope.row.good_status.indexOf('停用') == -1 ? '启用':'停用' }}</div>

        </template>

      </el-table-column>

      <el-table-column prop="date" label="操作" width="320" align="center">
        <template slot-scope="scope">
          <el-button @click="handleGoodInfoEdit(scope.$index, scope.row)" type="primary" size="small">编辑</el-button>
          <!--<el-button type="primary" size="small" @click="clickSelfPayment(scope.row.id)">自付比例</el-button>-->
          <el-button type="danger" size="small" @click="handleGoodInfoDelete(scope.$index, scope.row)">删除</el-button>

          <!--<el-button type="primary" size="small" @click="toReturn(scope.row.id,scope.row.is_mark)" v-if="$store.getters.xt_user.org_id == 9504 || $store.getters.xt_user.org_id == 10028 || $store.getters.xt_user.org_id == 10138">-->
             <!--<span v-if="scope.row.is_mark == 0">备案</span>-->
             <!--<span v-if="scope.row.is_mark == 1">撤销</span>-->
          <!--</el-button>-->

          <el-button type="primary" size="small" >
            <span   @click="putOnRecord(scope.row.id)" >目录对照</span>
            <span  @click="putOnUnRecord(scope.row.id)" >撤消对照</span>
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 50, 100,500,1000]"
      :page-size="10"
      background
      align="right"
      style="margin-top:20px;"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <good-info-dailog ref="addConsumable"
                      :titles="goodInfo.goodInfoDialog.goodInfoTitle"
                      :formValue="goodInfo.goodInfoDialog.formValue"
                      :visibility="goodInfo.goodInfoDialog.isVisibility"
                      :isCreated="goodInfo.goodInfoDialog.isCreated"
                      v-on:dialog-comfirm="goodInfoDialogComfirm"
                      v-on:dialog-cancle="goodInfoDialogCancle"
    ></good-info-dailog>
    <self-payment ref='selfPayment'></self-payment>


    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="40%"
    >
      <span>您提交的文档不是系统标准导入模板，请检查您的文档或重新 </span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>


     <el-dialog
      title="提示"
      :visible.sync="exportLogVisible"
      width="40%"
    >

      <div v-for="(item,i) in logs" :key="i">
        <span> {{ item.export_time | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
        <br/>
        <br/>
        <span>{{getContent(item)}}</span>
        <span >点击</span>
        <span style="color:blue" @click="generateTxt(item)">查看详情</span>
        <br/>
        <br/>
      </div>

      <span slot="footer" class="dialog-footer">
    <el-button @click="exportLogVisible = false">取 消</el-button>
    <el-button type="primary" @click="exportLogVisible = false">确 定</el-button>
    </span>
    </el-dialog>

  </div>
</template>

<script>
  import GoodInfoDailog from '../../stock/Dialog/goodInfoDailog'
  import { getDictionaryDataConfig } from "@/utils/data";
  import selfPayment from './selfPayment'
  import axios from 'axios'
  import {
    createGoodInfo,
    deleteGoodInfo,
    GetAllDeals,
    GetAllGoodType,
    GetAllManufacturer,
    GetGoodInfo,
    GetGoodInfoByGoodId,
    getGoodInfoList,
    modifyGoodInfo,
    postGoodInformation,
    getInitializtion,
    updateGoodInfoByUserOrgId
  } from '@/api/stock'
  import UploadExcel from '@/xt_pages/components/UploadExcel'
  import GoodExcel from '@/xt_pages/components/GoodExcel'
  import { generateLog } from '@/api/config'
  export default {
    components: {
      GoodInfoDailog,
      selfPayment,
      UploadExcel,
      GoodExcel
    },
    data() {
      return {
        good_kind:'',
        is_use:'',
        is_charge:'',
        search_input: '',
        options: [{
          value: '0',
          label: '全部'
        },{
          value: '1',
          label: '是'
        }, {
          value: '2',
          label: '否'
        }],
        value: '',

        total: 0,
        pageTotal: 0,
        pageSelect: 0,
        page: 1,
        limit: 10,
        keywords: '',
        goodInfo: {
          loading: false,
          goodInfoData: [],
          good_code: '',
          editGoodId: '',
          editGoodIndex: '',
          goodInfoDialog: {
            goodInfoTitle: '新增商品信息',
            isCreated: 1, //1.创建 2.编辑 3.查看详情
            formValue: {
              good_id: '',
              specification_name: '',
              buy_price: '',
              sell_price: '',
              remark: '',
              manufacturer: '',
              good_type_id: '',
              dealer: '',
              expiry_date_warn_day_count: '',
              stock_warn_count: '',
              is_reuse: '2',
              dealers: [],
              manufacturers: [],
              goodType: [],
              goodUnit: [],
              good_name:'',
              pinyin:"",
              wubi:"",
              good_kind:'',
              medical_insurance_level:'',
              good_unit:'',
              retail_price:'',
              medical_insurance_number:'',
              provinces_code:'',
              is_special_diseases:'',
              is_record:'',
              statistics_category:'',
              agent:'',
              good_status:'',
              default_count:'',
              sign:'',
              is_default:'',
              is_charge_use:'',
              is_charge_predict:'',
              is_statistics_work:'',
              sort:'',
              is_doctor_use:'',
              good_number:'',
              social_security_directory_code:"",
              special_medical:"",
              production_type:"",
              min_number:"",
              packing_unit:"",
              packing_price:'',
              default_count_unit:"",
              min_unit:"",
              total:"",
              register_number:"",
              register_number_name:"",
              is_user:"2",
              number:"",
              is_warehouse:"1",
              bbx01:"",
              bby01:"",
              is_show:"",
              is_zero_flag:"",
              split_of_number:"",
            },
            isVisibility: false,
          }
        },
        selectDrug:[],
        manufacturers:[],
        optionOne: [
          {
            value: '0',
            label: '全部'
          }, {
            value: '1',
            label: '已备案'
          }, {
            value: '2',
            label: '未备案'
        }],
        is_record:"",
        manufacturer:"",
        dialogVisible:false,
        goodType:[],
        dealers:[],
        exportLogVisible:false,
        logs: [],
        goodKindList:[],
        goodTypeList:[{id:0,type_name:"全部"}],
        is_type:0,
        medicalInsuranceLevelList:[]
      }
    },
    methods: {
    jiaoBen(){
      updateGoodInfoByUserOrgId().then(response=>{
        if(response.data.state ==1){

        }
      })
      },
      putOnUnRecord(id){
        var that = this;
        let params = {
          ids:id.toString(),
          record_type: 2,
          admin_user_id:this.$store.getters.xt_user.user.id
        };
        axios.get('http://127.0.0.1:9532/api/uncheckcode/get',{params:params}).then(function(response) {
          if (response.data.state == 0) {
            that.$message.error(response.data.data.msg);
            return false
          } else {
            if(response.data.data.failed_code == -10){
              // that.$message.error(response.data.data.msg)
              that.$confirm(response.data.data.msg, '医保错误信息', {
                confirmButtonText: '确 定',
                type: 'warning'
              }).then(() => {

              }).catch(() => {
              })
            }else{
              // for (let i = 0; i < that.tableData.length; i++) {
              //   if (that.tableData[i].id == that.currentObject.id) {
              //     that.tableData[i].record.is_cancel == 1
              //   }
              // }
            }

          }
        }).catch(function(error) {
        })
      },
      putOnRecord(id){
        var that = this;

        let params = {
          ids:id.toString(),
          record_type: 2,
          admin_user_id:this.$store.getters.xt_user.user.id
        };

        axios.get('http://127.0.0.1:9532/api/checkcode/get',{params:params}).then(function(response) {
          if (response.data.state == 0) {
            that.$message.error(response.data.data.msg);
            return false
          } else {
            if(response.data.data.failed_code == -10){
              // that.$message.error(response.data.data.msg)
              that.$confirm(response.data.data.msg, '医保错误信息', {
                confirmButtonText: '确 定',
                type: 'warning'
              }).then(() => {

              }).catch(() => {
              })
            }else{



            }



          }
        }).catch(function(error) {
        })
      },
      GDYBBatchPutOnRecord(){
        var that = this;
        var ids = [];
        var idMap = {};
        for (const index in this.selectDrug) {
          ids.push(this.selectDrug[index].id);
          idMap[this.selectDrug[index].id] = this.selectDrug[index].id;
        }
        let params = {
          ids:ids.join(','),
          record_type: 2,
          admin_user_id:this.$store.getters.xt_user.user.id
        };
        axios.get('http://127.0.0.1:9532/api/checkcode/get',{params:params}).then(function(response) {
          if (response.data.state == 0) {
            that.$message.error(response.data.data.msg);
            return false
          } else {
            if(response.data.data.failed_code == -10){
              // that.$message.error(response.data.data.msg)
              that.$confirm(response.data.data.msg, '医保错误信息', {
                confirmButtonText: '确 定',
                type: 'warning'
              }).then(() => {

              }).catch(() => {
              })
            }else{


            }
          }
        }).catch(function(error) {
        })
      },

      changeKind(val){
        this.getList()

      },
      changeCharge(val){
        this.getList()

      },
      changeUser(val){
        this.getList()


      },
      getGoodUnit(id){
        for (let i = 0; i <this.$store.getters.good_unit.length; i++ ){
          if(id == this.$store.getters.good_unit[i].id){

            return this.$store.getters.good_unit[i].name
          }
        }
        return ""
      },
      getGoodKind(id){
        // var data = this.getDictionaryDataConfig('system','good_kind')
        var data = this.goodKindList;

        var name = "";
        for(let i = 0; i < data.length; i++){
          if(id == data[i].value){
            name = data[i].name
          }

        }
        return name
      },
      getDictionaryDataConfig(module,filed_name){
        return getDictionaryDataConfig(module,filed_name)

      },
      search: function() {
        this.getList()
      },
      handleGoodInfoEdit: function(index, row) {
        this.getAllDealer();
        this.getAllManufacturer();
        this.getAllGoodType();
        this.goodInfo.editGoodId = row.id;
        this.goodInfo.editGoodIndex = index;

        let params = {
          id: row.id
        };
        GetGoodInfo(params).then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
            return false
          } else {
            console.log("respons------------",this.goodInfo.goodInfoDialog.formValue.register_number_name)

            console.log("respon23322323",response.data.data.goodInfo.register_number_name)

            this.goodInfo.goodInfoDialog.formValue.register_number_name = response.data.data.goodInfo.register_number_name
            if (response.data.data.goodInfo.good_unit <= 0) {
              this.goodInfo.goodInfoDialog.formValue.good_unit = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.good_unit =
                response.data.data.goodInfo.good_unit
            }

            if (response.data.data.goodInfo.manufacturer <= 0) {
              this.goodInfo.goodInfoDialog.formValue.manufacturer = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.manufacturer = response.data.data.goodInfo.manufacturer

            }

            if (response.data.data.goodInfo.dealer <= 0) {
              this.goodInfo.goodInfoDialog.formValue.dealer = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.dealer =
                response.data.data.goodInfo.dealer
            }

            this.goodInfo.goodInfoDialog.formValue.specification_name =
              response.data.data.goodInfo.specification_name;
            this.goodInfo.goodInfoDialog.formValue.buy_price =
              response.data.data.goodInfo.buy_price;
            this.goodInfo.goodInfoDialog.formValue.sell_price =
              response.data.data.goodInfo.sell_price;
            this.goodInfo.goodInfoDialog.formValue.expiry_date_warn_day_count =
              response.data.data.goodInfo.expiry_date_warn_day_count;
            this.goodInfo.goodInfoDialog.formValue.stock_warn_count =
              response.data.data.goodInfo.stock_warn_count;
            this.goodInfo.goodInfoDialog.formValue.is_reuse = response.data.data.goodInfo.is_reuse.toString();

            this.goodInfo.goodInfoDialog.formValue.remark =
              response.data.data.goodInfo.remark;
            this.goodInfo.goodInfoDialog.isCreated = 2;
            this.goodInfo.good_code = response.data.data.goodInfo.good_code;
            this.goodInfo.goodInfoDialog.formValue.good_type_id =
              response.data.data.goodInfo.good_type_id;


            this.goodInfo.goodInfoDialog.formValue.good_name = response.data.data.goodInfo.good_name;


            this.goodInfo.goodInfoDialog.formValue.pinyin = response.data.data.goodInfo.pinyin;

            this.goodInfo.goodInfoDialog.formValue.wubi = response.data.data.goodInfo.wubi;



            if (response.data.data.goodInfo.good_kind <= 0) {
              this.goodInfo.goodInfoDialog.formValue.good_kind = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.good_kind =
                response.data.data.goodInfo.good_kind
            }

            if (response.data.data.goodInfo.medical_insurance_level <= 0) {
              this.goodInfo.goodInfoDialog.formValue.medical_insurance_level = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.medical_insurance_level =
                response.data.data.goodInfo.medical_insurance_level
            }


            this.goodInfo.goodInfoDialog.formValue.retail_price =
              response.data.data.goodInfo.retail_price;


            this.goodInfo.goodInfoDialog.formValue.medical_insurance_number =
              response.data.data.goodInfo.medical_insurance_number;

            this.goodInfo.goodInfoDialog.formValue.provinces_code =
                response.data.data.goodInfo.provinces_code;


            if (response.data.data.goodInfo.is_special_diseases <= 0) {
              this.goodInfo.goodInfoDialog.formValue.is_special_diseases = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.is_special_diseases =
                response.data.data.goodInfo.is_special_diseases.toString()
            }

            if (response.data.data.goodInfo.is_record <= 0) {
              this.goodInfo.goodInfoDialog.formValue.is_record = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.is_record =
                response.data.data.goodInfo.is_record.toString()
            }

            if (response.data.data.goodInfo.statistics_category <= 0) {
              this.goodInfo.goodInfoDialog.formValue.statistics_category = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.statistics_category =
                response.data.data.goodInfo.statistics_category
            }


            if (response.data.data.goodInfo.good_status <= 0) {
              this.goodInfo.goodInfoDialog.formValue.good_status = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.good_status =
                response.data.data.goodInfo.good_status
            }


            if (response.data.data.goodInfo.default_count <= 0) {
              this.goodInfo.goodInfoDialog.formValue.default_count = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.default_count =
                response.data.data.goodInfo.default_count
            }




            if (response.data.data.goodInfo.sign <= 0) {
              this.goodInfo.goodInfoDialog.formValue.sign = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.sign =
                response.data.data.goodInfo.sign
            }



            if (response.data.data.goodInfo.is_default <= 0) {
              this.goodInfo.goodInfoDialog.formValue.is_default = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.is_default =
                response.data.data.goodInfo.is_default.toString()
            }

            if (response.data.data.goodInfo.is_charge_use <= 0) {
              this.goodInfo.goodInfoDialog.formValue.is_charge_use = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.is_charge_use =
                response.data.data.goodInfo.is_charge_use.toString()
            }


            if (response.data.data.goodInfo.is_charge_predict <= 0) {
              this.goodInfo.goodInfoDialog.formValue.is_charge_predict = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.is_charge_predict =
                response.data.data.goodInfo.is_charge_predict.toString()
            }


            if (response.data.data.goodInfo.is_statistics_work <= 0) {
              this.goodInfo.goodInfoDialog.formValue.is_statistics_work = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.is_statistics_work =
                response.data.data.goodInfo.is_statistics_work.toString()
            }


            if (response.data.data.goodInfo.sort <= 0) {
              this.goodInfo.goodInfoDialog.formValue.sort = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.sort =
                response.data.data.goodInfo.sort.toString()
            }

            if (response.data.data.goodInfo.total <= 0) {
              this.goodInfo.goodInfoDialog.formValue.total = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.total =
                      response.data.data.goodInfo.total
            }


            if (response.data.data.goodInfo.is_doctor_use <= 0) {
              this.goodInfo.goodInfoDialog.formValue.is_doctor_use = ''
            } else {
              this.goodInfo.goodInfoDialog.formValue.is_doctor_use =
                response.data.data.goodInfo.is_doctor_use.toString()
            }

            this.goodInfo.goodInfoDialog.formValue.agent =response.data.data.goodInfo.agent;

            this.goodInfo.goodInfoDialog.formValue.good_number = response.data.data.goodInfo.good_number;

            this.goodInfo.goodInfoDialog.formValue.social_security_directory_code = response.data.data.goodInfo.social_security_directory_code;


            this.goodInfo.goodInfoDialog.formValue.bbx01 = response.data.data.goodInfo.bbx01;
            this.goodInfo.goodInfoDialog.formValue.bby01 = response.data.data.goodInfo.bby01;



            if(response.data.data.production_type<=0){
               this.goodInfo.goodInfoDialog.production_type = ''
            }else{
              this.goodInfo.goodInfoDialog.formValue.production_type = response.data.data.goodInfo.production_type.toString()
            }

            if(response.data.data.special_medical<=0){
               this.goodInfo.goodInfoDialog.special_medical = ''
            }else{
              this.goodInfo.goodInfoDialog.formValue.special_medical = response.data.data.goodInfo.special_medical.toString()
            }
            this.goodInfo.goodInfoDialog.formValue.min_unit = response.data.data.goodInfo.min_unit
            this.goodInfo.goodInfoDialog.formValue.min_number = response.data.data.goodInfo.min_number
            this.goodInfo.goodInfoDialog.formValue.packing_unit = response.data.data.goodInfo.packing_unit
            this.goodInfo.goodInfoDialog.formValue.packing_price = response.data.data.goodInfo.packing_price
            this.goodInfo.goodInfoDialog.formValue.default_count_unit = response.data.data.goodInfo.default_count_unit
            this.goodInfo.goodInfoDialog.formValue.register_number = response.data.data.goodInfo.register_number

          
            // this.goodInfo.goodInfoDialog.formValue.register_number_name = response.data.data.goodInfo.register_number_name

            this.goodInfo.goodInfoDialog.formValue.bbx01 = response.data.data.goodInfo.bbx01
            this.goodInfo.goodInfoDialog.formValue.bby01 = response.data.data.goodInfo.bby01



            this.goodInfo.goodInfoDialog.formValue.number = response.data.data.goodInfo.number

            this.goodInfo.goodInfoDialog.formValue.is_user = response.data.data.goodInfo.is_user.toString()

            this.goodInfo.goodInfoDialog.formValue.is_warehouse = response.data.data.goodInfo.is_warehouse.toString()

             if(response.data.data.goodInfo.is_show<=0){
               this.goodInfo.goodInfoDialog.formValue.is_show = ''
              }else{
                this.goodInfo.goodInfoDialog.formValue.is_show =  response.data.data.goodInfo.is_show.toString()
              }

            if(response.data.data.goodInfo.is_zero_flag <=0){
              this.goodInfo.goodInfoDialog.formValue.is_zero_flag = ''
            }else{
              this.goodInfo.goodInfoDialog.formValue.is_zero_flag =  response.data.data.goodInfo.is_zero_flag.toString()
            }

            this.goodInfo.goodInfoDialog.formValue.split_of_number = response.data.data.goodInfo.split_of_number

        


            this.$refs.addConsumable.show(row.id, this.goodInfo.goodInfoDialog.formValue)

          }
        })
      },
      handleGoodInfoDelete: function(index, row) {
        this.$confirm('确认删除这条商品信息?', '删除商品信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            let params = {
              id: row.id
            };

            deleteGoodInfo(params).then(response => {
              if (response.data.state == 0) {
                this.$message.error(response.data.msg);
                return false
              } else {
                this.goodInfo.goodInfoData.splice(index, 1);
                this.$message.success('删除成功')
              }
            })
          })
          .catch(() => {
          })
      },
      getList() {
        this.goodInfo.loading = true;
        let params = {
          page: this.page,
          limit: this.limit,
          keyword: this.keywords,
          is_use:this.is_use,
          good_kind:this.good_kind,
          is_charge: this.is_charge,
          is_mark:this.is_record,
          manufacturer:this.manufacturer,
          is_type:this.is_type,
        };

        getGoodInfoList(params).then(response => {
          if (response.data.state == 0) {
            this.goodInfo.loading = false;
            this.$message.error(response.data.msg);
            return false
          } else {
            this.goodInfo.loading = false;
            this.total = response.data.data.total;
            this.goodInfo.goodInfoData = [];
            for (let i = 0; i < response.data.data.list.length; i++) {
              this.goodInfo.goodInfoData.push(response.data.data.list[i])
            }
          }
        })
      },
      tableRowClassName({ row, rowIndex }) {
        //把每一行的索引放进row
        row.index = rowIndex
      },
      onRowClick(row, event, column) {
        this.goodInfo.goodInfoData = [];
        this.goodType.tableCurrentIndex = row.index;
        this.goodInfo.goodInfoDialog.formValue.good_id = row.id;
        let params = {
          id: row.id
        };
        this.goodInfo.loading = true;
        GetGoodInfoByGoodId(params).then(response => {
          if (response.data.state == 0) {
            this.goodInfo.loading = false;
            this.$message.error(response.data.msg);
            return false
          } else {
            this.goodInfo.loading = false;
            this.getList()

            // for (let i = 0; i < response.data.data.list.length; i++) {
            //   this.goodInfo.goodInfoData.push(response.data.data.list[i])
            // }
          }
        })
      },
      goodInfoDialogComfirm: function(val) {
        console.log("VAL----------------",val)
        if (val.isCreated == 2) {
          //修改
          val['id'] = this.goodInfo.editGoodId;
          val['good_code'] = this.goodInfo.good_code;
          if(val.is_zero_flag == 1){
            if(val.split_of_number ==""){
                this.$message.error("拆零次数不能为空!")
                return
            }
          }

          modifyGoodInfo(val).then(response => {
            if (response.data.state == 0) {
              // this.$message.error(response.data.msg)
              this.$message.error("同一耗材类型同一规格名称不能重复录入!");
              return false
            } else {
              this.$refs.addConsumable.hide();
              this.getList();
              // this.goodInfo.goodInfoData[
              //   this.goodInfo.editGoodIndex
              //   ].specification_name =
              //   response.data.data.goodInfo.specification_name
              // this.goodInfo.goodInfoData[this.goodInfo.editGoodIndex].good_unit =
              //   response.data.data.goodInfo.good_unit
              // this.goodInfo.goodInfoData[
              //   this.goodInfo.editGoodIndex
              //   ].buy_price = response.data.data.goodInfo.buy_price.toString()
              // this.goodInfo.goodInfoData[
              //   this.goodInfo.editGoodIndex
              //   ].sell_price = response.data.data.goodInfo.sell_price.toString()
              // this.goodInfo.goodInfoData[
              //   this.goodInfo.editGoodIndex
              //   ].expiry_date_warn_day_count = response.data.data.goodInfo.expiry_date_warn_day_count.toString()
              // this.goodInfo.goodInfoData[
              //   this.goodInfo.editGoodIndex
              //   ].stock_warn_count = response.data.data.goodInfo.stock_warn_count.toString()

              this.$message.success('修改成功')
            }
          })
        } else if (val.isCreated == 1) {


          if(val.is_reuse == ""){
             val.is_reuse = 0
          }else{
            val.is_reuse = parseInt(val.is_reuse)
          }

          if(val.stock_warn_count == ""){
             val.stock_warn_count = 0
          }else{
            val.stock_warn_count = parseInt(val.stock_warn_count)
          }

          if(val.is_zero_flag == 1){
            if(val.split_of_number ==""){
                this.$message.error("拆零次数不能为空!")
                return
            }
          }

          //新增
          createGoodInfo(val).then(response => {
            if (response.data.state == 0) {
              // this.$message.error(response.data.msg)
              // return false
              this.$message.error("同一耗材类型同一规格名称不能重复录入!")
            } else {
              this.$refs.addConsumable.hide();
              this.getList();
              // this.goodInfo.goodInfoData.unshift(response.data.data.goodInfo)
              this.$message.success('新增成功')
            }
          })
        }
      },
      goodInfoDialogCancle: function() {
        this.$refs.addConsumable.hide()
      },
      getGoodTypeByID(id){
        let name = ""
        for(let i = 0;  i < this.goodInfo.goodInfoDialog.formValue.goodType.length;i++){
          if(this.goodInfo.goodInfoDialog.formValue.goodType[i].id == id){
            name = this.goodType[i].type_name
          }
        }
        return name

      },
      showInfoDialog: function() {
        this.getAllDealer();
        this.getAllManufacturer();
        this.goodInfo.goodInfoDialog.formValue.goodType = [];
        GetAllGoodType().then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
            return false
          } else {
            for (let i = 0; i < response.data.data.goodType.length; i++) {
              if (response.data.data.goodType[i].type == 1) {
                response.data.data.goodType[i].type_name = response.data.data.goodType[i].type_name + '(系统设定)'
              }
              this.goodInfo.goodInfoDialog.formValue.goodType.push(response.data.data.goodType[i])
            }
            if (this.goodInfo.goodInfoDialog.formValue.goodType.length <= 0) {
              this.$message.error('请先新增商品类型');

            } else {
              this.goodInfo.goodInfoDialog.isVisibility = true;
              this.goodInfo.goodInfoDialog.isCreated = 1
            }
          }
        });
        this.$refs.addConsumable.show()

      },
      getAllDealer: function() {
        this.goodInfo.goodInfoDialog.formValue.dealers = [];
        GetAllDeals().then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
            return false
          } else {
            for (let i = 0; i < response.data.data.dealer.length; i++) {
              this.goodInfo.goodInfoDialog.formValue.dealers.push(
                response.data.data.dealer[i]
              );
              this.dealers.push(response.data.data.dealer[i])
            }
          }
        })
      },
      getAllManufacturer: function() {
        this.goodInfo.goodInfoDialog.formValue.manufacturers = [];
        GetAllManufacturer().then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
            return false
          } else {
            var obj = {id:0,manufacturer_name:"全部"};
            this.manufacturers.push(obj);
            for (let i = 0; i < response.data.data.manufacturer.length; i++) {
              this.goodInfo.goodInfoDialog.formValue.manufacturers.push(
                response.data.data.manufacturer[i]
              );
              this.manufacturers.push(response.data.data.manufacturer[i])
            }

          }
        })
      },
      getAllGoodType: function() {
        this.goodInfo.goodInfoDialog.formValue.goodType = [];
        GetAllGoodType().then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
            return false
          } else {

            for(let i=0;i<response.data.data.goodType.length;i++){
              this.goodTypeList.push(response.data.data.goodType[i])
            }

            for (let i = 0; i < response.data.data.goodType.length; i++) {
              if (response.data.data.goodType[i].type == 1) {
                response.data.data.goodType[i].type_name = response.data.data.goodType[i].type_name + '(系统设定)'
              }
              this.goodInfo.goodInfoDialog.formValue.goodType.push(response.data.data.goodType[i]);
              this.goodType.push(response.data.data.goodType[i])
            }
            this.getList();

          }
        })
      },
      handleSizeChange(val) {
        this.limit = val;
        this.getList()
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getList()
      },
      searchAction() {
        this.is_use = "";
        this.is_charge = "";
        this.good_kind = "";
        this.getList()
      },clickSelfPayment(id){
      this.$refs.selfPayment.show(id,2)
      },
      openForm() {

        this.getAllDealer();
        this.getAllManufacturer();
        this.goodInfo.goodInfoDialog.formValue.goodType = [];
        GetAllGoodType().then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
            return false
          } else {
            for (let i = 0; i < response.data.data.goodType.length; i++) {
              if (response.data.data.goodType[i].type == 1) {
                response.data.data.goodType[i].type_name = response.data.data.goodType[i].type_name + '(系统设定)'
              }
              this.goodInfo.goodInfoDialog.formValue.goodType.push(response.data.data.goodType[i])
            }
            if (this.goodInfo.goodInfoDialog.formValue.goodType.length <= 0) {
              this.$message.error('请先新增商品类型');

            } else {
              this.goodInfo.goodInfoDialog.isVisibility = true;
              this.goodInfo.goodInfoDialog.isCreated = 1
            }
          }
        });
        this.goodInfo.goodInfoDialog.formValue.good_id = '';
        this.goodInfo.goodInfoDialog.formValue.specification_name = '';
        this.goodInfo.goodInfoDialog.formValue.buy_price = '';
        this.goodInfo.goodInfoDialog.formValue.sell_price = '';
        this.goodInfo.goodInfoDialog.formValue.remark = '';
        this.goodInfo.goodInfoDialog.formValue.manufacturer = '';
        this.goodInfo.goodInfoDialog.formValue.good_type_id = '';
        this.goodInfo.goodInfoDialog.formValue.dealer = '';
        this.goodInfo.goodInfoDialog.formValue.expiry_date_warn_day_count = '';
        this.goodInfo.goodInfoDialog.formValue.stock_warn_count = '';
        this.goodInfo.goodInfoDialog.formValue.is_reuse = '2';
        this.goodInfo.goodInfoDialog.formValue.good_name = '';
        this.goodInfo.goodInfoDialog.formValue.pinyin = '';
        this.goodInfo.goodInfoDialog.formValue.wubi = '';
        this.goodInfo.goodInfoDialog.formValue.good_kind = '';
        this.goodInfo.goodInfoDialog.formValue.medical_insurance_level = '';
        this.goodInfo.goodInfoDialog.formValue.retail_price = '';
        this.goodInfo.goodInfoDialog.formValue.medical_insurance_number = '';
        this.goodInfo.goodInfoDialog.formValue.provinces_code = '';

        this.goodInfo.goodInfoDialog.formValue.is_special_diseases = '';
        this.goodInfo.goodInfoDialog.formValue.is_record = '';
        this.goodInfo.goodInfoDialog.formValue.statistics_category = '';
        this.goodInfo.goodInfoDialog.formValue.good_status = '';
        this.goodInfo.goodInfoDialog.formValue.default_count = '';
        this.goodInfo.goodInfoDialog.formValue.sign = '';
        this.goodInfo.goodInfoDialog.formValue.is_default = '';
        this.goodInfo.goodInfoDialog.formValue.is_charge_use = '';
        this.goodInfo.goodInfoDialog.formValue.is_charge_predict = '';
        this.goodInfo.goodInfoDialog.formValue.is_statistics_work = '';
        this.goodInfo.goodInfoDialog.formValue.sort = '';
        this.goodInfo.goodInfoDialog.formValue.is_doctor_use = '';
        this.goodInfo.goodInfoDialog.formValue.agent = '';
        this.goodInfo.goodInfoDialog.formValue.good_number = '';
        this.goodInfo.goodInfoDialog.formValue.register_number = '';
        this.goodInfo.goodInfoDialog.formValue.register_number_name = '';



        this.$refs.addConsumable.show(0)
      },
     handleSelectionChange(val) {
      this.selectDrug = val;
     },
      // toRecord(){

      //    var that = this
      //    axios.get('http://127.0.0.1:9532/sz/api/goods/get').then(function(response) {
      //     if (response.data.state == 0) {
      //          that.$message.error(response.data.msg)
      //          return false
      //       } else {
      //         that.$message({ message: '备案成功', type: 'success' })
      //        }
      //      }).catch(function(error) {
      //   })
      // },
       BatchDelete() {
          if (this.selectDrug.length == 0) {
            this.$message.error("请选择要备案的信息");
            return false;
          }
          this.$confirm(
            "确认要备案所选记录吗? <br>",
            "备案提示",
            {
              dangerouslyUseHTMLString: true,
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }
          ).then(() => {
            var ids = [];
            var idMap = {};
            for (const index in this.selectDrug) {
              ids.push(this.selectDrug[index].id);
              idMap[this.selectDrug[index].id] = this.selectDrug[index].id;
            }

            var idss = ids.join(',');
            let params = {
              ids:idss,
              admin_user_id:this.$store.getters.xt_user.user.id
            };


            var that = this;
            axios.get('http://127.0.0.1:9532/sz/api/goods/get',{ params: params }).then(function(response) {
            if (response.data.state == 0) {
                  that.$message.error(response.data.data.msg);
                  return false
                } else {
                 if(response.data.data.msg == ""){
                  that.$message.success("备案成功!");
                  that.getList()
               }
               if(response.data.data.msg!=""){
                  that.$message.error(response.data.data.msg);
                  that.getList()
                }
                }
              }).catch(function(error) {
            })
          });
     },
      toReturn(id,isMark){

         var that = this;
         let params = {
             'id':id,
             'type_id':3,
             'is_mark':isMark,
             'admin_user_id':this.$store.getters.xt_user.user.id,
          };
         axios.get('http://127.0.0.1:9532/sz/api/revocation/get',{params:params}).then(function(response) {
          if (response.data.state == 0) {
               that.$message.error(response.data.data.msg);
               return false
            } else {
              if(response.data.data.msg == ""){
                  that.$message.success("备案成功!");
                  that.getList()
               }
               if(response.data.data.msg!=""){
                  that.$message.error(response.data.data.msg);
                  that.getList()
               }
             }
           }).catch(function(error) {
        })
      },
      changeManufacture(){
        this.getList()
      },
      changeRecord(){
        this.getList()
      },
      changeTypeList(){
        this.getList()
      },
      handleSuccess({ results, header }) {

        if (header != undefined && header.length > 0) {

          var isHasMedicalInsuranceLevel = header.includes('*医保等级');

          var isHasGoodUnit = header.includes('*包装单位');

          var isHasStockWarnCount = header.includes('*库存警戒');

          var isHasManuFacturer =  header.includes('*生产厂商');

          var isHasGoodName = header.includes('*耗材名称');

          var isHasGoodKand = header.includes('*耗材种类');

          var isHasSpecificationName = header.includes('*规格型号');

          var isHasBuyPrice = header.includes('*零售价');

          if (!(isHasMedicalInsuranceLevel && isHasGoodUnit && isHasStockWarnCount && isHasManuFacturer  && isHasGoodName && isHasGoodKand && isHasSpecificationName &&  isHasBuyPrice)) {
            this.dialogVisible = true;
            return
          }
        }else {
          this.dialogVisible = true;
          return
        }

       var tableData = [];
       for(let i=1;i<results.length;i++){
         let obj = {"good_kind_id":0,"good_type_id":0,"medical_insurance_id":0,"dealer_id":0,"statistic_id":0,"manufacturer_id":0,"unit_id":0,"default_count":1,"default_count_unit":"","buy_price":"","retail_price":""};
         for (var key in results[i]) {

           if (results[i]['*耗材名称'] === undefined) {
                obj['good_name'] = ''
              } else {
           if (key == '*耗材名称') {
               obj['good_name'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['*耗材种类'] === undefined) {
                obj['good_kind'] = ''
              } else {
           if (key == '*耗材种类') {
               obj['good_kind'] = results[i][key].replace(/\s/g,"")
              }
           }

          if (results[i]['*耗材类型'] === undefined) {
                obj['type_name'] = ''
              } else {
           if (key == '*耗材类型') {
               obj['type_name'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['*医保等级'] === undefined) {
                obj['medical_insurance_level'] = ''
              } else {
           if (key == '*医保等级') {
               obj['medical_insurance_level'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['*规格型号'] === undefined) {
                obj['specification_name'] = ''
              } else {
           if (key == '*规格型号') {
               obj['specification_name'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['*生产厂商'] === undefined) {
                obj['manufacturer'] = ''
              } else {
           if (key == '*生产厂商') {
               obj['manufacturer'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['*包装单位'] === undefined) {
                obj['good_unit'] = ''
              } else {
             if (key == '*包装单位') {
               obj['good_unit'] = results[i][key].replace(/\s/g,"")
              }
           }
           if (results[i]['*默认单次用量'] === undefined) {
                obj['default_count'] = ''
              } else {
             if (key == '*默认单次用量') {
               obj['default_count'] = parseInt(results[i][key].replace(/\s/g,""))
              }
           }

           if (results[i]['*默认单次用量单位'] === undefined) {
                obj['default_count_unit'] = ''
              } else {
             if (key == '*默认单次用量单位') {
               obj['default_count_unit'] = results[i][key].replace(/\s/g,"")
              }
           }

          if (results[i]['*零售价'] === undefined) {
                obj['retail_price'] = ''
              } else {
             if (key == '*零售价') {
               obj['retail_price'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['*进货价'] === undefined) {
                obj['buy_price'] = ''
              } else {
             if (key == '*进货价') {
               obj['buy_price'] = results[i][key].replace(/\s/g,"")
              }
           }

            if (results[i]['*库存警戒'] === undefined) {
                obj['stock_warn_count'] = ''
              } else {
             if (key == '*库存警戒') {
               obj['stock_warn_count'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['经销商'] === undefined) {
                obj['dealer'] = ''
              } else {
             if (key == '经销商') {
               obj['dealer'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['拼音'] === undefined) {
                obj['pinyin'] = ''
              } else {
             if (key == '拼音') {
               obj['pinyin'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['五笔'] === undefined) {
                obj['wubi'] = ''
              } else {
             if (key == '五笔') {
               obj['wubi'] = results[i][key].replace(/\s/g,"")
              }
           }



           if (results[i]['医保编码'] === undefined) {
                obj['medical_insurance_number'] = ''
              } else {
             if (key == '医保编码') {
               obj['medical_insurance_number'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['省编码'] === undefined) {
             obj['provinces_code'] = ''
           } else {
             if (key == '省编码') {
               obj['provinces_code'] = results[i][key].replace(/\s/g,"")
             }
           }

          if (results[i]['是否特病目录'] === undefined) {
                obj['is_special_diseases'] = ''
              } else {
             if (key == '是否特病目录') {
               obj['is_special_diseases'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['是否备案'] === undefined) {
                obj['is_record'] = ''
              } else {
             if (key == '是否备案') {
               obj['is_record'] = results[i][key].replace(/\s/g,"")
              }
           }

          if (results[i]['统计分类'] === undefined) {
                obj['statistics_category'] = ''
              } else {
             if (key == '统计分类') {
               obj['statistics_category'] = results[i][key].replace(/\s/g,"")
              }
           }

          if (results[i]['状态'] === undefined) {
                obj['good_status'] = ''
              } else {
             if (key == '状态') {
               obj['good_status'] = results[i][key].replace(/\s/g,"")
              }
           }


          if (results[i]['社保目录编码'] === undefined) {
                obj['social_security_directory_code'] = ''
              } else {
             if (key == '社保目录编码') {
               obj['social_security_directory_code'] = results[i][key].replace(/\s/g,"")
              }
           }

          if (results[i]['生产地类别'] === undefined) {
                obj['production_type'] = ''
              } else {
             if (key == '生产地类别') {
               obj['production_type'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['特殊医用材料标志'] === undefined) {
                obj['special_medical'] = ''
              } else {
             if (key == '特殊医用材料标志') {
               obj['special_medical'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['批准文号'] === undefined) {
                obj['number'] = ''
              } else {
             if (key == '批准文号') {
               obj['number'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['注册编号'] === undefined) {
                obj['register_number'] = ''
              } else {
             if (key == '注册编号') {
               obj['register_number'] = results[i][key].replace(/\s/g,"")
              }
           }

           if (results[i]['备注'] === undefined) {
                obj['remark'] = ''
              } else {
             if (key == '备注') {
               obj['remark'] = results[i][key].replace(/\s/g,"")
              }
           }


         }
         tableData.push(obj);
        var goodUnit =  this.$store.getters.good_unit;


        for(let i=0;i<tableData.length;i++){

         for(let c=0;c<goodUnit.length;c++){
            if(tableData[i].good_unit == goodUnit[c].name){
               tableData[i].unit_id = goodUnit[c].id
            }
         }

        }
       }

       for(let i=0;i<tableData.length;i++){
          tableData[i].stock_warn_count = parseInt(tableData[i].stock_warn_count);

          if(tableData[i].is_special_diseases == "是"){
              tableData[i].is_special_diseases = 1
          }
          if(tableData[i].is_special_diseases == "否"){
              tableData[i].is_special_diseases = 2
          }

          if(tableData[i].is_record == "是"){
             tableData[i].is_record = 1
          }
          if(tableData[i].is_record == "否"){
             tableData[i].is_record = 2
          }



          if(tableData[i].special_medical == "是"){
             tableData[i].special_medical = "1"
          }
          if(tableData[i].special_medical == "否"){
             tableData[i].special_medical = "2"
          }
       }

       for(let i=0;i<tableData.length;i++){

          if(tableData[i].is_special_diseases == ""){
             tableData[i].is_special_diseases = 0
          }else{
            tableData[i].is_special_diseases = parseInt(tableData[i].is_special_diseases)
          }

          if(tableData[i].is_record == ""){
             tableData[i].is_record = 0
          }else{
            tableData[i].is_record = parseInt(tableData[i].is_record)
          }


       }

       let params = {
          'goods':tableData
        };
        console.log("param2332323223",params)

        postGoodInformation(params).then(response=>{
           if(response.data.state == 1){
             var msg =  response.data.data.msg;
             this.$message.success("导入成功!");
             this.getList();
             this.getInitializtion()
           }else{
             this.$message.error("导入失败,请下载日志查看")
           }
        })
      },
      generateTxt: function(log) {
        var content = '';
        var errlog = log.err_logs;
        content = this.getContent(log);
        for (let i = 0; i < errlog.length; i++) {
          if (content.length == 0) {
            content = errlog[i].err_msg
          } else {
            content = content + '\n' + errlog[i].err_msg
          }
        }

        var url = new Blob(['\ufeff' + content], { type: 'text/txt,charset=UTF-8' });
        if (typeof url === 'object' && url instanceof Blob) {
          url = URL.createObjectURL(url) // 创建blob地址
        }
        const aLink = document.createElement('a');
        aLink.href = url;
        aLink.download = this.timestampToTime(log.export_time) + '患者导入日志' + '.txt';
        aLink.click()

      },
      getContent(log) {
        return '您导入的文档共' + log.total_num + '条患者数据' + '，' + '已成功导入' + log.success_num + '条，导入失败' + log.fail_num + '条,'
      },
      timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '年';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
        var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + '日 ';
        var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + '时';
        var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + '分';
        var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds()) + '秒';
        return Y + M + D + h + m + s
      },
       generateLog() {
        let params = {
          'log_type': 5
        };
        generateLog(params).then(
          response => {
            if (response.data.state === 1) {
              this.logs = response.data.data.logs;
              this.exportLogVisible = true
            } else {
              this.$message.error(response.data.msg)
            }
          }
        )

      },
      getInitializtion(){
       getInitializtion().then(response=>{
         if(response.data.state == 1){
           var goodKindList = response.data.data.goodKindList;

           this.goodKindList = goodKindList
           var medicalInsuranceLevelList =  response.data.data.medicalInsuranceLevelList
           console.log("医保等级",medicalInsuranceLevelList)
           this.medicalInsuranceLevelList = medicalInsuranceLevelList
         }
       })
      },
      exportList(){
        import('@/vendor/Export2Excel').then(excel => {
         console.log("this.table",this.goodInfo.goodInfoDialog.formValue.goodType)

         for(let i=0;i<this.goodInfo.goodInfoData.length;i++){
           for(let j=0;j<this.goodKindList.length;j++){
              if(this.goodInfo.goodInfoData[i].good_kind == this.goodKindList[j].value){
                 this.goodInfo.goodInfoData[i].good_kind_name = this.goodKindList[j].name
              }
           }
           for(let z=0;z<this.goodInfo.goodInfoDialog.formValue.goodType.length;z++){
              if(this.goodInfo.goodInfoData[i].good_type_id == this.goodInfo.goodInfoDialog.formValue.goodType[z].id){

                 this.goodInfo.goodInfoData[i].good_type_name = this.goodInfo.goodInfoDialog.formValue.goodType[z].type_name
              }
           }

           for(let y=0;y<this.medicalInsuranceLevelList.length;y++){
              if(this.goodInfo.goodInfoData[i].medical_insurance_level == this.medicalInsuranceLevelList[y].value){
                 this.goodInfo.goodInfoData[i].medical_insurance_level_name = this.medicalInsuranceLevelList[y].name
              }
           }

           for(let s=0;s<this.manufacturers.length;s++){
             if(this.manufacturers[s].id == this.goodInfo.goodInfoData[i].manufacturer){
                this.goodInfo.goodInfoData[i].manufacturer_name =  this.manufacturers[s].manufacturer_name
             }
           }

          for(let a=0;a<this.dealers.length;a++){
             if(this.dealers[a].id == this.goodInfo.goodInfoData[i].dealer){
                 this.goodInfo.goodInfoData[i].dealer_name = this.dealers[a].dealer_name
             }
          }
         }
         console.log("hhhadhh233323232",this.goodInfo.goodInfoData)

         const tHeader = ['耗材名称','耗材种类','耗材类型','医保等级','规格型号','生产厂商','包装单位','进货价','零售价','库存警戒','经销商','默认单次用量','默认单次用量单位','拼音','五笔','医保编码','是否特病目录','是否备案','统计分类','状态','社保目录编码','生产地类别','特殊医用标志',"批准文号","注册编号","备注"]
         const filterVal = ['good_name', 'good_kind_name','good_type_name','medical_insurance_level_name','specification_name','manufacturer_name','packing_unit','buy_price','packing_price','stock_warn_count','dealer_name','default_count','default_count_unit','','','medical_insurance_number','是','','','','social_security_directory_code','','','number','register_number','']

         const data = this.formatJson(filterVal,this.goodInfo.goodInfoData)

         excel.export_json_to_excel({
           header: tHeader,
           data,
           filename: '耗材信息'
         })
          this.downloadLoading = false

        })
       },
       formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
       },
       getManufactur(manufacturer){
        var manufacturer_name =""
         for(let i=0;i<this.manufacturers.length;i++){
           if(manufacturer == this.manufacturers[i].id){
              manufacturer_name = this.manufacturers[i].manufacturer_name
           }
         }
         return manufacturer_name
       }

    },
    created() {
      this.goodInfo.goodInfoDialog.formValue.is_user = "2"
      this.getAllGoodType();
      this.getAllDealer();
      this.getAllManufacturer();
      this.goodInfo.goodInfoDialog.formValue.goodUnit = this.$store.getters.good_unit;
      this.getInitializtion()

    }
  }
</script>
