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) {

  var tasks1 = [];
  var tasks2 = [];
  var tasks3 = [];

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

    var 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 == undefined || tasks.length <= 0) {
    $('#qz_list1').append('<div class="weui-loadmore weui-loadmore_line">\n' +
        '    <span class="weui-loadmore__tips">暂无数据</span>\n' +
        '</div>');
    return;
  }
  for (var i = 0; i < tasks.length; i++) {
    var task = tasks[i];
    $('#qz_list1').append($('<a onclick="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 == undefined || tasks.length <= 0) {
    $('#qz_list2').append('<div class="weui-loadmore weui-loadmore_line">\n' +
        '    <span class="weui-loadmore__tips">暂无数据</span>\n' +
        '</div>');
    return;
  }
  for (var i = 0; i < tasks.length; i++) {
    var task = tasks[i];
    $('#qz_list2').append($('<a onclick="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 == undefined || tasks.length <= 0) {
    $('#qz_list3').append('<div class="weui-loadmore weui-loadmore_line">\n' +
        '    <span class="weui-loadmore__tips">暂无数据</span>\n' +
        '</div>');
    return;
  }
  for (var i = 0; i < tasks.length; i++) {
    var task = tasks[i];
    let taskid = task.taskId + '';
    $('#qz_list3').append($('<a onclick="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 + "&userId=" + $('#userId').val();
}
