order-list.js 13 KB

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