order-list.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. //获取团队信息
  2. var request = getRequest(),
  3. teamCode = request.id,
  4. isLeader = request.isLeader || true;
  5. //记录页面控件的值
  6. var startDate = '',
  7. endDate = '',
  8. state = '', //状态
  9. dispensaryType = '', //配送方式
  10. page = 1,
  11. size = 10,
  12. hospital = '', //服务站code
  13. allocationType, //是否是待分配续方
  14. nameKey, //搜索的姓名
  15. selectItemNum = 0, //选中的数量
  16. selectItem = [], //选中的订单号集合
  17. isArrange = false, // 判断所选的订单是否是可分配的
  18. totalOrderCount = 0,
  19. totalHealthDoctorCount = 0,
  20. selectDoctor; //选中的医生
  21. $(function(){
  22. //非团队长隐藏操作按钮
  23. if(!isLeader || isLeader == 'false'){
  24. $("#arrange").hide();
  25. }
  26. //填充下拉框数据
  27. orderAPI.getFilterInfo().then(function(res){
  28. fillDropDown(res);
  29. //获得续方订单列表
  30. getPrescriptionList();
  31. });
  32. //获得服务站数据
  33. orderAPI.getHospitalList({data: {teamCode: teamCode}}).then(function(res){
  34. var html = template('address_tmpl', {list: res.data});
  35. $("#address").empty().append(html);
  36. });
  37. bindEvents();
  38. });
  39. //获得续方订单列表
  40. function getPrescriptionList( refresh){
  41. var params = {
  42. teamCode: teamCode,
  43. startDate: startDate,
  44. endDate: endDate,
  45. state: state,
  46. dispensaryType: dispensaryType,
  47. hospital: hospital,
  48. allocationType: allocationType,
  49. nameKey: nameKey
  50. };
  51. //先请求获得所有的数量
  52. orderAPI.getOrderListCount({data:params}).then(function(res){
  53. if(res.status == 200){
  54. totalOrderCount = res.data.total;
  55. if(refresh){
  56. $("#prescriptTable").bootstrapTable('refresh');
  57. }
  58. var options = $.extend(orderAPI.getOrderListTableAjaxObj, {
  59. queryParams: queryParams,
  60. queryParamsType: "limit",
  61. pagination: true,
  62. paginationLoop: true,
  63. sidePagination: 'server',
  64. pageNumber: 1,
  65. pageSize: 10,
  66. responseHandler: function (res) {
  67. var data = _.map(res.data, function(o){
  68. var result = "";
  69. for(var i=0; i<o.prescriptionDt.length; i++){
  70. if(i>0){
  71. result += ','+o.prescriptionDt[i].name;
  72. }else{
  73. result += o.prescriptionDt[i].name;
  74. }
  75. }
  76. o.result = result;
  77. o.statusName = getStatusName(o.status);
  78. o.express = getExpressName(o.dispensaryType);
  79. var address = "",
  80. expressage = "";
  81. if(o.dispensaryType == 2){
  82. expressage = o.expressageHospitalName;
  83. address = o.provinceName + o.cityName + o.townName + o.address;
  84. }else if(o.dispensaryType == 3){
  85. address = o.patientHospitalName;
  86. expressage = o.expressageName;
  87. }
  88. o.expressage = expressage;
  89. o.address = address;
  90. o.action = '<a class="c-12b7f5" href="prescription-main.html?code='+o.code+'&patiCode='+o.patientCode+'&teamCode='+teamCode+'&tab=2">查看</a>';
  91. o.checkbox = '<input name="orderItem" type="checkbox" class="icon-checkbox" data-status="'+o.status+'" data-type="'+o.dispensaryType+'" data-expressage="'+o.expressageCode+'" data-code="'+o.code+'">';
  92. return o;
  93. });
  94. return {
  95. rows: data,
  96. total: totalOrderCount
  97. }
  98. }
  99. })
  100. $("#prescriptTable").bootstrapTable(options);
  101. }
  102. });
  103. }
  104. function queryParams(params) {
  105. //当表格数据变化的时候,则取消全选按钮,然后之前的选中的信息将取消选中
  106. page = params.offset/params.limit + 1;
  107. selectItemNum = 0;
  108. $("#selectAll").prop("checked", false);
  109. $("#selectedCount").text(0);
  110. $("#arrange").addClass("disabled");
  111. return {
  112. teamCode: teamCode,
  113. page: params.offset/params.limit + 1,
  114. size: params.limit,
  115. startDate: startDate,
  116. endDate: endDate,
  117. state: state,
  118. dispensaryType: dispensaryType,
  119. hospital: hospital,
  120. allocationType: allocationType,
  121. nameKey: nameKey
  122. };
  123. }
  124. //获得健管师列表
  125. function getHealthDoctorList(isRefresh){
  126. if(isRefresh){
  127. $("#hDoctor").bootstrapTable('refresh');
  128. }
  129. var options = $.extend(orderAPI.getHealthDoctorTableAjaxObj, {
  130. queryParams: queryParams2,
  131. queryParamsType: "limit",
  132. pagination: true,
  133. paginationLoop: true,
  134. sidePagination: 'server',
  135. pageNumber: 1,
  136. pageSize: 8,
  137. pageList: [5,8,10],
  138. responseHandler: function (res) {
  139. return {
  140. rows: res.data.doctors,
  141. total: res.data.total
  142. }
  143. },
  144. columns: [{
  145. field: 'photo',
  146. title: '',
  147. width: '50',
  148. formatter: function(val, row, index){
  149. var url = "img/d-male.png";
  150. if(val.indexOf("http")>-1 || val.indexOf("https")>-1){
  151. url = val;
  152. }
  153. return '<img src="'+url+'" class="img-circle" width="40">';
  154. }
  155. }, {
  156. field: 'name',
  157. title: '',
  158. align: 'left'
  159. },{
  160. field: 'jobName',
  161. title: '职称',
  162. align: 'right'
  163. }],
  164. onClickRow: function(row, $el){
  165. $("#orderCount").text(selectItemNum);
  166. var jobName = '';
  167. if(row.jobName){
  168. jobName = row.jobName;
  169. }
  170. $("#docInfo").text(row.name+jobName);
  171. $("#confirmModal").modal('toggle');
  172. selectDoctor = row.code;
  173. }
  174. });
  175. $("#hDoctor").bootstrapTable(options);
  176. }
  177. function queryParams2(params) {
  178. console.log(params);
  179. //当表格数据变化的时候,则取消全选按钮,然后之前的选中的信息将取消选中
  180. return {
  181. page: params.offset/params.limit + 1,
  182. size: params.limit,
  183. name: $.trim($("#doctorName").val())
  184. };
  185. }
  186. function fillDropDown(res){
  187. if(res.status == 200){
  188. var stateHtml = template('state_tmpl', {list: res.data.states});
  189. $("#orderStatus").append(stateHtml);
  190. var expressHtml = template('express_tmpl', {list: res.data.dispensaryTypes});
  191. $("#express").append(expressHtml);
  192. }else{
  193. }
  194. }
  195. //绑定事件
  196. function bindEvents(){
  197. $(".n-tab").on('click', function(){
  198. if($(this).hasClass("active")){
  199. return false;
  200. }else{
  201. $(this).addClass("active");
  202. $(this).siblings().removeClass("active");
  203. var seDate = getStartEndDate($(this).attr("data-val"));
  204. startDate = seDate.startDate;
  205. endDate = seDate.endDate;
  206. getPrescriptionList(true);
  207. }
  208. });
  209. $("#orderStatus").on('change', function(){
  210. var $this = $(this);
  211. state = $this.val();
  212. getPrescriptionList(true);
  213. });
  214. $("#express").on('change', function(){
  215. dispensaryType = $(this).val();
  216. if(dispensaryType == 3){ //健管师配送时,显示复选框
  217. $("#checkboxBox").removeClass("hidden");
  218. }else{
  219. $("#checkboxBox").addClass("hidden");
  220. $("#allocationType").prop("checked", false);
  221. allocationType = 0;
  222. }
  223. getPrescriptionList(true);
  224. });
  225. $("#address").on('change', function(){
  226. hospital = $(this).val();
  227. getPrescriptionList(true);
  228. });
  229. $("#allocationType").on('change', function(){
  230. var $this = $(this);
  231. if($this.prop('checked')){
  232. allocationType = 1;
  233. }else{
  234. allocationType = 0;
  235. }
  236. getPrescriptionList(true);
  237. });
  238. $("#searchBtn").on('click', function(){
  239. var $input = $("#searchName"),
  240. text = $.trim($input.val());
  241. nameKey = text;
  242. getPrescriptionList(true);
  243. });
  244. $("#selectAll").on('click', function(){
  245. var $this = $(this),
  246. $checkbox = $("input[name=orderItem]"),
  247. length = $checkbox.length;
  248. if($this.prop("checked")){
  249. $checkbox.prop("checked", true);
  250. selectItemNum = length;
  251. $("#selectedCount").text(selectItemNum);
  252. }else{
  253. $checkbox.prop("checked", false);
  254. selectItemNum = 0;
  255. $("#selectedCount").text(0);
  256. }
  257. checkArrangeDisable('all');
  258. });
  259. $("body").on('click', "input[name=orderItem]", function(){
  260. var $this = $(this),
  261. status = $this.data('status'),
  262. type = $this.data('type'),
  263. expressage = $this.data('expressage'),
  264. code = $this.data('code');
  265. if($this.prop("checked")){
  266. selectItemNum ++;
  267. if((type == 3) && (status >= 50) && (expressage=='' || !expressage)){
  268. selectItem.push(code);
  269. }
  270. }else{
  271. selectItemNum --;
  272. if(selectItem.indexOf(code) > -1){
  273. var index = selectItem.indexOf(code);
  274. selectItem.splice(index,1);
  275. }
  276. }
  277. $("#selectedCount").text(selectItemNum);
  278. checkArrangeDisable();
  279. });
  280. $("#arrange").on('click', function(){
  281. if($(this).hasClass("disabled")){
  282. return false;
  283. }
  284. $('#myModal').modal('toggle');
  285. getHealthDoctorList();
  286. });
  287. $("#doctorName").on('keyup', function(e){
  288. if (e.which === 13) {
  289. getHealthDoctorList(true);
  290. }
  291. });
  292. $("#confirmBtn").on('click', function(){
  293. //发送请求确认的请求
  294. var params = {
  295. codes: selectItem.join(","),
  296. healthDoctor: selectDoctor
  297. }
  298. orderAPI.distributeHealthDoctor({data: params}).then(function(res){
  299. if(res.status == 200){
  300. $('#myModal').modal('toggle');
  301. $('#confirmModal').modal('toggle');
  302. $("#prescriptTable").bootstrapTable('refresh');
  303. }else{
  304. }
  305. })
  306. });
  307. }
  308. //判断选中的订单是否是可分配的的订单
  309. function checkArrangeDisable(clickType){ //type=all 为点击全选时处理
  310. //可以分配的条件,1是健管师配送订单,2状态为待分配
  311. var $checkbox = $("input[name=orderItem]:checked"),
  312. len = $checkbox.length;
  313. isArrange = false;
  314. if(clickType == 'all'){
  315. selectItem = [];
  316. }
  317. for(var i=0; i<len; i++){
  318. var $item = $($checkbox[i]),
  319. status = $item.data('status'),
  320. type = $item.data('type'),
  321. expressage = $item.data('expressage'),
  322. code = $item.data('code');
  323. if(type != 3){
  324. isArrange = false;
  325. break;
  326. }else{
  327. if((status >= 50) && (expressage=='' || !expressage)){ //支付成功后状态+配送员的名字为空为待分配状态
  328. isArrange = true;
  329. if(clickType == 'all'){
  330. selectItem.push(code);
  331. }
  332. }else{
  333. isArrange = false;
  334. break;
  335. }
  336. }
  337. }
  338. if(!isArrange){
  339. $("#arrange").addClass("disabled");
  340. }else{
  341. $("#arrange").removeClass("disabled");
  342. }
  343. }