function qiuzhu_init() {

  makeUI(taskList);

  $('#qz_btnQZ1').on('click', function () {

    $.ajax({
      url: '/yeweihui/qiuzhu/list.json',
      type: 'post',
      data: {
        houseNumber: $('#qz_searchNum1').val(),
        status: 1
      },
      success: function (data) {
        makeList1(data.data);
      },
      error: function () {
        $.alert("网络异常");
      }
    });

  });

  $('#qz_btnQZ2').on('click', function () {

    $.ajax({
      url: '/yeweihui/qiuzhu/list.json',
      type: 'post',
      data: {
        houseNumber: $('#qz_searchNum2').val(),
        status: 2
      },
      success: function (data) {
        makeList2(data.data);
      },
      error: function () {
        $.alert("网络异常");
      }
    });

  });

  $('#qz_btnQZ3').on('click', function () {
    $.ajax({
      url: '/yeweihui/qiuzhu/list.json',
      type: 'post',
      data: {
        houseNumber: $('#qz_searchNum3').val(),
        status: 3
      },
      success: function (data) {
        makeList3(data.data);
      },
      error: function () {
        $.alert("网络异常");
      }
    });
  });
}

function makeUI(tasks) {

  let tasks1 = [];
  let tasks2 = [];
  let tasks3 = [];

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

    let task = tasks[i];

    if (task.taskStatus == 1) {
      tasks1.push(task);
    }
    else if (task.taskStatus == 2) {
      tasks2.push(task);
    }
    else if (task.taskStatus == 3) {
      tasks3.push(task);
    }
  }

  makeList1(tasks1);
  makeList2(tasks2);
  makeList3(tasks3);
}

function makeList1(tasks) {

  $('#qz_list1').empty();
  if (tasks.length <= 0) {
    $('#qz_list1').append('<div class="weui-loadmore weui-loadmore_line">\n' +
        '    <span class="weui-loadmore__tips">暂无数据</span>\n' +
        '</div>');
  }
  for (let i = 0; i < tasks.length; i++) {
    let task = tasks[i];
    $('#qz_list1').append($('<a href="javascript:itemSelect(' + task.taskId + ');" class="weui-media-box weui-media-box_appmsg">\n' +
        '                            <div class="weui-media-box__bd">\n' +
        '                                <div style="display: flex; flex-direction: row; justify-content: space-between;">\n' +
        '                                    <p class="weui-media-box__desc">' + task.houseNumber + '</p>\n' +
        '                                    <p class="weui-media-box__desc">' + '2020-02-02 14:30' + '</p>\n' +
        '                                </div>\n' +
        '                                <h4 class="weui-media-box__title">' + task.taskTitle + '</h4>\n' +
        '                                <p class="weui-media-box__desc">' + task.remark + '</p>\n' +
        '                            </div>\n' +
        '                        </a>'));
  }
}

function makeList2(tasks) {

  $('#qz_list2').empty();
  if (tasks.length <= 0) {
    $('#qz_list2').append('<div class="weui-loadmore weui-loadmore_line">\n' +
        '    <span class="weui-loadmore__tips">暂无数据</span>\n' +
        '</div>');
  }
  for (let i = 0; i < tasks.length; i++) {
    let task = tasks[i];
    $('#qz_list2').append($('<a href="javascript:itemSelect(' + task.taskId + ');" class="weui-media-box weui-media-box_appmsg">\n' +
        '                            <div class="weui-media-box__bd">\n' +
        '                                <div style="display: flex; flex-direction: row; justify-content: space-between;">\n' +
        '                                    <p class="weui-media-box__desc">' + task.houseNumber + '</p>\n' +
        '                                    <p class="weui-media-box__desc">' + '2020-02-02 14:30' + '</p>\n' +
        '                                </div>\n' +
        '                                <h4 class="weui-media-box__title">' + task.taskTitle + '</h4>\n' +
        '                                <p class="weui-media-box__desc">' + task.remark + '</p>\n' +
        '                            </div>\n' +
        '                        </a>'));
  }
}

function makeList3(tasks) {

  $('#qz_list3').empty();
  if (tasks.length <= 0) {
    $('#qz_list3').append('<div class="weui-loadmore weui-loadmore_line">\n' +
        '    <span class="weui-loadmore__tips">暂无数据</span>\n' +
        '</div>');
  }
  for (let i = 0; i < tasks.length; i++) {
    let task = tasks[i];
    $('#qz_list3').append($('<a href="javascript:itemSelect(' + task.taskId + ');" class="weui-media-box weui-media-box_appmsg">\n' +
        '                            <div class="weui-media-box__bd">\n' +
        '                                <div style="display: flex; flex-direction: row; justify-content: space-between;">\n' +
        '                                    <p class="weui-media-box__desc">' + task.houseNumber + '</p>\n' +
        '                                    <p class="weui-media-box__desc">' + '2020-02-02 14:30' + '</p>\n' +
        '                                </div>\n' +
        '                                <h4 class="weui-media-box__title">' + task.taskTitle + '</h4>\n' +
        '                                <p class="weui-media-box__desc">' + task.remark + '</p>\n' +
        '                            </div>\n' +
        '                        </a>'));
  }
}

function itemSelect(taskId) {
  window.location.href = "/yeweihui/qiuzhudetail.html?taskId=" + taskId;
}
