order-list.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. $("#prescriptTable").bootstrapTable({
  59. method: 'get',
  60. url: APIService.server + 'doctor/prescriptionInfo/getDoctorPrescriptionExpressage',
  61. queryParams: queryParams,
  62. contentType: "application/json",
  63. queryParamsType: "limit",
  64. dataType: "json",
  65. pagination: true,
  66. paginationLoop: true,
  67. sidePagination: 'server',
  68. pageNumber: 1,
  69. pageSize: 10,
  70. ajaxOptions: {
  71. beforeSend: function(request) {
  72. var userAgent = {"id":4800,"uid":"zbqD201703150222","imei":"864394010176834","token":"71738e0adf3fa6dfe72eb71dc9c07ce2","platform":2,"hospital":"3502050100"};
  73. userAgent = JSON.stringify(userAgent);
  74. request.setRequestHeader("userAgent", userAgent);
  75. }
  76. },
  77. responseHandler: function (res) {
  78. var data = _.map(res.data, function(o){
  79. var result = "";
  80. for(var i=0; i<o.prescriptionDt.length; i++){
  81. if(i>0){
  82. result += ','+o.prescriptionDt[i].name;
  83. }else{
  84. result += o.prescriptionDt[i].name;
  85. }
  86. }
  87. o.result = result;
  88. o.statusName = getStatusName(o.status);
  89. o.express = getExpressName(o.dispensaryType);
  90. var address = "";
  91. if(o.dispensaryType == 2){
  92. address = o.patientHospitalAddress;
  93. o.expressageName = o.expressageHospitalName;
  94. }else{
  95. address = o.expressageHospitalName;
  96. }
  97. o.address = address;
  98. o.action = '<a class="c-12b7f5" href="">操作</a>';
  99. 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+'">';
  100. return o;
  101. });
  102. return {
  103. rows: data,
  104. total: totalOrderCount
  105. }
  106. }
  107. });
  108. }
  109. });
  110. }
  111. function queryParams(params) {
  112. console.log(params);
  113. //当表格数据变化的时候,则取消全选按钮,然后之前的选中的信息将取消选中
  114. page = params.offset/params.limit + 1;
  115. selectItemNum = 0;
  116. $("#selectAll").prop("checked", false);
  117. $("#selectedCount").text(0);
  118. $("#arrange").addClass("disabled");
  119. return {
  120. teamCode: teamCode,
  121. page: params.offset/params.limit + 1,
  122. size: params.limit,
  123. startDate: startDate,
  124. endDate: endDate,
  125. state: state,
  126. dispensaryType: dispensaryType,
  127. hospital: hospital,
  128. allocationType: allocationType,
  129. nameKey: nameKey
  130. };
  131. }
  132. //获得健管师列表
  133. function getHealthDoctorList(isRefresh){
  134. if(isRefresh){
  135. $("#hDoctor").bootstrapTable('refresh');
  136. }
  137. $("#hDoctor").bootstrapTable({
  138. method: 'get',
  139. url: APIService.server + 'doctor/prescriptionInfo/getHDoctorInDoctorHosiptal',
  140. queryParams: queryParams2,
  141. contentType: "application/json",
  142. queryParamsType: "limit",
  143. dataType: "json",
  144. pagination: true,
  145. paginationLoop: true,
  146. sidePagination: 'server',
  147. pageNumber: 1,
  148. pageSize: 8,
  149. pageList: [5,8,10],
  150. ajaxOptions: {
  151. beforeSend: function(request) {
  152. var userAgent = {"id":4800,"uid":"zbqD201703150222","imei":"864394010176834","token":"71738e0adf3fa6dfe72eb71dc9c07ce2","platform":2,"hospital":"3502050100"};
  153. userAgent = JSON.stringify(userAgent);
  154. request.setRequestHeader("userAgent", userAgent);
  155. }
  156. },
  157. responseHandler: function (res) {
  158. return {
  159. rows: res.data.doctors,
  160. total: res.data.total
  161. }
  162. },
  163. columns: [{
  164. field: 'photo',
  165. title: '',
  166. width: '50',
  167. formatter: function(val, row, index){
  168. var url = "img/d-male.png";
  169. if(val.indexOf("http")>-1 || val.indexOf("https")>-1){
  170. url = val;
  171. }
  172. return '<img src="'+url+'" class="img-circle" width="40">';
  173. }
  174. }, {
  175. field: 'name',
  176. title: '',
  177. align: 'left'
  178. },{
  179. field: 'jobName',
  180. title: '职称',
  181. align: 'right'
  182. }],
  183. onClickRow: function(row, $el){
  184. $("#orderCount").text(selectItemNum);
  185. $("#docInfo").text(row.name+row.jobName);
  186. $("#confirmModal").modal('toggle');
  187. selectDoctor = row.code;
  188. }
  189. });
  190. }
  191. function queryParams2(params) {
  192. console.log(params);
  193. //当表格数据变化的时候,则取消全选按钮,然后之前的选中的信息将取消选中
  194. return {
  195. page: params.offset/params.limit + 1,
  196. size: params.limit,
  197. name: $.trim($("#doctorName").val())
  198. };
  199. }
  200. function fillDropDown(res){
  201. if(res.status == 200){
  202. var stateHtml = template('state_tmpl', {list: res.data.states});
  203. $("#orderStatus").append(stateHtml);
  204. var expressHtml = template('express_tmpl', {list: res.data.dispensaryTypes});
  205. $("#express").append(expressHtml);
  206. }else{
  207. }
  208. }
  209. //绑定事件
  210. function bindEvents(){
  211. $(".n-tab").on('click', function(){
  212. if($(this).hasClass("active")){
  213. return false;
  214. }else{
  215. $(this).addClass("active");
  216. $(this).siblings().removeClass("active");
  217. getStartEndDate($(this).attr("data-val"));
  218. getPrescriptionList(true);
  219. }
  220. });
  221. $("#orderStatus").on('change', function(){
  222. var $this = $(this);
  223. state = $this.val();
  224. getPrescriptionList(true);
  225. });
  226. $("#express").on('change', function(){
  227. dispensaryType = $(this).val();
  228. if(dispensaryType == 3){ //健管师配送时,显示复选框
  229. $("#checkboxBox").removeClass("hidden");
  230. }else{
  231. $("#checkboxBox").addClass("hidden");
  232. $("#allocationType").prop("checked", false);
  233. allocationType = 0;
  234. }
  235. getPrescriptionList(true);
  236. });
  237. $("#address").on('change', function(){
  238. hospital = $(this).val();
  239. getPrescriptionList(true);
  240. });
  241. $("#allocationType").on('change', function(){
  242. var $this = $(this);
  243. if($this.prop('checked')){
  244. allocationType = 1;
  245. }else{
  246. allocationType = 0;
  247. }
  248. getPrescriptionList(true);
  249. });
  250. $("#searchBtn").on('click', function(){
  251. var $input = $("#searchName"),
  252. text = $.trim($input.val());
  253. nameKey = text;
  254. getPrescriptionList(true);
  255. });
  256. $("#selectAll").on('click', function(){
  257. var $this = $(this),
  258. $checkbox = $("input[name=orderItem]"),
  259. length = $checkbox.length;
  260. if($this.prop("checked")){
  261. $checkbox.prop("checked", true);
  262. selectItemNum = length;
  263. $("#selectedCount").text(selectItemNum);
  264. }else{
  265. $checkbox.prop("checked", false);
  266. selectItemNum = 0;
  267. $("#selectedCount").text(0);
  268. }
  269. checkArrangeDisable('all');
  270. });
  271. $("body").on('click', "input[name=orderItem]", function(){
  272. var $this = $(this),
  273. status = $this.data('status'),
  274. type = $this.data('type'),
  275. expressage = $this.data('expressage'),
  276. code = $this.data('code');
  277. if($this.prop("checked")){
  278. selectItemNum ++;
  279. if((type == 3) && (status >= 50) && (expressage=='' || !expressage)){
  280. selectItem.push(code);
  281. }
  282. }else{
  283. selectItemNum --;
  284. if(selectItem.indexOf(code) > -1){
  285. var index = selectItem.indexOf(code);
  286. selectItem.splice(index,1);
  287. }
  288. }
  289. $("#selectedCount").text(selectItemNum);
  290. checkArrangeDisable();
  291. });
  292. $("#arrange").on('click', function(){
  293. if($(this).hasClass("disabled")){
  294. return false;
  295. }
  296. $('#myModal').modal('toggle');
  297. getHealthDoctorList();
  298. });
  299. $("#doctorName").on('keyup', function(e){
  300. if (e.which === 13) {
  301. getHealthDoctorList(true);
  302. }
  303. });
  304. $("#confirmBtn").on('click', function(){
  305. //发送请求确认的请求
  306. var params = {
  307. codes: selectItem.join(","),
  308. healthDoctor: selectDoctor
  309. }
  310. orderAPI.distributeHealthDoctor({data: params}).then(function(res){
  311. if(res.status == 200){
  312. $('#myModal').modal('toggle');
  313. $('#confirmModal').modal('toggle');
  314. $("#prescriptTable").bootstrapTable('refresh');
  315. }else{
  316. }
  317. })
  318. });
  319. }
  320. //判断选中的订单是否是可分配的的订单
  321. function checkArrangeDisable(clickType){ //type=all 为点击全选时处理
  322. //可以分配的条件,1是健管师配送订单,2状态为待分配
  323. var $checkbox = $("input[name=orderItem]:checked"),
  324. len = $checkbox.length;
  325. isArrange = false;
  326. if(clickType == 'all'){
  327. selectItem = [];
  328. }
  329. for(var i=0; i<len; i++){
  330. var $item = $($checkbox[i]),
  331. status = $item.data('status'),
  332. type = $item.data('type'),
  333. expressage = $item.data('expressage'),
  334. code = $item.data('code');
  335. if(type != 3){
  336. isArrange = false;
  337. break;
  338. }else{
  339. if((status >= 50) && (expressage=='' || !expressage)){ //支付成功后状态+配送员的名字为空为待分配状态
  340. isArrange = true;
  341. if(clickType == 'all'){
  342. selectItem.push(code);
  343. }
  344. }else{
  345. isArrange = false;
  346. break;
  347. }
  348. }
  349. }
  350. if(!isArrange){
  351. $("#arrange").addClass("disabled");
  352. }else{
  353. $("#arrange").removeClass("disabled");
  354. }
  355. }
  356. //根据选择的tab获得开始和结束时间
  357. function getStartEndDate(index){
  358. var now = new Date(),
  359. sDate = new Date();
  360. endDate = now.format('yyyy-MM-dd');
  361. switch (index){
  362. case '0':
  363. startDate = '';
  364. endDate = '';
  365. break;
  366. case '1': //近一周
  367. sDate.setDate(now.getDate() - 7);
  368. startDate = sDate.format('yyyy-MM-dd');
  369. break;
  370. case '2': //近一个月
  371. sDate.setMonth(now.getMonth() -1);
  372. startDate = sDate.format('yyyy-MM-dd');
  373. break;
  374. case '3': //近半年
  375. sDate.setMonth(now.getMonth() - 6);
  376. startDate = sDate.format('yyyy-MM-dd');
  377. break;
  378. case '4': //近一年
  379. sDate.setFullYear(now.getFullYear() - 1);
  380. startDate = sDate.format('yyyy-MM-dd');
  381. break;
  382. }
  383. }
  384. //获得状态值
  385. //续方各状态返回值
  386. //(-3 支付过期 -2 患者自己取消 )续方取消,
  387. //-1 审核不通过 ,
  388. //(0 待审核, 2调整中,3调整成功, 4调整失败 ,10 医生审核(CA)通过)审核中,
  389. //20药师审核中,
  390. //21.药师审核失败,
  391. //30 开方中/药师审核成功,
  392. //31.开方失败,
  393. //(40开方完成/待支付 ,41 支付失败 )待支付,
  394. // 50 支付成功/待配药,
  395. //(60配药成功/待配送)等待领药,
  396. //(61配送失败62分配健管师 65配送中,69配送到服务站)配送中,
  397. //(100配送到患者手中/已完成)已完成
  398. //根据状态获得相关信息
  399. function getStatusName(status){
  400. var name = "",
  401. img = "";
  402. status = status + '';
  403. switch (status){
  404. case '-3':
  405. name = '支付过期';
  406. break;
  407. case '-2':
  408. name = '患者自己取消';
  409. break;
  410. case '-1':
  411. name = '审核不通过';
  412. break;
  413. case '0':
  414. case '2':
  415. case '3':
  416. case '4':
  417. case '10':
  418. name = '审核中';
  419. break;
  420. case '20':
  421. name = '药师审核中';
  422. break;
  423. case '21':
  424. name = '药师审核失败';
  425. break;
  426. case '30':
  427. name = '开方中';
  428. break;
  429. case '31':
  430. name = '开方失败';
  431. break;
  432. case '40':
  433. name = '待支付';
  434. break;
  435. case '41':
  436. name = '支付失败';
  437. break;
  438. case '50':
  439. name = '配药中';
  440. break;
  441. case '60':
  442. name = '等待领药';
  443. break;
  444. case '61':
  445. case '62':
  446. case '65':
  447. case '69':
  448. name = '配送中';
  449. break;
  450. case '100':
  451. name = '已完成';
  452. break;
  453. default:
  454. break;
  455. }
  456. return name;
  457. }
  458. function getExpressName(type){
  459. switch(type){
  460. case 1:
  461. return '自取';
  462. break;
  463. case 2:
  464. return '快递配送';
  465. break;
  466. case 3:
  467. return '健管师配送';
  468. break;
  469. }
  470. }