order-list.js 12 KB

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