order-list.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. setTitle("续方订单");
  24. //非团队长隐藏操作按钮
  25. if(!isLeader || isLeader == 'false'){
  26. $("#arrange").hide();
  27. }
  28. //填充下拉框数据
  29. orderAPI.getFilterInfo().then(function(res){
  30. fillDropDown(res);
  31. //获得续方订单列表
  32. getPrescriptionList();
  33. });
  34. //获得服务站数据
  35. orderAPI.getHospitalList({data: {teamCode: teamCode}}).then(function(res){
  36. var html = template('address_tmpl', {list: res.data});
  37. $("#address").empty().append(html);
  38. });
  39. bindEvents();
  40. });
  41. //获得续方订单列表
  42. function getPrescriptionList( refresh){
  43. var params = {
  44. teamCode: teamCode,
  45. startDate: startDate,
  46. endDate: endDate,
  47. state: state,
  48. dispensaryType: dispensaryType,
  49. hospital: hospital,
  50. allocationType: allocationType,
  51. nameKey: nameKey
  52. };
  53. //先请求获得所有的数量
  54. orderAPI.getOrderListCount({data:params}).then(function(res){
  55. if(res.status == 200){
  56. totalOrderCount = res.data.total;
  57. if(refresh){
  58. $("#prescriptTable").bootstrapTable('refresh');
  59. }
  60. var options = $.extend(orderAPI.getOrderListTableAjaxObj, {
  61. queryParams: queryParams,
  62. queryParamsType: "limit",
  63. pagination: true,
  64. paginationLoop: true,
  65. sidePagination: 'server',
  66. pageNumber: 1,
  67. pageSize: 10,
  68. responseHandler: function (res) {
  69. var data = _.map(res.data, function(o){
  70. var result = "";
  71. for(var i=0; i<o.prescriptionDt.length; i++){
  72. if(i>0){
  73. result += ','+o.prescriptionDt[i].name;
  74. }else{
  75. result += o.prescriptionDt[i].name;
  76. }
  77. }
  78. o.result = result;
  79. if(o.status == '50'){
  80. o.statusName = '订单已支付';
  81. }else if(o.status == '60'){
  82. o.statusName = '配药完成';
  83. }else{
  84. o.statusName = getStatusName(o.status);
  85. }
  86. o.express = getExpressName(o.dispensaryType);
  87. var address = "",
  88. expressage = "";
  89. if(o.dispensaryType == 2){
  90. expressage = o.expressageHospitalName;
  91. address = o.provinceName + o.cityName + o.townName + o.address;
  92. }else if(o.dispensaryType == 3){
  93. address = o.patientHospitalName;
  94. expressage = o.expressageName;
  95. }
  96. o.expressage = expressage;
  97. o.address = address;
  98. o.action = '<a class="c-12b7f5" href="prescription-main.html?code='+o.code+'&patiCode='+o.patientCode+'&teamCode='+teamCode+'&tab=2&patiName='+o.name+'">查看</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. $("#prescriptTable").bootstrapTable(options);
  109. }
  110. });
  111. }
  112. function queryParams(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: 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. jgPage = params.offset/params.limit + 1
  188. return {
  189. page: jgPage,
  190. size: params.limit,
  191. name: $.trim($("#doctorName").val())
  192. };
  193. }
  194. function fillDropDown(res){
  195. if(res.status == 200){
  196. var stateHtml = template('state_tmpl', {list: res.data.states});
  197. $("#orderStatus").append(stateHtml);
  198. var expressHtml = template('express_tmpl', {list: res.data.dispensaryTypes});
  199. $("#express").append(expressHtml);
  200. }else{
  201. }
  202. }
  203. //绑定事件
  204. function bindEvents(){
  205. $(".n-tab").on('click', function(){
  206. if($(this).hasClass("active")){
  207. return false;
  208. }else{
  209. $(this).addClass("active");
  210. $(this).siblings().removeClass("active");
  211. var seDate = getStartEndDate($(this).attr("data-val"));
  212. startDate = seDate.startDate;
  213. endDate = seDate.endDate;
  214. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  215. getPrescriptionList(true);
  216. }
  217. });
  218. $("#orderStatus").on('change', function(){
  219. var $this = $(this);
  220. state = $this.val();
  221. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  222. getPrescriptionList(true);
  223. });
  224. $("#express").on('change', function(){
  225. dispensaryType = $(this).val();
  226. if(dispensaryType == 3){ //健管师配送时,显示复选框
  227. $("#checkboxBox").removeClass("hidden");
  228. }else{
  229. $("#checkboxBox").addClass("hidden");
  230. $("#allocationType").prop("checked", false);
  231. allocationType = 0;
  232. }
  233. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  234. getPrescriptionList(true);
  235. });
  236. $("#address").on('change', function(){
  237. hospital = $(this).val();
  238. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  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. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  249. getPrescriptionList(true);
  250. });
  251. $("#searchBtn").on('click', function(){
  252. var $input = $("#searchName"),
  253. text = $.trim($input.val());
  254. nameKey = text;
  255. $('#prescriptTable').bootstrapTable('refreshOptions',{pageNumber:1});
  256. getPrescriptionList(true);
  257. });
  258. $("#selectAll").on('click', function(){
  259. var $this = $(this),
  260. $checkbox = $("input[name=orderItem]"),
  261. length = $checkbox.length;
  262. if($this.prop("checked")){
  263. $checkbox.prop("checked", true);
  264. selectItemNum = length;
  265. $("#selectedCount").text(selectItemNum);
  266. }else{
  267. $checkbox.prop("checked", false);
  268. selectItemNum = 0;
  269. $("#selectedCount").text(0);
  270. }
  271. checkArrangeDisable('all');
  272. });
  273. $("body").on('click', "input[name=orderItem]", function(){
  274. var $this = $(this),
  275. status = $this.data('status'),
  276. type = $this.data('type'),
  277. expressage = $this.data('expressage'),
  278. code = $this.data('code');
  279. if($this.prop("checked")){
  280. selectItemNum ++;
  281. if((type == 3) && (status >= 50) && (expressage=='' || !expressage)){
  282. selectItem.push(code);
  283. }
  284. }else{
  285. selectItemNum --;
  286. if(selectItem.indexOf(code) > -1){
  287. var index = selectItem.indexOf(code);
  288. selectItem.splice(index,1);
  289. }
  290. }
  291. $("#selectedCount").text(selectItemNum);
  292. checkArrangeDisable();
  293. });
  294. $("#arrange").on('click', function(){
  295. if($(this).hasClass("disabled")){
  296. return false;
  297. }
  298. $('#myModal').modal('toggle');
  299. getHealthDoctorList();
  300. });
  301. $("#doctorName").on('keyup', function(e){
  302. if (e.which === 13) {
  303. $('#hDoctor').bootstrapTable('refreshOptions',{pageNumber:1});
  304. getHealthDoctorList(true);
  305. }
  306. });
  307. $("#confirmBtn").on('click', function(){
  308. //发送请求确认的请求
  309. var params = {
  310. codes: selectItem.join(","),
  311. healthDoctor: selectDoctor
  312. }
  313. orderAPI.distributeHealthDoctor({data: params}).then(function(res){
  314. if(res.status == 200){
  315. $('#myModal').modal('toggle');
  316. $('#confirmModal').modal('toggle');
  317. $("#prescriptTable").bootstrapTable('refresh');
  318. }else{
  319. }
  320. })
  321. });
  322. }
  323. //判断选中的订单是否是可分配的的订单
  324. function checkArrangeDisable(clickType){ //type=all 为点击全选时处理
  325. //可以分配的条件,1是健管师配送订单,2状态为待分配
  326. var $checkbox = $("input[name=orderItem]:checked"),
  327. len = $checkbox.length;
  328. isArrange = false;
  329. if(clickType == 'all'){
  330. selectItem = [];
  331. }
  332. for(var i=0; i<len; i++){
  333. var $item = $($checkbox[i]),
  334. status = $item.data('status'),
  335. type = $item.data('type'),
  336. expressage = $item.data('expressage'),
  337. code = $item.data('code');
  338. if(type != 3){
  339. isArrange = false;
  340. break;
  341. }else{
  342. if((status >= 50) && (expressage=='' || !expressage)){ //支付成功后状态+配送员的名字为空为待分配状态
  343. isArrange = true;
  344. if(clickType == 'all'){
  345. selectItem.push(code);
  346. }
  347. }else{
  348. isArrange = false;
  349. break;
  350. }
  351. }
  352. }
  353. if(!isArrange){
  354. $("#arrange").addClass("disabled");
  355. }else{
  356. $("#arrange").removeClass("disabled");
  357. }
  358. }