<template>
  <div class="testdiv">
    <div class="divborder newSearchDiv">
      <!-- 搜索条件--程序号 -->
      <div class="filter">
        <label>{{ $t("600009") }}：</label>
        <Input class="searchInput" type="text" v-model="index_Program_number" />
      </div>
      <!-- 搜索条件--产品名称 -->
      <div class="filter">
        <label>{{ $t("100088") }}：</label>
        <Select
          v-model="index_Program_name"
          label-in-value
          clearable
          filterable
          class="searchSelect"
        >
          <Option
            v-for="item in products1"
            :value="item.name"
            :key="item.id"
            :label="item.name"
            >{{ item.name }}({{ item.code }})</Option
          >
        </Select>
      </div>
      <!-- 搜索条件--审核状态 -->
      <div class="filter">
        <label>{{ $t("700095") }}：</label>
        <Select
          v-model="index_audit_status"
          label-in-value
          clearable
          class="searchSelect"
        >
          <Option :value="1">待审核</Option>
          <Option :value="2">已审核</Option>
          <Option :value="3">被拒绝</Option>
        </Select>
      </div>
      <!-- 按钮组 -->
      <div class="searchBtn">
        <!-- 查询按钮 -->
        <Button
          v-show="btnshow1"
          type="primary"
          class="twoWord"
          icon="ios-search"
          @click="search(1, 10)"
          >查询</Button
        >
        <!-- 添加按钮 -->
        <Button
          v-show="btnshow2"
          type="success"
          class="twoWord"
          icon="md-add-circle"
          @click="add()"
          >添加</Button
        >
        <!-- 修改按钮 -->
        <Button
          v-show="btnshow3"
          type="warning"
          class="twoWord"
          icon="ios-build"
          @click="edit()"
          >修改</Button
        >
        <!-- 删除按钮 -->
        <Button
          v-show="btnshow4"
          type="error"
          class="twoWord"
          icon="md-close-circle"
          @click="dele()"
          >删除</Button
        >
        <!-- 下载按钮 -->
        <Button
          v-show="btnshow5"
          type="primary"
          class="twoWord intervalRight"
          icon="md-download"
          @click="download()"
          >下载</Button
        >
        <!-- 编辑内容按钮 -->
        <Button
          v-show="btnshow6"
          type="primary"
          class="fourWord"
          icon="md-create"
          @click="editprogram()"
          >编辑内容</Button
        >
        <!-- <Button v-show="btnshow2" type="success" class="twoWord" icon="md-add-circle" @click="daoru()">导入</Button> -->
      </div>
    </div>
    <div class="divborder newTableDiv">
      <!-- 主体表格 -->
      <template>
        <Table
          class="tableClass"
          ref="currentRowTable"
          @on-expand="handleExpandChange"
          @on-current-change="handleRowChange"
          @on-selection-change="handleselection"
          highlight-row
          :data="tableData1"
          :columns="tableColumns1"
        >
          <template slot-scope="{ row, index }" slot="content">{{
            row.content
          }}</template>
          <template slot-scope="{ row, index }" slot="xuhao">
            <span>{{ row.xuhao }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="program_code">
            <span>{{ row.program_code }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="productname">
            <span>{{ row.productname }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="code">
            <span>{{ row.code }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="file_name">
            <span>{{ row.file_name }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="createname">
            <span>{{ row.createname }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="createtime">
            <span>{{ row.createtime }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="create_remark">
            <span>{{ row.create_remark }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="checkname">
            <span>{{ row.checkname }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="checktime">
            <span>{{ row.checktime }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="checkinfo">
            <span v-if="row.checkinfo === 1">{{ $t("700114") }}</span>
            <span v-if="row.checkinfo === 2">{{ $t("700115") }}</span>
            <span v-if="row.checkinfo !== 1 && row.checkinfo !== 2">NA</span>
          </template>
          <template slot-scope="{ row, index }" slot="check_remark">
            <span>{{ row.check_remark }}</span>
          </template>
          <template slot-scope="{ row, index }" slot="checkstatus">
            <span
              v-if="row.checkstatus === 1"
              style="background-color: #ffdf25"
              >{{ $t("700096") }}</span
            >
            <span
              v-if="row.checkstatus === 2"
              style="background-color: #00ff00"
              >{{ $t("700097") }}</span
            >
            <span
              v-if="row.checkstatus === 3"
              style="background-color: #ff0000"
              >{{ $t("700098") }}</span
            >
          </template>
        </Table>
      </template>
      <!-- 分页器 -->
      <div class="pageDiv">
        <div class="pageDirection">
          <Page
            :total="total"
            :current="page"
            @on-change="changePage"
            show-elevator
            show-sizer
            show-total
            @on-page-size-change="handlePageSize"
            :page-size-opts="[10, 20, 30, 40, 100]"
          ></Page>
        </div>
      </div>
    </div>
    <!-- 添加弹框 -->
    <Modal
      class="newModalClass"
      :title="title1"
      v-model="editmodal"
      :styles="{ width: '600px' }"
    >
      <div class="modal_body">
        <div class="filter">
          <label> <i>*</i>选择文件： </label>
          <span style="width: 300px" v-show="update">{{
            editobj.file_name
          }}</span>
          <label
            class="publicinput"
            style="
              text-align: center;
              background-color: #2d8cf0;
              color: white;
              vertical-align: middle;
              cursor: pointer;
            "
          >
            <input
              class="publicinput"
              style="border: 0px; display: none"
              type="file"
              ref="fileIntedit"
              @change="uploadprogram"
              accept=".txt, .eia, .mpf, .min, .spf, .cnc, .nc, .prg, .zip"
            />
            {{ $t("600576") }}
          </label>
        </div>
        <br />
        <div class="filter">
          <label> <i>*</i>程序号： </label>
          <Input
            class="searchInput"
            type="text"
            v-model="editobj.program_code"
            @blur="checkSame()"
          />
        </div>
        <div class="filter">
          <label> <i>*</i>产品名称： </label>
          <Select
            v-model="editobj.productid"
            label-in-value
            clearable
            filterable
            class="searchSelect"
          >
            <Option v-for="item in products" :value="item.id" :key="item.id">{{
              item.name
            }}</Option>
          </Select>
        </div>
        <div class="filter">
          <label> <i>*</i>审核人员： </label>
          <Select
            v-model="editobj.checkmid"
            label-in-value
            clearable
            filterable
            class="searchSelect"
          >
            <Option v-for="item in users" :value="item.mid" :key="item.id">{{
              item.name + " " + item.work_code
            }}</Option>
          </Select>
        </div>

        <div class="filter" style="display: flex; margin-bottom: 30px">
          <label id="desc">备注：</label>
          <Input
            type="textarea"
            v-model="editobj.create_remark"
            maxlength="255"
            show-word-limit
            class="searchInput MaxWidth"
            :autosize="{ minRows: 2, maxRows: 2 }"
          />
        </div>
      </div>
      <div slot="footer">
        <Button type="text" size="large" @click="cancle">取消</Button>
        <Button type="primary" v-if="type === 1" size="large" @click="adddata"
          >添加</Button
        >
        <Button type="primary" v-if="type === 2" size="large" @click="editdata"
          >修改</Button
        >
      </div>
    </Modal>
    <!-- 编辑内容弹框 -->
    <Modal
      class="newModalClass"
      :title="title2"
      v-model="contentmodal"
      :styles="{ width: '670px' }"
    >
      <div
        class="modal_body"
        style="
          width: 670px !important;
          padding: 0 0px;
          height: 450px !important;
        "
      >
        <div style="width: 600px; float: left; height: 100%; padding-left: 5px">
          <textarea
            style="
              white-space: nowrap;
              overflow: scroll;
              resize: none;
              width: 580px;
              height: 450px;
            "
            v-model="editcontent"
          ></textarea>
        </div>
      </div>
      <div slot="footer">
        <Button type="text" size="large" @click="cancle">取消</Button>
        <Button type="primary" size="large" @click="editprogramcontent"
          >确定</Button
        >
      </div>
    </Modal>
    <!-- 修改弹框 -->
    <Modal
      class="newModalClass11"
      :title="title1"
      v-model="editmodal2"
      :styles="{ width: '600px' }"
    >
      <div class="modal_body">
        <div class="filter">
          <label> <i>*</i>导入程序文件： </label>
          <span style="width: 300px" v-show="update">{{
            editobj1.file_name
          }}</span>
          <label
            class="publicinput"
            style="
              text-align: center;
              background-color: #2d8cf0;
              color: white;
              vertical-align: middle;
              cursor: pointer;
            "
          >
            <input
              class="publicinput"
              style="border: 0px; display: none"
              type="file"
              ref="fileIntedit1"
              @change="uploadprogram1"
              accept=".txt, .eia, .mpf, .min, .spf, .cnc, .nc, .prg, .zip"
            />
            {{ $t("600576") }}
          </label>
        </div>
        <br />
        <div class="filter">
          <label> <i>*</i>导入关系文件： </label>
          <span style="width: 300px" v-show="update">{{
            editobj1.file_name1
          }}</span>
          <label
            class="publicinput"
            style="
              text-align: center;
              background-color: #2d8cf0;
              color: white;
              vertical-align: middle;
              cursor: pointer;
            "
          >
            <input
              class="publicinput"
              style="border: 0px; display: none"
              type="file"
              ref="fileIntedit2"
              @change="uploadprogram2"
              accept=".txt, .eia, .mpf, .min, .spf, .cnc, .nc, .prg, .zip, .json"
            />
            {{ $t("600576") }}
          </label>
        </div>
        <br />
      </div>
      <div slot="footer">
        <Button type="text" size="large" @click="cancle">取消</Button>
        <Button type="primary" v-if="type === 1" size="large" @click="daorudate"
          >添加</Button
        >
        <Button type="primary" v-if="type === 2" size="large" @click="daorudate"
          >修改</Button
        >
      </div>
    </Modal>
  </div>
</template>
<script>
import axios from "@/libs/api.request";
import "view-design/dist/styles/iview.css";

export default {
  data() {
    return {
      headers: {
        token: localStorage.getItem("token"),
        timestamp: localStorage.getItem("timestamp"),
        nonce: localStorage.getItem("nonce"),
        sign: localStorage.getItem("sign"),
      },
      page: 1,
      pagesize: 10,
      total: 0,
      index_audit_status: "",
      index_Program_name: "",
      index_Program_number: "",
      btnshow: true,
      btnshow1: false,
      btnshow2: false,
      btnshow3: false,
      downloadpg: false,
      btnshow4: false,
      btnshow5: false,
      btnshow6: false,
      tableData1: [],
      content: "",
      tableColumns1: [
        {
          type: "selection",
          width: 60,
          align: "center",
        },
        {
          type: "expand",
          width: 40,
          render: (h, params) => {
            if (params.row.id === this.obj.id) {
              var newArr = [];
              if (
                this.content !== null &&
                this.content !== undefined &&
                this.content !== ""
              ) {
                var infoArray = this.content.split("\n");
                infoArray.forEach((ele, i) => {
                  newArr.push(
                    h("p", [
                      h(
                        "span",
                        {
                          style: {
                            background: "#ddd",
                            display: "inline-block",
                            "text-align": "center",
                            padding: "0px 5px",
                            "min-width": "30px",
                          },
                        },
                        i + 1
                      ),
                      h("span", ele),
                    ])
                  );
                });
              }
              return h(
                "div",
                {
                  style: {
                    border: "1px solid black",
                    overflow: "auto",
                    width: "99%",
                    height: "200px",
                  },
                },
                [
                  h(
                    "div",
                    {
                      style: { "white-space": "nowrap", "max-width": "1000px" },
                    },
                    newArr
                  ),
                ]
              );
            }
          },
        },
        {
          type: "index2",
          title: "序号",
          key: "xuhao",
          slot: "xuhao",
          render: (h, params) => {
            // console.log(params.index + (this.page - 1) * this.pagesize + 1)
            return h(
              "span",
              params.index + (this.page - 1) * this.pagesize + 1
            );
          },
          width: 90,
        },

        {
          title: "程序号",
          key: "program_code",
          slot: "program_code",
        },
        {
          title: "产品名称",
          key: "productname",
          slot: "productname",
        },
        {
          title: "产品图纸号",
          key: "code",
          slot: "code",
        },
        {
          title: "文件名",
          key: "file_name",
          slot: "file_name",
        },
        {
          title: "创建人",
          key: "createname",
          slot: "createname",
        },
        {
          title: "创建时间",
          key: "createtime",
          slot: "createtime",
          width: 148,
        },
        {
          title: "创建备注",
          key: "create_remark",
          slot: "create_remark",
        },
        {
          title: "审核人",
          key: "checkname",
          slot: "checkname",
        },
        {
          title: "审核时间",
          key: "checktime",
          slot: "checktime",
          width: 148,
        },
        {
          title: "审核结果",
          key: "checkinfo",
          slot: "checkinfo",
        },
        {
          title: "审核备注",
          key: "check_remark",
          slot: "check_remark",
        },
        // {
        //   title: '版本',
        //   key: 'program_version'
        //   // slot: 'program_version'
        // },
        {
          title: "状态",
          key: "checkstatus",
          slot: "checkstatus",
        },
      ],
      users: [],
      products: [],
      products1: [],
      title1: "",
      title2: this.$t("700178"),
      editmodal: false,
      editmodal2: false,
      editobj: {},
      editobj1: {},
      type: 0,
      update: true,
      editcontent: "",
      contentmodal: false,
      selection: [],
    };
  },
  mounted() {
    this.getbtnpower();
    this.search(1, 10);
    this.getuser();
    this.getproduct();
    // 格式化表格样式
    this.tableColumns1 = this.$time.initTableTitle(this.tableColumns1);
  },
  methods: {
    uploadprogram() {
      // 上传照片
      const file = this.$refs.fileIntedit.files[0];
      const data = new FormData();
      data.append("file", file);
      axios
        .request({
          url: "/dnc/DncPgCreate/Upload",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            this.$Message.success(this.$t("100378"));
            var result = res.data.data;
            this.editobj.file_name = result.name;
            this.editobj.file_url = result.file_url;
            this.editobj.file_size = result.size;
            this.update = false;
            this.update = true;
          } else {
            this.update = false;
            this.update = true;
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    uploadprogram1() {
      // 上传照片
      const file = this.$refs.fileIntedit1.files[0];
      const data = new FormData();
      data.append("file", file);
      axios
        .request({
          url: "/dnc/DNCBaLingLing/Upload",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            this.$Message.success(this.$t("100378"));
            var result = res.data.data;
            this.editobj1.file_name = result.name;
            this.editobj1.file_url = result.file_url;
            this.editobj1.file_size = result.size;
            this.update = false;
            this.update = true;
          } else {
            this.update = false;
            this.update = true;
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    uploadprogram2() {
      // 上传照片
      const file = this.$refs.fileIntedit2.files[0];
      const data = new FormData();
      data.append("file", file);
      axios
        .request({
          url: "/dnc/DNCBaLingLing/UploadFile",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            this.$Message.success(this.$t("100378"));
            var result = res.data.data;
            this.editobj1.file_name1 = result.name;
            this.editobj1.file_url1 = result.file_url;
            this.editobj1.file_size1 = result.size;
            this.update = false;
            this.update = true;
          } else {
            this.update = false;
            this.update = true;
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    checkSame() {
      let data = {
        programcode: this.editobj.program_code,
      };
      this.axios
        .request({
          url: "/dnc/DncPgCreate/programCodePost",
          data,
          method: "post",
        })
        .then((res) => {
          console.log(res.data);
          if (res.data.ret == 1) {
            console.log(1);
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    cancle() {
      this.$refs.fileIntedit.setAttribute("type", "text");
      this.$refs.fileIntedit.setAttribute("type", "file");
      this.editobj = {};
      this.editmodal = false;
      this.search(this.page, this.pagesize);
      this.title1 = "";
      this.type = 0;
      this.editcontent = "";
      this.contentmodal = false;
    },
    // 获得按钮权限
    getbtnpower() {
      axios
        .request({
          url: "/dnc/DncPgCreate/GetCheckbuttons",
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            var checkbt = res.data.data;
            if (checkbt.addpower === 1) {
              // 添加权限
              this.btnshow1 = true; // 查询
              this.btnshow2 = true; // 添加
              this.btnshow3 = true; // 编辑
              this.btnshow5 = true; // 下载
              this.btnshow6 = true; // 编辑内容
            }
            if (checkbt.delpower === 1) {
              // 删除权限
              this.btnshow1 = true; // 查询
              this.btnshow4 = true; // 删除
              this.btnshow5 = true; // 下载
            }
            if (checkbt.allpower === 1) {
              // 超管权限
              // 添加权限
              this.btnshow1 = true; // 查询
              this.btnshow2 = true; // 添加
              this.btnshow3 = true; // 编辑
              this.btnshow4 = true; // 删除
              this.btnshow5 = true; // 下载
              this.btnshow6 = true; // 编辑内容
            }
          }
        });
    },
    search(page, pagesize) {
      var params = {
        programcode: this.index_Program_number,
        product_name: this.index_Program_name,
        checkstatus:
          this.index_audit_status === undefined ||
          this.index_audit_status === null ||
          this.index_audit_status === ""
            ? 0
            : this.index_audit_status,
        page: page,
        pagesize: pagesize,
      };
      this.page = page;
      this.selection = [];
      axios
        .request({
          url: "/dnc/DncPgCreate/GetProgramLists",
          params,
          method: "get",
        })
        .then((res) => {
          this.total = 0;
          this.tableData1 = [];
          if (
            res.data.ret === 1 &&
            res.data.data != null &&
            res.data.data.length > 0
          ) {
            this.total = res.data.total;
            this.mockTableData1(res.data.data);
          }
        });
      this.obj = {};
    },
    mockTableData1(tablelist) {
      let data = [];
      tablelist.forEach((item) => {
        if (item) {
          data.push({
            id: item.id,
            program_code: item.program_code,
            productid: item.productid,
            createmid: item.createmid,
            createtime: item.createtime,
            create_remark: item.create_remark,
            checkmid: item.checkmid,
            checktime: item.checktime,
            check_remark: item.check_remark,
            checkinfo: item.checkinfo,
            checkstatus: item.checkstatus,
            status: item.status,
            file_url: item.file_url,
            file_name: item.file_name,
            projectid: item.projectid,
            file_size: item.file_size,
            productname: item.productname,
            code: item.code,
            createname: item.createname,
            checkname: item.checkname,
            drawno: item.drawno,
            parentproccess: item.parentproccess,
            workproccess: item.workproccess,
            workproccess_name: item.workproccess_name,
            toll_gate_code: item.toll_gate_code,
            process_code: item.process_code,
            machine_code: item.machine_code,
            program_version: item.program_version,
          });
        }
      });
      this.tableData1 = data;
    },
    getuser() {
      axios
        .request({
          url: "/dnc/DncPgCreate/GetCheckUsers",
          method: "get",
        })
        .then((res) => {
          this.users = res.data.data;
        });
    },
    getproduct() {
      axios
        .request({
          url: "/config/ProjectProduct/GetProductsByCode?code=&name=&count=50",
          method: "get",
        })
        .then((res) => {
          this.products = res.data.data;
          this.products1 = res.data.data;
        });
    },
    editprogram() {
      if (
        this.obj.file_url === null ||
        this.obj.file_url === undefined ||
        this.obj.file_url === ""
      ) {
        this.$Message.error("请先选择");
        return;
      }
      axios
        .request({
          url: "/dnc/DncPgCreate/getContent?file_url=" + this.obj.file_url,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            this.editcontent = res.data.data.content;
            this.contentmodal = true;
            // var content = info.content.replace(/\n/g,"\r\n")
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    editprogramcontent() {
      if (this.obj === null || this.obj === undefined || this.obj === {}) {
        this.$Message.error(this.$t("9000147"));
        return;
      }
      var data = {
        id: this.obj.id,
        content: this.editcontent,
      };
      axios
        .request({
          url: "/dnc/DncPgCreate/UpdateProgramContent",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            this.$Message.success(this.$t("1064"));
            this.editcontent = "";
            this.contentmodal = false;
            // var content = info.content.replace(/\n/g,"\r\n")
            this.search(this.page, this.pagesize);
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    add() {
      this.$refs.fileIntedit.setAttribute("type", "text");
      this.$refs.fileIntedit.setAttribute("type", "file");
      this.editobj = {};
      this.title1 = this.$t("1002");
      this.type = 1;
      this.editmodal = true;
    },
    checkFor(v) {
      if (!v) {
        return true;
      }
      return false;
    },
    adddata() {
      const _this = this;
      let { checkFor } = this;
      if (checkFor(_this.editobj.file_url)) {
        _this.$Message.error(_this.$t(666614));
        return false;
      }

      if (checkFor(_this.editobj.program_code)) {
        _this.$Message.error(_this.$t(666615));
        return false;
      }

      if (checkFor(_this.editobj.productid)) {
        _this.$Message.error(_this.$t(666616));
        return false;
      }

      if (checkFor(_this.editobj.checkmid)) {
        _this.$Message.error(_this.$t(666617));
        return false;
      }

      var reg = new RegExp(
        "[`~!@%#$^&*()=|{}':;',　\\[\\]<>/? ／＼］\\；：%……+ ￥（）【】‘”“'．。，、？１２３４５６７８９０－＝＿＋～？！＠＃＄％＾＆＊）]"
      );
      if (reg.test(this.editobj.program_code)) {
        this.$Message.error("程序号含有特殊字符");
        return false;
      }

      var data = {
        programcode: this.editobj.program_code,
        productid: this.editobj.productid,
        checkmid: this.editobj.checkmid,
        createremark: this.editobj.create_remark,
        file_url: this.editobj.file_url,
        file_name: this.editobj.file_name,
        file_size: this.editobj.file_size,
      };

      axios
        .request({
          url: "/dnc/DncPgCreate/AddProgramPost",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret == 1) {
            this.editmodal = false;
            this.type = 0;
            this.editobj = {};
            this.$Message.success(this.$t("1055"));
            this.search(this.page, this.pagesize);
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    daoru() {
      this.$refs.fileIntedit.setAttribute("type", "text");
      this.$refs.fileIntedit.setAttribute("type", "file");
      this.editobj1 = {};
      this.title1 = this.$t("700147");
      this.type = 1;
      this.editmodal2 = true;
    },
    daorudate() {
      if (this.editobj.file_url1) {
        this.$Message.error("必填项不能为空");
        return false;
      }

      var data = {
        file_url1: this.editobj1.file_url1,
        file_name1: this.editobj1.file_name1,
        file_size1: this.editobj1.file_size1,
        file_url: this.editobj1.file_url,
        file_name: this.editobj1.file_name,
        file_size: this.editobj1.file_size,
      };

      axios
        .request({
          url: "/dnc/DNCBaLingLing/AddProgramPost",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret == 1) {
            this.editmodal = false;
            this.type = 0;
            this.editobj1 = {};
            this.$Message.success(this.$t("1055"));
            this.search(this.page, this.pagesize);
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    edit() {
      if (
        JSON.stringify(this.obj) === "{}" ||
        this.obj === undefined ||
        this.obj === null
      ) {
        this.$Message.error(this.$t("1043"));
        return false;
      }
      this.$refs.fileIntedit.setAttribute("type", "text");
      this.$refs.fileIntedit.setAttribute("type", "file");
      this.editobj = {};
      this.title1 = this.$t("1003");
      this.type = 2;
      this.getprogram();
      this.editmodal = true;
    },
    getprogram() {
      axios
        .request({
          url: "dnc/DncPgCreate/GetProgramInfo?programid=" + this.obj.id,
          method: "get",
        })
        .then((res) => {
          this.editobj = res.data.data;
        });
    },
    editdata() {
      const _this = this;
      let { checkFor } = this;
      if (checkFor(_this.editobj.file_url)) {
        _this.$Message.error(_this.$t(666614));
        return false;
      }

      if (checkFor(_this.editobj.program_code)) {
        _this.$Message.error(_this.$t(666615));
        return false;
      }

      if (checkFor(_this.editobj.productid)) {
        _this.$Message.error(_this.$t(666616));
        return false;
      }

      if (checkFor(_this.editobj.checkmid)) {
        _this.$Message.error(_this.$t(666617));
        return false;
      }

      var reg = new RegExp(
        "[`~!@%#$^&*()=|{}':;',　\\[\\]<>/? ／＼］\\；：%……+ ￥（）【】‘”“'．。，、？１２３４５６７８９０－＝＿＋～？！＠＃＄％＾＆＊）]"
      );
      if (reg.test(this.editobj.program_code)) {
        this.$Message.error("程序号含有特殊字符");
        return false;
      }

      var data = {
        programid: this.obj.id,
        programcode: this.editobj.program_code,
        productid: this.editobj.productid,
        checkmid: this.editobj.checkmid,
        createremark: this.editobj.create_remark,
        file_url: this.editobj.file_url,
        file_name: this.editobj.file_name,
        file_size: parseInt(this.editobj.file_size),
      };

      axios
        .request({
          url: "/dnc/DncPgCreate/EditProgram",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            this.editmodal = false;
            this.type = 0;
            this.editobj = {};
            this.$Message.success("修改成功");
            this.search(this.page, this.pagesize);
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    dele() {
      if (
        this.selection === [] ||
        this.selection.length === 0 ||
        this.selection === undefined
      ) {
        this.$Message.error(this.$t("1017"));
        return false;
      } else {
        var ids = this.selection.map((item) => {
          return item.id;
        });
        var data = {
          programid: ids,
        };
        this.$Modal.confirm({
          title: this.$t("1018"),
          content: "",
          width: "290px",
          closable: true,
          okText: this.$t("1004"),
          onOk: () => {
            axios
              .request({
                url: "/dnc/DncPgCreate/DelProgram",
                data,
                method: "post",
              })
              .then((res) => {
                if (res.data.ret === 1) {
                  this.search(this.page, this.pagesize);
                  this.$Message.success(this.$t("1058"));
                } else {
                  this.$Message.error(this.$t(res.data.msg));
                }
              });
          },
        });
      }
    },
    download() {
      if (
        this.obj.id == "" ||
        this.obj.id == undefined ||
        this.obj.id == null
      ) {
        this.$Message.error("请先选择数据");
        return false;
      }
      if (
        this.obj.file_url === null ||
        this.obj.file_url === undefined ||
        this.obj.file_url === ""
      ) {
        this.$Message.error(this.$t("9000147"));
        return;
      }
      let params = {
        file_url: this.obj.file_url,
        filename: this.obj.file_name,
      };
      let type = this.obj.file_name.slice(-3);
      if (type == "zip") {
        axios
          .request({
            url: "/dnc/DncPgCreate/GetContentDownload",
            params,
            method: "get",
          })
          .then((res) => {
            if (res.data.ret == 1) {
              window.location.href = this.axios.publicPath + res.data.data;
              // this.Down(
              //   this.axios.publicPath + res.data.data,
              //   this.obj.file_name
              // );
            } else {
              this.$Message.error(this.$t(res.data.msg));
            }
          });
      } else {
        axios
          .request({
            url: "/dnc/DncPgCreate/getContent?file_url=" + this.obj.file_url,
            method: "get",
          })
          .then((res) => {
            if (res.data.ret === 1) {
              var info = res.data.data;
              var content = info.content.replace(/\n/g, "\r\n");
              this.funDownload(content, this.obj.file_name);
            } else {
              this.$Message.error(this.$t(res.data.msg));
            }
          });
      }
    },
    Down(downloadUrl, fileName) {
      let a = document.createElement("a");
      a.href = downloadUrl;
      a.download = fileName;
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
    },
    // 下载方法
    funDownload(content, filename) {
      // 创建隐藏的可下载链接
      var eleLink = document.createElement("a");
      eleLink.download = filename;
      eleLink.style.display = "none";
      // 字符内容转变成blob地址
      var blob = new Blob([content]);
      eleLink.href = URL.createObjectURL(blob);
      // 触发点击
      document.body.appendChild(eleLink);
      eleLink.click();
      // 然后移除
      document.body.removeChild(eleLink);
    },
    handlePageSize(value) {
      this.pagesize = value;
      this.tableData1 = this.search(this.page, this.pagesize);
    },
    changePage(value) {
      this.page = value;

      this.tableData1 = this.search(this.page, this.pagesize);
    },
    handleRowChange(currentRow, oldCurrentRow) {
      this.obj = currentRow;
    },
    handleselection(value) {
      this.selection = value;
    },
    handleExpandChange(currentRow, status) {
      if (status) {
        this.handleSpinShow();
        this.content = "";
        axios
          .request({
            url: "/dnc/DncPgCreate/getContent?file_url=" + currentRow.file_url,
            method: "get",
          })
          .then((res) => {
            this.content = res.data.data.content;
            this.$Spin.hide();
          })
          .catch((res) => {
            this.$Spin.hide();
          });
        var objData = this.$refs.currentRowTable.$data.objData;
        var data = [];
        for (var val in this.$refs.currentRowTable.$data.objData) {
          data.push(val);
        }
        data.forEach((index) => {
          if (objData[index].id !== currentRow.id) {
            objData[index]._isExpanded = false;
          }
        });
      } else {
      }
    },
    handleFormatError(file) {
      this.$Message.error(this.$t("9000123"));
    },
    handleSuccess(res, file) {
      if (res.ret === 1) {
        this.$Message.success(this.$t("100378"));
      } else {
        this.$Message.error(this.$t(res.msg));
      }
    },
    handleError() {
      this.$Message.error(this.$t("600512"));
    },
    handleSpinShow() {
      this.$Spin.show();
    },
  },
};
</script>
<style lang="less" scoped>
.expand-row {
  margin-bottom: 16px;
}
.demo-spin-icon-load {
  animation: ani-demo-spin 1s linear infinite;
}
.ivu-input-word-count {
  text-align: center;
  position: absolute;
  right: 7px;
  bottom: 2px;
  padding-left: 7px;
  background: #fff;
  z-index: 1;
  display: inline-flex;
  color: #808695;
  font-size: 12px;
}
</style>
