manualConfirmationJS.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. import repostCurd from '@/business/platform/form/utils/custom/joinCURD.js'
  2. export default {
  3. methods: {
  4. facilityData(page) {
  5. this.loadDataBySQL(page)
  6. },
  7. loadDataBySQL(page) {
  8. // 扫码扫到新数据,查询 并分页 回填展示
  9. let countSQL = `select count(*) as count from t_mjypb where jie_yang_zhuang_t = '待确认'`
  10. let str = (page-1)*10
  11. let fysql = `select ypb.*,sqb.fu_kuan_fang_shi_,sqb.fu_he_yuan_,sqb.ye_mian_zong_zhua,lian_xi_ren_ from t_mjypb ypb JOIN t_mjwtsqb sqb on ypb.wai_jian_ = sqb.id_ and ypb.jie_yang_zhuang_t = '待确认' order by yang_pin_bian_hao asc limit ${str},10`
  12. Promise.all([repostCurd('sql', countSQL), repostCurd('sql', fysql)]).then(([res1, res]) => {
  13. this.listData = []
  14. this.pageCount = res1.variables.data[0].count
  15. const { data } = res.variables || []
  16. if (data.length > 0) {
  17. data.forEach(item=>{
  18. item.jie_yang_shu_lian = 1
  19. item.jie_yang_zhuang_t = '已确认'
  20. this.listData.push(item)
  21. })
  22. console.log('Init Data',this.listData)
  23. }else{
  24. this.dontHaveSample();
  25. }
  26. })
  27. },
  28. dontHaveSample(){
  29. this.visable = false
  30. this.$message({
  31. message: '暂无样品待接收确认!',
  32. type: 'success'
  33. })
  34. this.closeDialog();
  35. },
  36. /* 列表失去焦点*/
  37. handleChange() {
  38. this.$refs.redarInput.focus(); //聚焦input
  39. },
  40. /* 关闭弹出列表框*/
  41. closeDialog() {
  42. this.remRedar()
  43. //回传关闭事件。隐藏当前组件。
  44. },
  45. handleClose() {
  46. this.handleChange()
  47. this.$confirm('确认关闭样品列表页面?').then(_ => {
  48. this.closeDialog();
  49. }).catch(_ => {});
  50. },
  51. handleLocationInfo(currentPosition, isLiuYang, positionDatas, positionIds, item, currentTime) {
  52. !positionIds.has(currentPosition) ? positionIds.add(currentPosition) : positionDatas.find(i => i.id_ === currentPosition).wei_zhi_zhuang_ta = '占用'
  53. if (positionDatas.find(i => i.id_ === currentPosition)!=undefined && positionDatas.find(i => i.id_ === currentPosition).wei_zhi_zhuang_ta === '空余') {
  54. let obj = {
  55. where: {
  56. id_: currentPosition
  57. },
  58. param: {
  59. wei_zhi_zhuang_ta: "占用",
  60. ru_ku_shi_jian_: currentTime,
  61. yang_pin_bian_hao: item.yang_pin_bian_hao,
  62. yang_pin_ming_che: item.yang_pin_ming_che,
  63. shi_fou_liu_yang_: isLiuYang
  64. }
  65. }
  66. let result = {
  67. name: 'emptyPosition',
  68. value: obj
  69. }
  70. return result
  71. } else { // 新增一条位置信息(修改它的样品编号,样品名称,入库时间,标识UUID)
  72. let sampleInfo = {
  73. yang_pin_bian_hao: item.yang_pin_bian_hao,
  74. yang_pin_ming_che: item.yang_pin_ming_che,
  75. ru_ku_shi_jian_: currentTime,
  76. biao_zhi_uuid_: item.biao_zhi_uuid_,
  77. shi_fou_liu_yang_: isLiuYang
  78. }
  79. let newPosition = this.generateNewPosition(positionDatas.find(i => i.id_ === currentPosition), sampleInfo)
  80. let result = {
  81. name: 'fullPosition',
  82. value: newPosition
  83. }
  84. return result
  85. }
  86. },
  87. // 根据旧位置数据生成新位置数据
  88. generateNewPosition(oldLocation, sampleInfo) {
  89. let temp = {
  90. fang_jian_lei_xin: oldLocation.fang_jian_lei_xin,
  91. qu_yu_: oldLocation.qu_yu_,
  92. huo_jia_lei_xing_: oldLocation.huo_jia_lei_xing_,
  93. huo_jia_hao_: oldLocation.huo_jia_hao_,
  94. gua_jia_hao_:oldLocation.gua_jia_hao_ || '',
  95. ceng_hao_: oldLocation.ceng_hao_,
  96. wei_zhi_bian_hao_: oldLocation.wei_zhi_bian_hao_,
  97. wei_zhi_zhuang_ta: oldLocation.wei_zhi_zhuang_ta,
  98. cun_fang_lei_xing: oldLocation.cun_fang_lei_xing,
  99. cun_chu_tiao_jian: oldLocation.cun_chu_tiao_jian,
  100. yang_pin_bian_hao: sampleInfo.yang_pin_bian_hao,
  101. yang_pin_ming_che: sampleInfo.yang_pin_ming_che,
  102. ru_ku_shi_jian_: sampleInfo.ru_ku_shi_jian_,
  103. shi_fou_liu_yang_: sampleInfo.shi_fou_liu_yang_,
  104. shou_yang_ri_qi_: sampleInfo.biao_zhi_uuid_,
  105. }
  106. return temp
  107. },
  108. submitData(type) {
  109. if (this.listData.length == 0) {
  110. this.$emit('callback', true)
  111. this.visable = false
  112. this.$message({
  113. message: '暂无样品待接收确认!',
  114. type: 'error'
  115. })
  116. this.closeDialog();
  117. } else {
  118. this.$confirm('请再次确认 [样品接收信息]').then(_ => {
  119. // 获取样品列表
  120. let ypInfoList = this.listData
  121. const currentTime = new Date(new Date().getTime() + 28800000).toJSON().slice(0, 16).replace('T', ' ')
  122. // 优化对象
  123. let positionArr = [] // 位置数组
  124. let positionIdSet = new Set() // 位置ID集合
  125. let ypdjbList = []
  126. let ypbList = []
  127. let ypbForeignKeyList = []
  128. let zsbIdList = []
  129. let taskList = []
  130. let allUUID = []
  131. // 1、确认样品数量,位置(数据校验)
  132. for(let item of ypInfoList){
  133. if(item.jie_yang_shu_lian > item.shou_yang_shu_lia){
  134. this.$message.error('操作失败,[' +item.yang_pin_ming_che + '] 接收确认数量不得大于收样数量。')
  135. return;
  136. }
  137. if(item.jie_yang_zhuang_t == '待确认'){
  138. this.$message.error('操作失败,[' + item.yang_pin_ming_che + '] 接收确认状态必须为已确认。')
  139. return;
  140. }
  141. if(item.shi_fou_liu_yang_ == "否" && (item.shou_yang_wei_zhi == null || item.shou_yang_wei_zhi == '') ){
  142. this.$message.error("收样存放位置不能为空!")
  143. return;
  144. }
  145. if(item.shi_fou_liu_yang_ == "是" && (item.liu_yang_wei_zhi_ == null || item.liu_yang_wei_zhi_ == '') ){
  146. this.$message.error("你要留样的话,存放位置不能为空哦!")
  147. return;
  148. }
  149. positionArr.push(item.shou_yang_wei_zhi,item.liu_yang_wei_zhi_)
  150. }
  151. // 2、整理样品位置信息
  152. let positionStr = positionArr.filter(i => i).join(',')
  153. var allPositionSql = `select * from t_mjypcfwz where find_in_set(id_,'${positionStr}')`// 搜集所有选择的位置信息
  154. repostCurd('sql', allPositionSql).then(res => {
  155. let { data } = res.variables || []
  156. // console.log(data)
  157. let handleResult = []
  158. this.emptyPosition = []
  159. this.fullPosition = []
  160. ypInfoList.forEach(item=>{
  161. allUUID.push(item.biao_zhi_uuid_)
  162. if(item.shou_yang_wei_zhi != undefined && item.shou_yang_wei_zhi){
  163. handleResult.push(this.handleLocationInfo(item.shou_yang_wei_zhi,'否',data,positionIdSet,item,currentTime))
  164. }
  165. if(item.liu_yang_wei_zhi_ != undefined && item.liu_yang_wei_zhi_){
  166. handleResult.push(this.handleLocationInfo(item.liu_yang_wei_zhi_,'是',data,positionIdSet,item,currentTime))
  167. }
  168. })
  169. let allUUIDStr = allUUID.filter(i => i).join(',')
  170. handleResult.forEach(item=>{
  171. item.name === 'emptyPosition' ? this.emptyPosition.push(item.value) : this.fullPosition.push(item.value)
  172. })
  173. console.log('sample_empty_position',this.emptyPosition)
  174. console.log('sample_full_position',this.fullPosition)
  175. if(this.emptyPosition.length > 0){
  176. let allParams = {
  177. tableName: 't_mjypcfwz',
  178. updList: this.emptyPosition
  179. }
  180. repostCurd('updatesByWhere',JSON.stringify(allParams))
  181. }
  182. repostCurd('add', '{"tableName":"t_mjypcfwz","paramWhere":' + JSON.stringify(this.fullPosition) + '}').then(res => {
  183. // 再次查询位置表,对比当前样品列表 替换初始值为占用的样品位置id
  184. let findPositionAgain = `select id_,shi_fou_liu_yang_,shou_yang_ri_qi_ from t_mjypcfwz where find_in_set(shou_yang_ri_qi_,'${allUUIDStr}')`
  185. repostCurd('sql', findPositionAgain).then(res => {
  186. const { data } = res.variables || []
  187. console.log('add_position_res',data)
  188. data.forEach(item=>{
  189. let ypIndex = ypInfoList.findIndex(i => i.biao_zhi_uuid_ === item.shou_yang_ri_qi_)
  190. if(ypIndex != -1){
  191. item.shi_fou_liu_yang_ === '否'?ypInfoList[ypIndex].shou_yang_wei_zhi = item.id_ : ypInfoList[ypIndex].liu_yang_wei_zhi_ = item.id_
  192. }
  193. })
  194. // 所有数据整理完毕 开始封装对象😊
  195. ypInfoList.forEach(item=>{
  196. // 3、整理样品登记表数据(更新样品登记表)
  197. let ypdjbObj = {
  198. where:{
  199. yang_pin_bian_hao:item.yang_pin_bian_hao
  200. },
  201. param:{
  202. shou_yang_wei_zhi:item.shou_yang_wei_zhi || '',
  203. liu_yang_wei_zhi_:item.liu_yang_wei_zhi_ || '',
  204. jie_yang_shu_lian:item.jie_yang_shu_lian,
  205. jie_yang_zhuang_t:"已确认"
  206. },
  207. }
  208. // 4、整理样品表数据(更新样品表)
  209. let ypbObj = {
  210. where:{
  211. id_:item.id_
  212. },
  213. param:{
  214. cun_fang_wei_zhi_:item.shou_yang_wei_zhi || '',
  215. liu_yang_cun_fang:item.liu_yang_wei_zhi_ || '',
  216. jie_yang_zhuang_t:"已确认"
  217. },
  218. }
  219. // 整理任务分配表数据
  220. let taskItem = {
  221. yang_pin_bian_hao: item.yang_pin_bian_hao, // 取对应的样品编号
  222. yang_pin_ming_che : item.yang_pin_ming_che, // 对应的样品名称
  223. yang_pin_dai_ci_ : item.dai_ci_ , // 对应的样品代次
  224. yang_pin_pi_hao_ : item.pi_hao_, // 对应的样品批号
  225. yang_pin_shu_lian : item.yang_pin_zong_shu, // 对应的样品数量
  226. bug_ri_qi_ : item.song_yang_ri_qi_, // 对应的送样日期
  227. cun_fang_wei_zhi_ : item.shou_yang_wei_zhi,
  228. wei_tuo_wai_jian_ : item.wai_jian_ , // 检测申请单id
  229. he_tong_wai_jian_ : item.he_tong_bian_hao_, //合同id
  230. song_yang_ri_qi_ : item.biao_zhi_uuid_, // 收样日期
  231. wei_tuo_ren_ : item.lian_xi_ren_ , // 委托人
  232. bao_gao_jian_ce_s : currentTime, // 检测时间
  233. zhan_shi_biao_wai : item.ye_mian_zong_zhua,
  234. zhuang_tai_ : "任务待分配" , // 状态
  235. yang_pin_bei_zhu_ : item.bei_zhu_, // 样品备注
  236. shi_fou_jia_ji_ : item.fu_kuan_fang_shi_ ,// 2023-2-24吴懿要加的
  237. wu_jun_shi_fou_ch : item.fu_he_yuan_ // 2023-3-6 王嘎嘎加
  238. }
  239. // ypbForeignKeyList.push('{"id_":"'+item.wai_jian_+'"}')
  240. // zsbIdList.push('{"shen_qing_id_":"' + item.ye_mian_zong_zhua + '"}')
  241. ypbForeignKeyList.push({id_:item.wai_jian_})
  242. zsbIdList.push({shen_qing_id_:item.ye_mian_zong_zhua})
  243. ypdjbList.push(ypdjbObj)
  244. ypbList.push(ypbObj)
  245. taskList.push(taskItem)
  246. })
  247. const ypbForeignKeyFilterList = [...new Set(ypbForeignKeyList)]
  248. const zsbIdFilterList = [...new Set(zsbIdList)] // 这步因上面存储的是对象,所以去重不了,后续优化
  249. console.log("样品外键List",ypbForeignKeyFilterList)
  250. console.log("展示表主键List",zsbIdFilterList)
  251. let ypdjbParams = {
  252. tableName: "t_mjypdjb",
  253. updList: ypdjbList
  254. }
  255. let ypbParams = {
  256. tableName: "t_mjypb",
  257. updList: ypbList
  258. }
  259. // 5、更新t_mjwtsqb -> "zhuang_tai_":"已完成" , "jian_ce_kai_shi_s"
  260. let up_Wtsqb_Obj = {
  261. tableName:"t_mjwtsqb",
  262. paramWhere:ypbForeignKeyFilterList,
  263. paramCond:{
  264. zhuang_tai_: "已完成",
  265. jian_ce_kai_shi_s:currentTime
  266. }
  267. }
  268. // 6、更新t_mjwtzsb -> "zhuang_tai_":"任务分配进行中" 需不需要再根据样品编号比对,因为此表同个单的id是一样的
  269. let up_zsb_Obj = {
  270. tableName:"t_mjwtzsb",
  271. paramWhere:zsbIdFilterList,
  272. paramCond:{
  273. zhuang_tai_: "任务分配进行中"
  274. }
  275. }
  276. // 7、添加 t_rwfpb 开启任务流程(遍历样品表开任务分配流程,一个样品对应多个检测时,循环开启)
  277. let add_task_Obj = {
  278. tableName: "t_rwfpb",
  279. paramWhere:taskList,
  280. defKey:"Process_04tgh24",
  281. formKey:"mjrwfp"
  282. }
  283. console.log("add_taskList",add_task_Obj)
  284. repostCurd('add', JSON.stringify(add_task_Obj)).then(res=>{
  285. console.log('up_委托单',up_Wtsqb_Obj)
  286. repostCurd('updates', JSON.stringify(up_Wtsqb_Obj)).then(res=>{
  287. console.log('up_展示表',up_zsb_Obj)
  288. repostCurd('updates', JSON.stringify(up_zsb_Obj))
  289. }).catch(error =>{
  290. console.log(error)
  291. this.handleAnySituation(true,"委托单数据修改失败!请勿关闭此页面,联系开发人员解决",'error')
  292. })
  293. console.log('up_ypb',ypbParams)
  294. repostCurd('updatesByWhere', JSON.stringify(ypbParams)).then(res=>{
  295. console.log('up_ypdjb',ypdjbParams)
  296. repostCurd('updatesByWhere', JSON.stringify(ypdjbParams)).then(re=>{
  297. this.handleAnySituation(true,"样品成功接收,正在开启任务分配!",'success')
  298. }).catch(error =>{
  299. console.log(error)
  300. this.handleAnySituation(true,"样品登记表数据添加失败!请勿关闭此页面,联系开发人员解决",'error')
  301. })
  302. })
  303. })
  304. })
  305. })
  306. })
  307. }).catch(_ => {});
  308. }
  309. },
  310. handleAnySituation(callBackBool,msg,type){
  311. this.$emit('callback', callBackBool)
  312. this.visable = false
  313. this.$message({
  314. message: msg,
  315. type: type
  316. })
  317. this.closeDialog();
  318. },
  319. /* 去除指定行数据 使用过滤器filter过滤指定行号数据 */
  320. deleteData(val) {
  321. this.listData = this.listData.filter((data) => {
  322. return data.id_ != val
  323. })
  324. },
  325. unique(arr) { // 可以去重对象的
  326. return arr.filter((item, index) => {
  327. return arr.indexOf(item, 0) === index;
  328. });
  329. },
  330. /* 关闭*/
  331. remRedar() {
  332. this.visible = false // 列表隐藏
  333. this.listData = [] // 清空列表数据
  334. this.redar = false // 扫码图标隐藏
  335. this.$emit('scanOff', false)
  336. }
  337. }
  338. }