inspect.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import {
  2. SEARCH_LIST,
  3. SET_LABEL,
  4. FILL_ACTIVE,
  5. GET_EXCEL,
  6. CHECK_VALUE_IS_CHANGE,
  7. CLEAR_LABEL,
  8. RESET_LABEL,
  9. CLEAR_ALL_LABEL,
  10. DEL_PART_ITEM,
  11. DEL_EXCEL_LIST,
  12. ADD_LABEL,
  13. SET_CONTEXT,
  14. SET_TIP_NEW,
  15. SEARCH_TYPE,
  16. DEL_ONE_PIC,
  17. CHECK_ON_OFF,
  18. REINSPECTDATA,
  19. CLEARINSPECTDATA,
  20. } from '../types/inspect';
  21. import store from '@store';
  22. import { getStringPlus, getPushLists, getPushList,getCurrentDate} from '@utils/tools.js';
  23. const initSearchList = {
  24. list: [], //搜索的结果
  25. labelList: [], //选中的结果,也是需要保存的数据
  26. labelListActive: [], //缓存值
  27. fillActive: {}, //选中的标签的填写单
  28. getExcelData: {}, //导入的数据
  29. inspectStrPlus:'',
  30. getExcelDataList: [], //导入的数据
  31. pushItem:[], //推送的数据
  32. pushItems:[], //右侧模板预览的数据
  33. inspectVal:'',
  34. context:{},
  35. shType:2,
  36. labelListBig:[],//大项
  37. labelListSmall:[],//小项
  38. totalOrder:[],//开单项
  39. }
  40. export default (state = initSearchList, action) => {
  41. if (action.type == CHECK_ON_OFF) {
  42. const newState = Object.assign({}, state);
  43. let tempArr = newState.labelListBig;
  44. let tempArrs = newState.labelListSmall;
  45. let tmpLis = action.item,tempBigOrder=[],tempSmallOrder=[],tempTotalOrder=[];
  46. if(tmpLis&&tmpLis.flg == 1){
  47. for(let i = 0;i < tempArr.length;i++){
  48. if(action.tip == i){
  49. let flg = tempArr[i].check;
  50. tempArr[i].check = !flg
  51. }
  52. }
  53. newState.labelListBig = [...tempArr]
  54. }else{
  55. for(let i = 0;i < tempArrs.length;i++){
  56. if(action.tip==i){
  57. let flg = tempArrs[i].check;
  58. tempArrs[i].check = !flg
  59. }
  60. }
  61. newState.labelListSmall = [...tempArrs]
  62. }
  63. tempBigOrder = tempArr.filter((item)=>item.check)
  64. tempSmallOrder = tempArrs.filter((item)=>item.check)
  65. tempTotalOrder=tempBigOrder.concat(tempSmallOrder)
  66. newState.totalOrder=[...tempTotalOrder]
  67. return newState;
  68. }
  69. if (action.type == DEL_ONE_PIC) {
  70. const newState = Object.assign({}, state);
  71. let tempArr = newState.labelListBig;
  72. let tempArrs = newState.labelListSmall;
  73. let tmpLis = action.item,tempBigOrder=[],tempSmallOrder=[],tempTotalOrder=[];
  74. if(tmpLis&&tmpLis.flg == 1){//大项
  75. tempArr = tempArr.filter((item,idx)=>{
  76. if(action.tip == idx){
  77. return item
  78. }
  79. })
  80. newState.labelListBig = [...tempArr]
  81. }else{//小项
  82. tempArrs = tempArrs.filter((item,idx)=> {
  83. if(action.tip == idx){
  84. return item
  85. }
  86. } )
  87. newState.labelListSmall = [...tempArrs]
  88. }
  89. tempBigOrder = tempArr.filter((item)=>item.check)
  90. tempSmallOrder = tempArrs.filter((item)=>item.check)
  91. tempTotalOrder=tempBigOrder.concat(tempSmallOrder)
  92. newState.totalOrder=[...tempTotalOrder]
  93. return newState;
  94. }
  95. if (action.type == SET_TIP_NEW) {
  96. const newState = Object.assign({}, state);
  97. let tempArr = newState.labelListBig;
  98. let tempArrs = newState.labelListSmall;
  99. let tmpLis = action.item
  100. if(tmpLis.flg == 1){//大项,改的只能是时间
  101. tempArr = tempArr.filter((item,idx)=>{
  102. if(action.sign==idx){
  103. item.time = action.value
  104. item.dateValue = action.value
  105. }
  106. return item
  107. })
  108. }else{
  109. tempArrs = tempArrs.filter((item,idx)=>{
  110. if(action.sign == idx){
  111. if(action.tip==1){//小项改时间
  112. item.time = action.value
  113. item.dateValue = action.value
  114. }else{//小项该数值
  115. if(isNumber(action.value-0)){
  116. item.value = action.value
  117. }else{
  118. item.otherValue = action.value
  119. }
  120. }
  121. }
  122. return item
  123. })
  124. }
  125. newState.labelListBig = [...tempArr]
  126. newState.labelListSmall = [...tempArrs]
  127. return newState;
  128. }
  129. if (action.type == SEARCH_TYPE) {
  130. const newState = Object.assign({}, state);
  131. newState.shType = action.value
  132. return newState;
  133. }
  134. if (action.type == RESET_LABEL) { //选中的结果重组
  135. const newState = Object.assign({}, state);
  136. const tempArr = newState.labelListBig;
  137. const tempArrs = newState.labelListSmall;
  138. let tmpLis = action.list
  139. tmpLis['dateValue'] = getCurrentDate(1)
  140. tmpLis['time'] = getCurrentDate(1)
  141. if(tmpLis.flg == 1){//大项
  142. tempArr.push(tmpLis)
  143. newState.labelListBig = [...tempArr]
  144. }else{//小项
  145. tempArrs.push(tmpLis)
  146. newState.labelListSmall = [...tempArrs]
  147. }
  148. return newState;
  149. }
  150. if (action.type == SEARCH_LIST) {
  151. const newState = Object.assign({}, state);
  152. newState.list = action.list
  153. newState.inspectVal = action.val
  154. return newState;
  155. }
  156. if (action.type == SET_LABEL) { //选中的结果
  157. const newState = Object.assign({}, state);
  158. let tempArr = [];
  159. if(action.sign == 'common'){
  160. let tmpInspectList = store.getState().homePage.inspectList
  161. tempArr = tmpInspectList;
  162. }else{
  163. tempArr = newState.list
  164. }
  165. const tempArrs = newState.labelList;
  166. for (let i = 0; i < tempArr.length; i++) {
  167. if (i == action.idx) {
  168. tempArrs.push(tempArr[i])
  169. newState.labelList = [...tempArrs]
  170. }
  171. }
  172. let tmpArr = newState.getExcelDataList;
  173. let tmpArr2 = newState.labelList;
  174. newState.pushItems = getPushLists(tmpArr,tmpArr2);
  175. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  176. return newState;
  177. }
  178. if (action.type == ADD_LABEL) { //右侧推送的检验检查项,点击开单放到左侧检验检查的位置上
  179. const newState = Object.assign({}, state);
  180. const tempArr = newState.labelList;
  181. for(let i = 0;i <action.lis.length;i++){
  182. tempArr.push(action.lis[i]);
  183. }
  184. newState.labelList = [...tempArr]
  185. let tmpArr = newState.getExcelDataList;
  186. let tmpArr2 = newState.labelList;
  187. newState.pushItems = getPushLists(tmpArr,tmpArr2);
  188. newState.inspectStrPlus = getStringPlus(newState.pushItems);
  189. return newState;
  190. }
  191. if (action.type == FILL_ACTIVE) { //点击标签放到暂存里
  192. const newState = Object.assign({}, state);
  193. const tempArr = newState.labelList;
  194. for (let i = 0; i < tempArr.length; i++) {
  195. if (i == action.idx) {
  196. newState.fillActive = tempArr[i]
  197. }
  198. }
  199. return newState;
  200. }
  201. if (action.type == CLEAR_LABEL) { //清空数据填写
  202. const newState = Object.assign({}, state);
  203. const tempArrs = newState.fillActive;
  204. const tempArr = newState.fillActive.details;
  205. let tmpArr = newState.getExcelDataList;
  206. let tmpArr2 = newState.labelList;
  207. for (let i = 0; i < tempArr.length; i++) {
  208. // tempArr[i].value = ''
  209. }
  210. tempArrs.show = false;
  211. newState.pushItem = getPushList(tmpArr,tmpArr2);
  212. newState.pushItems = getPushLists(tmpArr,tmpArr2);
  213. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  214. return newState;
  215. }
  216. if (action.type == GET_EXCEL) { //导入数据
  217. const newState = Object.assign({}, state);
  218. let tmpArr = newState.getExcelDataList;
  219. let tmpArr2 = newState.labelList;
  220. newState.getExcelData = action.data
  221. tmpArr.push(action.data)
  222. newState.getExcelDataList = [...tmpArr]
  223. newState.pushItem = getPushList(tmpArr,tmpArr2);
  224. newState.pushItems = getPushLists(tmpArr,tmpArr2);
  225. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  226. // getExcelString(action,newState,tmpArr,tmpArr2)
  227. return newState;
  228. }
  229. if(action.type == DEL_EXCEL_LIST){ //删除excel列表的某个数据
  230. const newState = Object.assign({}, state);
  231. const tempArr2 = newState.labelList;
  232. let tmpArr = newState.getExcelDataList;
  233. tmpArr.splice(action.idx,1);
  234. newState.getExcelDataList = [...tmpArr];
  235. let tempArr1 = newState.getExcelDataList;
  236. newState.pushItem = getPushList(tempArr1,tempArr2);
  237. newState.pushItems = getPushLists(tempArr1,tempArr2);
  238. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  239. return newState;
  240. }
  241. if (action.type == CHECK_VALUE_IS_CHANGE) { //数据添加后显示与否
  242. const newState = Object.assign({}, state);
  243. // const tempArrAct = newState.fillActive;
  244. const tempArr = action.arr;
  245. tempArr.time = action.time;
  246. tempArr.dateValue = action.time
  247. let tmpArr = newState.getExcelDataList;
  248. const tempArrs = newState.labelList;
  249. tempArrs[action.idx] = tempArr;
  250. newState.fillActive = tempArr;
  251. newState.labelList = tempArrs;
  252. // tempArrAct.show = true;
  253. newState.pushItem = getPushList(tmpArr,tempArrs);
  254. newState.pushItems = getPushLists(tmpArr,tempArrs);
  255. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  256. return newState;
  257. }
  258. if (action.type == CLEAR_ALL_LABEL) { //清空所有数据
  259. const newState = Object.assign({}, state);
  260. newState.labelList =action.data;
  261. newState.getExcelDataList = action.dataExcel;
  262. let tmpArr = action.dataExcel;
  263. const tempArrs = action.data;
  264. newState.pushItem = getPushList(tmpArr,tempArrs);
  265. newState.inspectStrPlus = action.saveTextData;
  266. return newState;
  267. }
  268. if (action.type == DEL_PART_ITEM) { //清空填寫数据
  269. const newState = Object.assign({}, state);
  270. const tempArr = newState.labelList;
  271. tempArr.splice(action.idx,1);
  272. newState.labelList = [...tempArr];
  273. let tmpArr = newState.getExcelDataList;
  274. newState.pushItem = getPushList(tmpArr,tempArr);
  275. newState.pushItems = getPushLists(tmpArr,tempArr);
  276. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  277. return newState;
  278. }
  279. if (action.type == SET_CONTEXT) {
  280. const newState = Object.assign({}, state);
  281. newState.context = action.obj
  282. return newState;
  283. }
  284. if (action.type == REINSPECTDATA) {
  285. const newState = Object.assign({}, state);
  286. newState.labelListBig = action.params[8].content.labelListBig
  287. newState.labelListSmall = action.params[8].content.labelListSmall;
  288. newState.totalOrder = action.params[8].content.labelListBig;
  289. return newState;
  290. }
  291. if (action.type == CLEARINSPECTDATA) {
  292. let newState = Object.assign({}, state);
  293. newState.labelListBig = [];
  294. newState.labelListSmall = [];
  295. newState.totalOrder = [];
  296. return newState;
  297. }
  298. return state;
  299. }
  300. function isNumber(obj) {
  301. return typeof obj === 'number' && !isNaN(obj)
  302. }