order-list.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. jgPage = 1,
  12. size = 10,
  13. hospital = '', //服务站code
  14. allocationType, //是否是待分配续方
  15. nameKey, //搜索的姓名
  16. selectItemNum = 0, //选中的数量
  17. selectItem = [], //选中的订单号集合
  18. isArrange = false, // 判断所选的订单是否是可分配的
  19. totalOrderCount = 0,
  20. totalHealthDoctorCount = 0,
  21. selectDoctor; //选中的医生
  22. $(function(){
  23. //非团队长隐藏操作按钮
  24. if(!isLeader || isLeader == 'false'){
  25. $("#arrange").hide();
  26. }
  27. //填充下拉框数据
  28. orderAPI.getFilterInfo().then(function(res){
  29. fillDropDown(res);
  30. //获得续方订单列表
  31. getPrescriptionList();
  32. });
  33. //获得服务站数据
  34. orderAPI.getHospitalList({data: {teamCode: teamCode}}).then(function(res){
  35. var html = template('address_tmpl', {list: res.data});
  36. $("#address").empty().append(html);
  37. });
  38. bindEvents();
  39. });
  40. //获得续方订单列表
  41. function getPrescriptionList( refresh){
  42. var params = {
  43. teamCode: teamCode,
  44. startDate: startDate,
  45. endDate: endDate,
  46. state: state,
  47. dispensaryType: dispensaryType,
  48. hospital: hospital,
  49. allocationType: allocationType,
  50. nameKey: nameKey
  51. };
  52. //先请求获得所有的数量
  53. orderAPI.getOrderListCount({data:params}).then(function(res){
  54. if(res.status == 200){
  55. totalOrderCount = res.data.total;
  56. if(refresh){
  57. $("#prescriptTable").bootstrapTable('refresh');
  58. }
  59. var options = $.extend(orderAPI.getOrderListTableAjaxObj, {
  60. queryParams: queryParams,
  61. queryParamsType: "limit",
  62. pagination: true,
  63. paginationLoop: true,
  64. sidePagination: 'server',
  65. pageNumber: 1,
  66. pageSize: 10,
  67. responseHandler: function (res) {
  68. var data = _.map(res.data, function(o){
  69. var result = "";
  70. for(var i=0; i<o.prescriptionDt.length; i++){
  71. if(i>0){
  72. result += ','+o.prescriptionDt[i].name;
  73. }else{
  74. result += o.prescriptionDt[i].name;
  75. }
  76. }
  77. o.result = result;
  78. if(o.status == '50'){
  79. o.statusName = '订单已支付';
  80. }else if(o.status == '60'){
  81. o.statusName = '配药完成';
  82. }else{
  83. o.statusName = getStatusName(o.status);
  84. }
  85. o.express = getExpressName(o.dispensaryType);
  86. var address = "",
  87. expressage = "";
  88. if(o.dispensaryType == 2){
  89. expressage = o.expressageHospitalName;
  90. address = o.provinceName + o.cityName + o.townName + o.address;
  91. }else if(o.dispensaryType == 3){
  92. address = o.patientHospitalName;
  93. expressage = o.expressageName;
  94. }
  95. o.expressage = expressage;
  96. o.address = address;
  97. o.action = '<a class="c-12b7f5" href="prescription-main.html?code='+o.code+'&patiCode='+o.patientCode+'&teamCode='+teamCode+'&tab=2">查看</a>';
  98. 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+'">';
  99. return o;
  100. });
  101. return {
  102. rows: data,
  103. total: totalOrderCount
  104. }
  105. }
  106. })
  107. $("#prescriptTable").bootstrapTable(options);
  108. }
  109. });
  110. }
  111. function queryParams(params) {
  112. //当表格数据变化的时候,则取消全选按钮,然后之前的选中的信息将取消选中
  113. page = params.offset/params.limit + 1;
  114. selectItemNum = 0;
  115. $("#selectAll").prop("checked", false);
  116. $("#selectedCount").text(0);
  117. $("#arrange").addClass("disabled");
  118. return {
  119. teamCode: teamCode,
  120. page: page,
  121. size: params.limit,
  122. startDate: startDate,
  123. endDate: endDate,
  124. state: state,
  125. dispensaryType: dispensaryType,
  126. hospital: hospital,
  127. allocationType: allocationType,
  128. nameKey: nameKey
  129. };
  130. }
  131. //获得健管师列表
  132. function getHealthDoctorList(isRefresh){
  133. if(isRefresh){
  134. $("#hDoctor").bootstrapTable('refresh');
  135. }
  136. var options = $.extend(orderAPI.getHealthDoctorTableAjaxObj, {
  137. queryParams: queryParams2,
  138. queryParamsType: "limit",
  139. pagination: true,
  140. paginationLoop: true,
  141. sidePagination: 'server',
  142. pageNumber: 1,
  143. pageSize: 8,
  144. pageList: [5,8,10],
  145. responseHandler: function (res) {
  146. return {
  147. rows: res.data.doctors,
  148. total: res.data.total
  149. }
  150. },
  151. columns: [{
  152. field: 'photo',
  153. title: '',
  154. width: '50',
  155. formatter: function(val, row, index){
  156. var url = APIService.getImgUrl(val);
  157. if((url.indexOf("http")== -1) && (url.indexOf("https")== -1)){
  158. url = "img/d-male.png";
  159. }
  160. return '<img src="'+url+'" class="img-circle" width="40">';
  161. }
  162. }, {
  163. field: 'name',
  164. title: '',
  165. align: 'left'
  166. },{
  167. field: 'jobName',
  168. title: '职称',
  169. align: 'right'
  170. }],
  171. onClickRow: function(row, $el){
  172. $("#orderCount").text(selectItemNum);
  173. var jobName = '';
  174. if(row.jobName){
  175. jobName = row.jobName;
  176. }
  177. $("#docInfo").text(row.name+jobName);
  178. $("#confirmModal").modal('toggle');
  179. selectDoctor = row.code;
  180. }
  181. });
  182. $("#hDoctor").bootstrapTable(options);
  183. }
  184. function queryParams2(params) {
  185. //当表格数据变化的时候,则取消全选按钮,然后之前的选中的信息将取消选中
  186. jgPage = params.offset/params.limit + 1
  187. return {
  188. page: jgPage,
  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. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  214. getPrescriptionList(true);
  215. }
  216. });
  217. $("#orderStatus").on('change', function(){
  218. var $this = $(this);
  219. state = $this.val();
  220. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber: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. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  233. getPrescriptionList(true);
  234. });
  235. $("#address").on('change', function(){
  236. hospital = $(this).val();
  237. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber: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. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  248. getPrescriptionList(true);
  249. });
  250. $("#searchBtn").on('click', function(){
  251. var $input = $("#searchName"),
  252. text = $.trim($input.val());
  253. nameKey = text;
  254. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber: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. $('#hDoctor').bootstrapTable('refreshOptions',{pageNumber:1});
  303. getHealthDoctorList(true);
  304. }
  305. });
  306. $("#confirmBtn").on('click', function(){
  307. //发送请求确认的请求
  308. var params = {
  309. codes: selectItem.join(","),
  310. healthDoctor: selectDoctor
  311. }
  312. orderAPI.distributeHealthDoctor({data: params}).then(function(res){
  313. if(res.status == 200){
  314. $('#myModal').modal('toggle');
  315. $('#confirmModal').modal('toggle');
  316. $("#prescriptTable").bootstrapTable('refresh');
  317. }else{
  318. }
  319. })
  320. });
  321. }
  322. //判断选中的订单是否是可分配的的订单
  323. function checkArrangeDisable(clickType){ //type=all 为点击全选时处理
  324. //可以分配的条件,1是健管师配送订单,2状态为待分配
  325. var $checkbox = $("input[name=orderItem]:checked"),
  326. len = $checkbox.length;
  327. isArrange = false;
  328. if(clickType == 'all'){
  329. selectItem = [];
  330. }
  331. for(var i=0; i<len; i++){
  332. var $item = $($checkbox[i]),
  333. status = $item.data('status'),
  334. type = $item.data('type'),
  335. expressage = $item.data('expressage'),
  336. code = $item.data('code');
  337. if(type != 3){
  338. isArrange = false;
  339. break;
  340. }else{
  341. if((status >= 50) && (expressage=='' || !expressage)){ //支付成功后状态+配送员的名字为空为待分配状态
  342. isArrange = true;
  343. if(clickType == 'all'){
  344. selectItem.push(code);
  345. }
  346. }else{
  347. isArrange = false;
  348. break;
  349. }
  350. }
  351. }
  352. if(!isArrange){
  353. $("#arrange").addClass("disabled");
  354. }else{
  355. $("#arrange").removeClass("disabled");
  356. }
  357. }