order-list.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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){
  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. if(o.dispensaryType == 2){
  81. address = o.patientHospitalAddress;
  82. o.expressageName = o.expressageHospitalName;
  83. }else{
  84. address = o.expressageHospitalName;
  85. }
  86. o.address = address;
  87. o.action = '<a class="c-12b7f5" href="prescription-main.html?code='+o.code+'&patiCode='+o.patientCode+'&teamCode='+teamCode+'&tab=2">查看</a>';
  88. 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+'">';
  89. return o;
  90. });
  91. return {
  92. rows: data,
  93. total: totalOrderCount
  94. }
  95. }
  96. })
  97. $("#prescriptTable").bootstrapTable(options);
  98. }
  99. });
  100. }
  101. function queryParams(params) {
  102. console.log(params);
  103. //当表格数据变化的时候,则取消全选按钮,然后之前的选中的信息将取消选中
  104. page = params.offset/params.limit + 1;
  105. selectItemNum = 0;
  106. $("#selectAll").prop("checked", false);
  107. $("#selectedCount").text(0);
  108. $("#arrange").addClass("disabled");
  109. return {
  110. teamCode: teamCode,
  111. page: params.offset/params.limit + 1,
  112. size: params.limit,
  113. startDate: startDate,
  114. endDate: endDate,
  115. state: state,
  116. dispensaryType: dispensaryType,
  117. hospital: hospital,
  118. allocationType: allocationType,
  119. nameKey: nameKey
  120. };
  121. }
  122. //获得健管师列表
  123. function getHealthDoctorList(isRefresh){
  124. if(isRefresh){
  125. $("#hDoctor").bootstrapTable('refresh');
  126. }
  127. var options = $.extend(orderAPI.getHealthDoctorTableAjaxObj, {
  128. queryParams: queryParams2,
  129. queryParamsType: "limit",
  130. pagination: true,
  131. paginationLoop: true,
  132. sidePagination: 'server',
  133. pageNumber: 1,
  134. pageSize: 8,
  135. pageList: [5,8,10],
  136. responseHandler: function (res) {
  137. return {
  138. rows: res.data.doctors,
  139. total: res.data.total
  140. }
  141. },
  142. columns: [{
  143. field: 'photo',
  144. title: '',
  145. width: '50',
  146. formatter: function(val, row, index){
  147. var url = "img/d-male.png";
  148. if(val.indexOf("http")>-1 || val.indexOf("https")>-1){
  149. url = val;
  150. }
  151. return '<img src="'+url+'" class="img-circle" width="40">';
  152. }
  153. }, {
  154. field: 'name',
  155. title: '',
  156. align: 'left'
  157. },{
  158. field: 'jobName',
  159. title: '职称',
  160. align: 'right'
  161. }],
  162. onClickRow: function(row, $el){
  163. $("#orderCount").text(selectItemNum);
  164. $("#docInfo").text(row.name+row.jobName);
  165. $("#confirmModal").modal('toggle');
  166. selectDoctor = row.code;
  167. }
  168. });
  169. $("#hDoctor").bootstrapTable(options);
  170. }
  171. function queryParams2(params) {
  172. console.log(params);
  173. //当表格数据变化的时候,则取消全选按钮,然后之前的选中的信息将取消选中
  174. return {
  175. page: params.offset/params.limit + 1,
  176. size: params.limit,
  177. name: $.trim($("#doctorName").val())
  178. };
  179. }
  180. function fillDropDown(res){
  181. if(res.status == 200){
  182. var stateHtml = template('state_tmpl', {list: res.data.states});
  183. $("#orderStatus").append(stateHtml);
  184. var expressHtml = template('express_tmpl', {list: res.data.dispensaryTypes});
  185. $("#express").append(expressHtml);
  186. }else{
  187. }
  188. }
  189. //绑定事件
  190. function bindEvents(){
  191. $(".n-tab").on('click', function(){
  192. if($(this).hasClass("active")){
  193. return false;
  194. }else{
  195. $(this).addClass("active");
  196. $(this).siblings().removeClass("active");
  197. var seDate = getStartEndDate($(this).attr("data-val"));
  198. startDate = seDate.startDate;
  199. endDate = seDate.endDate;
  200. getPrescriptionList(true);
  201. }
  202. });
  203. $("#orderStatus").on('change', function(){
  204. var $this = $(this);
  205. state = $this.val();
  206. getPrescriptionList(true);
  207. });
  208. $("#express").on('change', function(){
  209. dispensaryType = $(this).val();
  210. if(dispensaryType == 3){ //健管师配送时,显示复选框
  211. $("#checkboxBox").removeClass("hidden");
  212. }else{
  213. $("#checkboxBox").addClass("hidden");
  214. $("#allocationType").prop("checked", false);
  215. allocationType = 0;
  216. }
  217. getPrescriptionList(true);
  218. });
  219. $("#address").on('change', function(){
  220. hospital = $(this).val();
  221. getPrescriptionList(true);
  222. });
  223. $("#allocationType").on('change', function(){
  224. var $this = $(this);
  225. if($this.prop('checked')){
  226. allocationType = 1;
  227. }else{
  228. allocationType = 0;
  229. }
  230. getPrescriptionList(true);
  231. });
  232. $("#searchBtn").on('click', function(){
  233. var $input = $("#searchName"),
  234. text = $.trim($input.val());
  235. nameKey = text;
  236. getPrescriptionList(true);
  237. });
  238. $("#selectAll").on('click', function(){
  239. var $this = $(this),
  240. $checkbox = $("input[name=orderItem]"),
  241. length = $checkbox.length;
  242. if($this.prop("checked")){
  243. $checkbox.prop("checked", true);
  244. selectItemNum = length;
  245. $("#selectedCount").text(selectItemNum);
  246. }else{
  247. $checkbox.prop("checked", false);
  248. selectItemNum = 0;
  249. $("#selectedCount").text(0);
  250. }
  251. checkArrangeDisable('all');
  252. });
  253. $("body").on('click', "input[name=orderItem]", function(){
  254. var $this = $(this),
  255. status = $this.data('status'),
  256. type = $this.data('type'),
  257. expressage = $this.data('expressage'),
  258. code = $this.data('code');
  259. if($this.prop("checked")){
  260. selectItemNum ++;
  261. if((type == 3) && (status >= 50) && (expressage=='' || !expressage)){
  262. selectItem.push(code);
  263. }
  264. }else{
  265. selectItemNum --;
  266. if(selectItem.indexOf(code) > -1){
  267. var index = selectItem.indexOf(code);
  268. selectItem.splice(index,1);
  269. }
  270. }
  271. $("#selectedCount").text(selectItemNum);
  272. checkArrangeDisable();
  273. });
  274. $("#arrange").on('click', function(){
  275. if($(this).hasClass("disabled")){
  276. return false;
  277. }
  278. $('#myModal').modal('toggle');
  279. getHealthDoctorList();
  280. });
  281. $("#doctorName").on('keyup', function(e){
  282. if (e.which === 13) {
  283. getHealthDoctorList(true);
  284. }
  285. });
  286. $("#confirmBtn").on('click', function(){
  287. //发送请求确认的请求
  288. var params = {
  289. codes: selectItem.join(","),
  290. healthDoctor: selectDoctor
  291. }
  292. orderAPI.distributeHealthDoctor({data: params}).then(function(res){
  293. if(res.status == 200){
  294. $('#myModal').modal('toggle');
  295. $('#confirmModal').modal('toggle');
  296. $("#prescriptTable").bootstrapTable('refresh');
  297. }else{
  298. }
  299. })
  300. });
  301. }
  302. //判断选中的订单是否是可分配的的订单
  303. function checkArrangeDisable(clickType){ //type=all 为点击全选时处理
  304. //可以分配的条件,1是健管师配送订单,2状态为待分配
  305. var $checkbox = $("input[name=orderItem]:checked"),
  306. len = $checkbox.length;
  307. isArrange = false;
  308. if(clickType == 'all'){
  309. selectItem = [];
  310. }
  311. for(var i=0; i<len; i++){
  312. var $item = $($checkbox[i]),
  313. status = $item.data('status'),
  314. type = $item.data('type'),
  315. expressage = $item.data('expressage'),
  316. code = $item.data('code');
  317. if(type != 3){
  318. isArrange = false;
  319. break;
  320. }else{
  321. if((status >= 50) && (expressage=='' || !expressage)){ //支付成功后状态+配送员的名字为空为待分配状态
  322. isArrange = true;
  323. if(clickType == 'all'){
  324. selectItem.push(code);
  325. }
  326. }else{
  327. isArrange = false;
  328. break;
  329. }
  330. }
  331. }
  332. if(!isArrange){
  333. $("#arrange").addClass("disabled");
  334. }else{
  335. $("#arrange").removeClass("disabled");
  336. }
  337. }