inspect.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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(tempArr[i].time == tmpLis.time){
  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(tempArrs[i].time == tmpLis.time){
  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)=>item.time != tmpLis.time)
  76. newState.labelListBig = [...tempArr]
  77. }else{//小项
  78. tempArrs = tempArrs.filter((item)=> item.time != tmpLis.time )
  79. newState.labelListSmall = [...tempArrs]
  80. }
  81. tempBigOrder = tempArr.filter((item)=>item.check)
  82. tempSmallOrder = tempArrs.filter((item)=>item.check)
  83. tempTotalOrder=tempBigOrder.concat(tempSmallOrder)
  84. newState.totalOrder=[...tempTotalOrder]
  85. return newState;
  86. }
  87. if (action.type == SET_TIP_NEW) {
  88. const newState = Object.assign({}, state);
  89. let tempArr = newState.labelListBig;
  90. let tempArrs = newState.labelListSmall;
  91. let tmpLis = action.item
  92. if(tmpLis.flg == 1){//大项,改的只能是时间
  93. tempArr = tempArr.filter((item,idx)=>{
  94. if(action.sign==idx){
  95. item.time = action.value
  96. }
  97. return item
  98. })
  99. }else{
  100. tempArrs = tempArrs.filter((item,idx)=>{
  101. if(action.sign == idx){
  102. if(action.tip==1){//小项改时间
  103. item.time = action.value
  104. }else{//小项该数值
  105. if(isNumber(action.value-0)){
  106. item.value = action.value
  107. }else{
  108. item.otherValue = action.value
  109. }
  110. }
  111. }
  112. return item
  113. })
  114. }
  115. newState.labelListBig = [...tempArr]
  116. newState.labelListSmall = [...tempArrs]
  117. return newState;
  118. }
  119. if (action.type == SEARCH_TYPE) {
  120. const newState = Object.assign({}, state);
  121. newState.shType = action.value
  122. return newState;
  123. }
  124. if (action.type == RESET_LABEL) { //选中的结果重组
  125. const newState = Object.assign({}, state);
  126. const tempArr = newState.labelListBig;
  127. const tempArrs = newState.labelListSmall;
  128. let tmpLis = action.list
  129. tmpLis['dateValue'] = getCurrentDate(1)
  130. tmpLis['time'] = getCurrentDate(1)
  131. if(tmpLis.flg == 1){//大项
  132. tempArr.push(tmpLis)
  133. newState.labelListBig = [...tempArr]
  134. }else{//小项
  135. tempArrs.push(tmpLis)
  136. newState.labelListSmall = [...tempArrs]
  137. }
  138. return newState;
  139. }
  140. if (action.type == SEARCH_LIST) {
  141. const newState = Object.assign({}, state);
  142. newState.list = action.list
  143. newState.inspectVal = action.val
  144. return newState;
  145. }
  146. if (action.type == SET_LABEL) { //选中的结果
  147. const newState = Object.assign({}, state);
  148. let tempArr = [];
  149. if(action.sign == 'common'){
  150. let tmpInspectList = store.getState().homePage.inspectList
  151. tempArr = tmpInspectList;
  152. }else{
  153. tempArr = newState.list
  154. }
  155. const tempArrs = newState.labelList;
  156. for (let i = 0; i < tempArr.length; i++) {
  157. if (i == action.idx) {
  158. tempArrs.push(tempArr[i])
  159. newState.labelList = [...tempArrs]
  160. }
  161. }
  162. let tmpArr = newState.getExcelDataList;
  163. let tmpArr2 = newState.labelList;
  164. newState.pushItems = getPushLists(tmpArr,tmpArr2);
  165. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  166. return newState;
  167. }
  168. if (action.type == ADD_LABEL) { //右侧推送的检验检查项,点击开单放到左侧检验检查的位置上
  169. const newState = Object.assign({}, state);
  170. const tempArr = newState.labelList;
  171. for(let i = 0;i <action.lis.length;i++){
  172. tempArr.push(action.lis[i]);
  173. }
  174. newState.labelList = [...tempArr]
  175. let tmpArr = newState.getExcelDataList;
  176. let tmpArr2 = newState.labelList;
  177. newState.pushItems = getPushLists(tmpArr,tmpArr2);
  178. newState.inspectStrPlus = getStringPlus(newState.pushItems);
  179. return newState;
  180. }
  181. if (action.type == FILL_ACTIVE) { //点击标签放到暂存里
  182. const newState = Object.assign({}, state);
  183. const tempArr = newState.labelList;
  184. for (let i = 0; i < tempArr.length; i++) {
  185. if (i == action.idx) {
  186. newState.fillActive = tempArr[i]
  187. }
  188. }
  189. return newState;
  190. }
  191. if (action.type == CLEAR_LABEL) { //清空数据填写
  192. const newState = Object.assign({}, state);
  193. const tempArrs = newState.fillActive;
  194. const tempArr = newState.fillActive.details;
  195. let tmpArr = newState.getExcelDataList;
  196. let tmpArr2 = newState.labelList;
  197. for (let i = 0; i < tempArr.length; i++) {
  198. // tempArr[i].value = ''
  199. }
  200. tempArrs.show = false;
  201. newState.pushItem = getPushList(tmpArr,tmpArr2);
  202. newState.pushItems = getPushLists(tmpArr,tmpArr2);
  203. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  204. return newState;
  205. }
  206. if (action.type == GET_EXCEL) { //导入数据
  207. const newState = Object.assign({}, state);
  208. let tmpArr = newState.getExcelDataList;
  209. let tmpArr2 = newState.labelList;
  210. newState.getExcelData = action.data
  211. tmpArr.push(action.data)
  212. newState.getExcelDataList = [...tmpArr]
  213. newState.pushItem = getPushList(tmpArr,tmpArr2);
  214. newState.pushItems = getPushLists(tmpArr,tmpArr2);
  215. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  216. // getExcelString(action,newState,tmpArr,tmpArr2)
  217. return newState;
  218. }
  219. if(action.type == DEL_EXCEL_LIST){ //删除excel列表的某个数据
  220. const newState = Object.assign({}, state);
  221. const tempArr2 = newState.labelList;
  222. let tmpArr = newState.getExcelDataList;
  223. tmpArr.splice(action.idx,1);
  224. newState.getExcelDataList = [...tmpArr];
  225. let tempArr1 = newState.getExcelDataList;
  226. newState.pushItem = getPushList(tempArr1,tempArr2);
  227. newState.pushItems = getPushLists(tempArr1,tempArr2);
  228. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  229. return newState;
  230. }
  231. if (action.type == CHECK_VALUE_IS_CHANGE) { //数据添加后显示与否
  232. const newState = Object.assign({}, state);
  233. // const tempArrAct = newState.fillActive;
  234. const tempArr = action.arr;
  235. tempArr.time = action.time;
  236. let tmpArr = newState.getExcelDataList;
  237. const tempArrs = newState.labelList;
  238. tempArrs[action.idx] = tempArr;
  239. newState.fillActive = tempArr;
  240. newState.labelList = tempArrs;
  241. // tempArrAct.show = true;
  242. newState.pushItem = getPushList(tmpArr,tempArrs);
  243. newState.pushItems = getPushLists(tmpArr,tempArrs);
  244. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  245. return newState;
  246. }
  247. if (action.type == CLEAR_ALL_LABEL) { //清空所有数据
  248. const newState = Object.assign({}, state);
  249. newState.labelList =action.data;
  250. newState.getExcelDataList = action.dataExcel;
  251. let tmpArr = action.dataExcel;
  252. const tempArrs = action.data;
  253. newState.pushItem = getPushList(tmpArr,tempArrs);
  254. newState.inspectStrPlus = action.saveTextData;
  255. return newState;
  256. }
  257. if (action.type == DEL_PART_ITEM) { //清空填寫数据
  258. const newState = Object.assign({}, state);
  259. const tempArr = newState.labelList;
  260. tempArr.splice(action.idx,1);
  261. newState.labelList = [...tempArr];
  262. let tmpArr = newState.getExcelDataList;
  263. newState.pushItem = getPushList(tmpArr,tempArr);
  264. newState.pushItems = getPushLists(tmpArr,tempArr);
  265. newState.inspectStrPlus = getStringPlus(newState.pushItems)
  266. return newState;
  267. }
  268. if (action.type == SET_CONTEXT) {
  269. const newState = Object.assign({}, state);
  270. newState.context = action.obj
  271. return newState;
  272. }
  273. if (action.type == REINSPECTDATA) {
  274. const newState = Object.assign({}, state);
  275. newState.labelListBig = action.params[8].content.labelListBig
  276. newState.labelListSmall = action.params[8].content.labelListSmall;
  277. newState.totalOrder = action.params[8].content.labelListBig;
  278. return newState;
  279. }
  280. if (action.type == CLEARINSPECTDATA) {
  281. let newState = Object.assign({}, state);
  282. newState.labelListBig = [];
  283. newState.labelListSmall = [];
  284. newState.totalOrder = [];
  285. return newState;
  286. }
  287. return state;
  288. }
  289. function isNumber(obj) {
  290. return typeof obj === 'number' && !isNaN(obj)
  291. }