123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- var num = 0
- let arr = [{
- id: 0,
- name: "故障记录",
- English: 'faultRecord'
- },
- {
- id: 1,
- name: "故障案例",
- English: 'repairManual'
- },
- {
- id: 2,
- name: "技术资料",
- English: 'article'
- },
- ]
- $(function() {
- var storage = window.localStorage;
- let user = window.localStorage.getItem('user');
- let userInfo = JSON.parse(user);
- let type = '';
- var momEle = document.getElementById("search-box");
- $('.search-type span').click((e) => {
- console.log(e.target.id)
- type = e.target.id;
- $('.search-type span').css({
- color: 'black',
- // borderBottom: 'black'
- });
- e.target.style.color = '#09c'
- // e.target.style.borderBottom = '1px solid #09c'
- })
- $('#logOut').click(() => {
- const data = {
- id: userInfo.id
- };
- $.ajax({
- type: "post",
- url: urlBase + "api/common/login",
- async: true,
- data: JSON.stringify(data),
- success: res => {
- if (res.status == 0) {
- window.location.href = '../index.html';
- } else {
- alert(res.msg);
- }
- },
- error: xhr => {
- console.log(xhr)
- }
- });
- })
- $("input[id='add']").click(add);
- function add() {
- num++;
- var divEle = document.createElement("div");
- divEle.setAttribute("class", "form");
- divEle.setAttribute("id", `${num}`);
- var inner =
- '<div style="margin-top: 15px;display: block;margin-left:18% ;width:100%;" class="form"><select id="sel'+num+'" class="sel" lay-search="sel" lay-verify="required"><option value="">AND</option><option value="1">OR</option><option value="2">NOT</option></select><select id="all'+num+'" class="all" lay-search="all" lay-verify="required" style="margin-left:22px;"><option value="">故障记录</option><option value="1">故障案例</option><option value="2">技术资料</option></select><input style="width:256px;margin-left:10px;" type="text" id="search' +
- num + '" class="searchInput" placeholder="请输入关键字" /></div>'
- divEle.innerHTML = inner;
- // alert(divEle.innerHTML);
- if (num >= 4) {
- alert("最多四条")
- } else {
- momEle.appendChild(divEle);
- }
- }
- $("input[id='pop']").click(pop);
- function pop() {
- if (num != 0) {
- var current_dom = document.getElementById(`${num}`);
- momEle.removeChild(current_dom);
- num--
- } else {
- alert('最少有一个字段')
- }
- }
- $('#searchBtn').click(() => {
- if ($('.searchInput').val() == "") {} else {
- $('.search-box').addClass('search-box-toLeft');
- $('.search-data').css({
- 'display': 'block'
- });
- const data = {
- type: type,
- keyword: $('.searchInput').val()
- };
- $.ajax({
- type: "get",
- url: urlBase + "api/common/find",
- async: true,
- data: data,
- headers: {
- // token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxIn0.Oik3R7IxeUi9v9d0C7kvFd2gF_xSu4WjspKKeXy3dGw"
- token: sessionStorage.getItem('token')
- },
- success: res => {
- if (res.status == 0) {
- $('.search-data-list').html();
- let data = res.data;
- let str = '';
- var name, path;
- let allData = [];
- for (var index in data) {
- for (var i = 0; i < data[index].length; i++) {
- cData = data[index];
- if (index == 'repairManual') {
- name = cData[i].device_type;
- // console.log(name)
- } else if (index == 'faultRecord') {
- name = cData[i].device_name + cData[i].equipment_name +
- cData[i].fault_content;
- // console.log(name)
- } else if (index == 'article') {
- name = cData[i].keywords;
- // console.log(name)
- }
- var fileType;
- if (cData[i].file_path) {
- fileType = cData[i].file_path.split('.')[1];
- path = urlBase + cData[i].file_path;
- }
- str += '<li class="search-data-item"><a href="' + path +
- '">' + name +
- '</a></li>'
- // console.log(str)
- }
- }
- $('.search-data-list').html(str)
- } else {
- alert(res.msg);
- }
- },
- error: xhr => {
- console.log(xhr)
- }
- });
- }
- });
- function getAll() {
- // $("#all").append($("<option>", {
- // value: -1,
- // text: "请选择"
- // }));
- for (var i = 0; i < arr.length; i++) {
- $("#all").append(
- $("<option>", {
- // value: arr[i].id,
- text: arr[i].name
- })
- );
- }
- };
- getAll()
-
- layui.use(["form"], function() {
- var form = layui.form
- form.on("select", function(data) {
- if (data.elem.id === "all"){
- roleName = data.elem[data.elem.selectedIndex].text;
- console.log(roleName)
- }
- })
- })
- })
|