123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731 |
- layui.define(['tool'], function (exports) {
- const layer = layui.layer, tool = layui.tool, form = layui.form, table = layui.table, upload = layui.upload;
- // 查找指定的元素在数组中的位置
- Array.prototype.indexOf = function (val) {
- for (var i = 0; i < this.length; i++) {
- if (this[i] == val) {
- return i;
- }
- }
- return -1;
- };
- // 通过索引删除数组元素
- Array.prototype.remove = function (val) {
- var index = this.indexOf(val);
- if (index > -1) {
- this.splice(index, 1);
- }
- };
- //格式化文件大小
- function renderSize(value) {
- if (null == value || value == '') {
- return "0 Bytes";
- }
- var unitArr = new Array("Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
- var index = 0;
- var srcsize = parseFloat(value);
- index = Math.floor(Math.log(srcsize) / Math.log(1024));
- var size = srcsize / Math.pow(1024, index);
- size = size.toFixed(2);//保留的小数位数
- return size + unitArr[index];
- }
- const obj = {
- addFile: function (options) {
- console.log(options)
- let that = this;
- let settings = {
- type: 0,
- btn: 'uploadBtn',
- box: 'fileBox',
- url: "/admin/api/upload",
- accept: 'file', //普通文件
- exts: 'png|jpg|gif|jpeg|doc|docx|ppt|pptx|xls|xlsx|pdf|zip|rar|7z|txt|wps|avi|wmv|mpg|mov|rm|swf|flv|mp4|dwg|dxf|dwt|xmind', //只允许上传文件格式
- colmd: 4,
- isSave: false,
- uidDelete: false,
- ajaxSave: null,
- ajaxDelete: null
- };
- console.log(123123)
- let opts = $.extend({}, settings, options);
- let box = $('#' + opts.box);
- let boxInput = box.find('[data-type="file"]');
- console.log("wozaizheliyo")
- //删除
- box.on('click', '.btn-delete', function () {
- // let file_id = $(this).data('id');
- let file_id = $(this).parent().parent().data('id');
- let uid = $(this).data('uid');
- // if (uid != login_admin && opts.uidDelete == true) {
- // layer.msg('你不是该文件的上传人,无权限删除');
- // return false;
- // }
- let idsStr = boxInput.val(), idsArray = [];
- if (typeof idsStr !== 'undefined' && idsStr != '') {
- idsArray = idsStr.split(",");
- idsArray.remove(file_id);
- }
- layer.confirm('确定删除该附件吗?', {
- icon: 3,
- title: '提示'
- }, function (index) {
- if (typeof (opts.ajaxDelete) === "function") {
- //ajax删除
- if (opts.type == 1) {
- opts.ajaxDelete(file_id);
- } else {
- opts.ajaxDelete(idsArray.join(','));
- }
- } else {
- //虚拟删除
- boxInput.val(idsArray.join(','));
- $('#fileItem' + file_id).remove();
- }
- layer.close(index);
- });
- })
- //多附件上传
- upload.render({
- elem: '#' + opts.btn,
- url: opts.url,
- accept: opts.accept,
- exts: opts.exts,
- multiple: true,
- before: function (obj) {
- layer.msg('上传中...', {icon: 16, time: 0});
- },
- done: function (res) {
- if (res.code == 0) {
- //上传成功
- if (opts.type == 0) {
- let idsStr = boxInput.val(), idsArray = [];
- if (typeof idsStr !== 'undefined' && idsStr != '') {
- idsArray = idsStr.split(",");
- }
- idsArray.push(res.data.id);
- let filesize = renderSize(res.data.filesize);
- let type_icon = 'icon-sucaiziyuan';
- let view_btn = '<a class="blue" href="' + res.data.filepath + '" download="' + res.data.name + '" target="_blank" title="下载查看"><i class="iconfont icon-tuiguangshezhi"></i></a>';
- if (res.data.fileext == 'pdf') {
- type_icon = 'icon-lunwenguanli';
- view_btn = '<span class="file-view-pdf blue" data-href="' + res.data.filepath + '" title="在线查看"><i class="iconfont icon-yuejuan"></i></span>';
- }
- if (res.data.fileext == 'jpg' || res.data.fileext == 'jpeg' || res.data.fileext == 'png' || res.data.fileext == 'gif') {
- type_icon = 'icon-sucaiguanli';
- view_btn = '<span class="file-view-img blue" data-href="' + res.data.filepath + '" title="在线查看"><i class="iconfont icon-tupianguanli"></i></span>';
- }
- let temp = `<div class="layui-col-md${opts.colmd}" id="fileItem${res.data.id}">
- <div class="file-card">
- <i class="file-icon iconfont ${type_icon}"></i>
- <div class="file-info">
- <div class="file-title">${res.data.name}</div>
- <div class="file-ops">${filesize},一分钟前</div>
- </div>
- <div class="file-tool">${view_btn}<span class="btn-delete red" data-id="${res.data.id}" title="删除"><i class="iconfont icon-shanchu"></i></span></div>
- </div>
- </div>`;
- boxInput.val(idsArray.join(','));
- box.append(temp);
- if (typeof (opts.ajaxSave) === "function" && opts.isSave == true) {
- opts.ajaxSave(idsArray.join(','));
- } else {
- layer.msg(res.msg);
- }
- }
- if (opts.type == 1) {
- if (typeof (opts.ajaxSave) === "function" && opts.isSave == true) {
- opts.ajaxSave(res);
- }
- }
- } else {
- layer.msg(res.msg);
- }
- }
- });
- },
- //选择部门
- departmentPicker: function (type, callback) {
- let select_type = type == 1 ? 'radio' : 'checkbox', departmentTable;
- layer.open({
- type: 1,
- title: '选择部门',
- area: ['500px', '536px'],
- content: `<div style="width:468px; height:420px; padding:12px;">
- <div id="departmentBox"></div>
- </div>`,
- success: function () {
- departmentTable = table.render({
- elem: '#departmentBox'
- , url: "/api/index/get_department"
- , page: false //开启分页
- , cols: [[
- {type: select_type, title: '选择'}
- , {field: 'id', width: 80, title: '编号', align: 'center'}
- , {field: 'title', title: '部门名称'}
- ]]
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(departmentTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data);
- layer.closeAll();
- } else {
- layer.msg('请选择部门');
- return;
- }
- }
- })
- },
- //选择岗位
- positionPicker: function (type, callback) {
- let select_type = type == 1 ? 'radio' : 'checkbox', positionTable;
- layer.open({
- title: '选择岗位',
- type: 1,
- area: ['390px', '436px'],
- content: '<div style="padding:12px"><div id="positionBox"></div></div>',
- success: function () {
- positionTable = table.render({
- elem: '#positionBox'
- , url: "/api/index/get_position"
- , page: false //开启分页
- , cols: [[
- {type: select_type, title: '选择'}
- , {field: 'id', width: 80, title: '编号', align: 'center'}
- , {field: 'name', title: '岗位名称'}
- ]]
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(positionTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data);
- layer.closeAll();
- } else {
- layer.msg('请选择岗位');
- return;
- }
- }
- })
- },
- //选择服务类型
- servicePicker: function (type, callback) {
- let select_type = type == 1 ? 'radio' : 'checkbox', departmentTable;
- var serviceTable;
- layer.open({
- title: '选择服务类型',
- area: ['500px', '536px'],
- type: 1,
- content: '<div class="picker-table"><div id="serviceTable"></div></div>',
- success: function () {
- serviceTable = table.render({
- elem: '#serviceTable'
- , url: '/api/index/get_services'
- , page: false
- , cols: [[
- {type: select_type, title: '选择'}
- , {field: 'id', width: 100, title: '编号', align: 'center'}
- , {field: 'title', title: '服务名称'}
- ]]
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(serviceTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data);
- layer.closeAll();
- } else {
- layer.msg('请选择服务类型');
- return;
- }
- }
- })
- },
- //选择委托单位
- customerPicker: function (callback) {
- var customeTable;
- layer.open({
- title: '选择委托单位',
- area: ['600px', '580px'],
- type: 1,
- content: '<div class="picker-table">\
- <form class="layui-form pb-2">\
- <div class="layui-input-inline" style="width:480px;">\
- <input type="text" name="keywords" placeholder="委托单位" class="layui-input" autocomplete="off" />\
- </div>\
- <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="search_customer">提交搜索</button>\
- </form>\
- <div id="customerTable"></div></div>',
- success: function () {
- customeTable = table.render({
- elem: '#customerTable'
- , url: '/admin/project.cost/get_customer'
- , page: true //开启分页
- , limit: 10
- , cols: [[
- {type: 'radio', title: '选择'},
- {field: 'id', width: 80, title: '编号', align: 'center'},
- {field: 'title', title: '评审单位名称', align: 'center'},
- {field: 'nickname', title: '评审单位负责人', align: 'center'},
- {field: 'mobile', title: '评审单位负责人电话', align: 'center'},
- {field: 'address', title: ' 评审单位地址', align: 'center'}
- ]]
- });
- //客户搜索提交
- form.on('submit(search_customer)', function (data) {
- customeTable.reload({where: {keywords: data.field.keywords}, page: {curr: 1}});
- return false;
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(customeTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data[0]);
- layer.closeAll();
- } else {
- layer.msg('请先选择评审单位');
- return false;
- }
- }
- })
- },
- //选择送审单位
- proprietorPicker : function (callback) {
- var proprietorTable;
- layer.open({
- title: '选择送审单位',
- area: ['600px', '580px'],
- type: 1,
- content: '<div class="picker-table">\
- <form class="layui-form pb-2">\
- <div class="layui-input-inline" style="width:480px;">\
- <input type="text" name="keywords" placeholder="送审单位" class="layui-input" autocomplete="off" />\
- </div>\
- <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="search_customer">提交搜索</button>\
- </form>\
- <div id="customerTable"></div></div>',
- success: function () {
- proprietorTable = table.render({
- elem: '#customerTable'
- , url: '/admin/project.cost/get_proprietor_list'
- , page: true //开启分页
- , limit: 10
- , cols: [[
- {type: 'radio', title: '选择'},
- {field: 'id', width: 80, title: '编号', align: 'center'},
- {field: 'title', title: '送审单位名称', align: 'center'},
- {field: 'nickname', title: '送审单位负责人', align: 'center'},
- {field: 'mobile', title: '送审单位负责人电话', align: 'center'},
- {field: 'address', title: '送审单位地址', align: 'center'}
- ]]
- });
- //客户搜索提交
- form.on('submit(search_customer)', function (data) {
- proprietorTable.reload({where: {keywords: data.field.keywords}, page: {curr: 1}});
- return false;
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(proprietorTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data[0]);
- layer.closeAll();
- } else {
- layer.msg('请先选择送审单位');
- return false;
- }
- }
- })
- },
- //请款选择造价项目
- ProjectPicker: function (callback) {
- var projectTable;
- layer.open({
- title: '选择造价项目',
- area: ['600px', '580px'],
- type: 1,
- content: '<div class="picker-table">\
- <form class="layui-form pb-2">\
- <div class="layui-input-inline" style="width:480px;">\
- <input type="text" name="keywords" placeholder="造价项目" class="layui-input" autocomplete="off" />\
- </div>\
- <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="search_customer">提交搜索</button>\
- </form>\
- <div id="customerTable"></div></div>',
- success: function () {
- projectTable = table.render({
- elem: '#customerTable'
- , url: '/admin/project.api/get_project'
- , page: true //开启分页
- , limit: 10
- , cols: [[
- {type: 'radio', title: '选择'},
- {field: 'id', width: 80, title: '编号', align: 'center'},
- {field: 'project_name', title: '项目名称', align: 'center'},
- {field: 'sent_review_cost', title: '送审服务费', align: 'center'},
- {field: 'entrust_unit_name', title: '委托单位', align: 'center'},
- ]]
- });
- //客户搜索提交
- form.on('submit(search_customer)', function (data) {
- projectTable.reload({where: {keywords: data.field.keywords}, page: {curr: 1}});
- return false;
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(projectTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data[0]);
- layer.closeAll();
- } else {
- layer.msg('请先选择项目');
- return false;
- }
- }
- })
- },
- //选择造价项目
- addProject: function (callback) {
- var projectTable;
- layer.open({
- title: '选择造价项目',
- area: ['600px', '580px'],
- type: 1,
- content: '<div class="picker-table">\
- <form class="layui-form pb-2">\
- <div class="layui-input-inline" style="width:480px;">\
- <input type="text" name="keywords" placeholder="造价项目" class="layui-input" autocomplete="off" />\
- </div>\
- <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="search_customer">提交搜索</button>\
- </form>\
- <div id="customerTable"></div></div>',
- success: function () {
- projectTable = table.render({
- elem: '#customerTable'
- , url: '/admin/project.api/get_self_project'
- , page: true //开启分页
- , limit: 10
- , cols: [[
- {type: 'radio', title: '选择'},
- {field: 'id', width: 80, title: '编号', align: 'center'},
- {field: 'project_name', title: '项目名称', align: 'center'},
- {field: 'entrust_unit_name', title: '委托单位', align: 'center'},
- {field: 'review_unit_name', title: '评审单位', align: 'center'},
- ]]
- });
- //客户搜索提交
- form.on('submit(search_customer)', function (data) {
- projectTable.reload({where: {keywords: data.field.keywords}, page: {curr: 1}});
- return false;
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(projectTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data[0]);
- layer.closeAll();
- } else {
- layer.msg('请先选择项目');
- return false;
- }
- }
- })
- },
- //选择合同
- contractPicker: function (callback) {
- var contractTable;
- layer.open({
- title: '选择合同',
- area: ['720px', '580px'],
- type: 1,
- content: '<div class="picker-table">\
- <form class="layui-form pb-2">\
- <div class="layui-input-inline" style="width:600px;">\
- <input type="text" name="keywords" placeholder="合同名称" class="layui-input" autocomplete="off" />\
- </div>\
- <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="search_contract">提交搜索</button>\
- </form>\
- <div id="contractTable"></div></div>',
- success: function () {
- contractTable = table.render({
- elem: '#contractTable'
- , url: '/contract/api/get_contract'
- , page: true //开启分页
- , limit: 10
- , cols: [[
- {type: 'radio', title: '选择'}
- , {field: 'code', width: 168, title: '合同编号', align: 'center'}
- , {field: 'name', title: '合同名称'}
- , {field: 'customer_name', title: '客户名称', width: 240}
- ]]
- });
- //合同搜索提交
- form.on('submit(search_contract)', function (data) {
- contractTable.reload({where: {keywords: data.field.keywords}, page: {curr: 1}});
- return false;
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(contractTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data[0]);
- layer.closeAll();
- } else {
- layer.msg('请先选择合同');
- return false;
- }
- }
- })
- },
- //选择项目
- // projectPicker: function (callback) {
- // var projectTable;
- // let projectLayer = layer.open({
- // title: '选择项目',
- // area: ['600px', '580px'],
- // type: 1,
- // content: '<div class="picker-table">\
- // <form class="layui-form pb-2">\
- // <div class="layui-input-inline" style="width:480px;">\
- // <input type="text" name="keywords" placeholder="项目名称" class="layui-input" autocomplete="off" />\
- // </div>\
- // <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="search_project">提交搜索</button>\
- // </form>\
- // <div id="projectTable"></div></div>',
- // success: function () {
- // projectTable = table.render({
- // elem: '#projectTable'
- // , url: '/project/api/get_project'
- // , page: true //开启分页
- // , limit: 10
- // , cols: [[
- // {type: 'radio', title: '选择'}
- // , {field: 'id', width: 100, title: '编号', align: 'center'}
- // , {field: 'title', title: '项目名称'}
- // ]]
- // });
- // //合同搜索提交
- // form.on('submit(search_project)', function (data) {
- // projectTable.reload({where: {keywords: data.field.keywords}, page: {curr: 1}});
- // return false;
- // });
- // },
- // btn: ['确定'],
- // btnAlign: 'c',
- // yes: function () {
- // var checkStatus = table.checkStatus(projectTable.config.id);
- // var data = checkStatus.data;
- // if (data.length > 0) {
- // callback(data[0]);
- // layer.close(projectLayer);
- // } else {
- // layer.msg('请先选择项目');
- // return false;
- // }
- // }
- // })
- // },
- //选择任务
- getEntrust: function (callback) {
- var entrustTable;
- let taskLayer = layer.open({
- title: '选择委托单位',
- area: ['600px', '580px'],
- type: 1,
- content: '<div class="picker-table">\
- <form class="layui-form pb-2">\
- <div class="layui-input-inline" style="width:480px;">\
- <input type="text" name="keywords" placeholder="委托单位" class="layui-input" autocomplete="off" />\
- </div>\
- <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="entrustSearch">提交搜索</button>\
- </form>\
- <div id="entrustTable"></div></div>',
- success: function () {
- entrustTable = table.render({
- elem: '#entrustTable'
- , url: '/admin/project.api/get_entrust'
- , page: true //开启分页
- , limit: 10
- , cols: [[
- {type: 'radio', title: '选择'},
- {field: 'id', width: 80, title: '编号', align: 'center'},
- {field: 'title', title: '评审单位名称', align: 'center'},
- {field: 'nickname', title: '评审单位负责人', align: 'center'},
- {field: 'mobile', title: '评审单位负责人电话', align: 'center'},
- {field: 'address', title: ' 评审单位地址', align: 'center'}
- ]]
- });
- //合同搜索提交
- form.on('submit(entrustSearch)', function (data) {
- entrustTable.reload({where: {keywords: data.field.keywords}, page: {curr: 1}});
- return false;
- });
- },
- btn: ['确定'],
- btnAlign: 'c',
- yes: function () {
- var checkStatus = table.checkStatus(entrustTable.config.id);
- var data = checkStatus.data;
- if (data.length > 0) {
- callback(data[0]);
- layer.close(taskLayer);
- } else {
- layer.msg('请先选择任务主题');
- return false;
- }
- }
- })
- }
- };
- //选择部门
- $('body').on('click', '.picker-depament', function () {
- let that = $(this);
- let callback = function (data) {
- that.val(data[0].title);
- that.next().val(data[0].id);
- }
- obj.departmentPicker(1, callback);
- });
- $('body').on('click', '.picker-depaments', function () {
- let that = $(this), ids = [], names = [];
- let callback = function (data) {
- for (var i = 0; i < data.length; i++) {
- ids.push(data[i].id);
- names.push(data[i].title);
- }
- that.val(names.join(','));
- that.next().val(ids.join(','));
- }
- obj.departmentPicker(2, callback);
- });
- //选择岗位
- $('body').on('click', '.picker-position', function () {
- let that = $(this);
- let callback = function (data) {
- that.val(data[0].name);
- that.next().val(data[0].id);
- }
- obj.positionPicker(1, callback);
- });
- $('body').on('click', '.picker-positions', function () {
- let that = $(this), ids = [], names = [];
- let callback = function (data) {
- for (var i = 0; i < data.length; i++) {
- ids.push(data[i].id);
- names.push(data[i].name);
- }
- that.val(names.join(','));
- that.next().val(ids.join(','));
- }
- obj.positionPicker(2, callback);
- });
- //选择服务
- $('body').on('click', '.picker-service', function () {
- let that = $(this);
- let callback = function (data) {
- that.val(data[0].title);
- that.next().val(data[0].id);
- }
- obj.servicePicker(1, callback);
- });
- $('body').on('click', '.picker-services', function () {
- let that = $(this), ids = [], names = [];
- let callback = function (data) {
- for (var i = 0; i < data.length; i++) {
- ids.push(data[i].id);
- names.push(data[i].title);
- }
- that.val(names.join(','));
- that.next().val(ids.join(','));
- }
- obj.servicePicker(2, callback);
- });
- //选择客户
- $('body').on('click', '.picker-customer', function () {
- let that = $(this);
- let callback = function (data) {
- that.val(data.name);
- that.next().val(data.id);
- }
- obj.customerPicker(callback);
- });
- //选择合同
- $('body').on('click', '.picker-contract', function () {
- let that = $(this);
- let callback = function (data) {
- that.val(data.name);
- that.next().val(data.id);
- }
- obj.contractPicker(callback);
- });
- //选择项目
- $('body').on('click', '.picker-project', function () {
- let that = $(this);
- let callback = function (data) {
- that.val(data.title);
- that.next().val(data.id);
- }
- obj.projectPicker(callback);
- });
- exports('oaTool', obj);
- });
|