resultValueEntry.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. var app = getApp();
  2. var that;
  3. import moment from 'moment' // 时间库
  4. Page({
  5. data: {
  6. tabIndex: 1,//条件选择
  7. list: [],
  8. page: 1,
  9. id: '',
  10. packageName: '',
  11. },
  12. onLoad(e) {
  13. that = this;
  14. dd.setNavigationBar({ title: "结果值录入" });
  15. this.setData({
  16. id: e.id,
  17. packageName: e.tel,
  18. })
  19. this.getPackageDtail()
  20. },
  21. tabAction(e) {
  22. let index = e.target.dataset.index
  23. this.setData({
  24. tabIndex: index,
  25. })
  26. this.getPackageDtail()
  27. },
  28. bindTextAreaBlur(e) {
  29. this.setData({
  30. [`rvenotList[${e.target.dataset.index}].result`]: e.detail.value,
  31. });
  32. },
  33. deleteImg(e) {
  34. let item = e.target.dataset.item
  35. let index = e.target.dataset.index
  36. let indexT = e.target.dataset.indexT
  37. if (item.length == 1) {
  38. this.setData({
  39. [`rvenotList[${index}].result_file.append`]: [],
  40. })
  41. return false
  42. }
  43. item.splice(indexT, 1)
  44. this.setData({
  45. [`rvenotList[${index}].result_file.append`]: item,
  46. })
  47. console.log(item,index,indexT,this.data.rvenotList[index])
  48. },
  49. showImg(e) {
  50. let item = e.target.dataset.item
  51. app.$get('api/drive/grant', { file_id: item.fileId }).then(res => {
  52. dd.previewFileInDingTalk({
  53. corpId: app.globalData.corpId,
  54. spaceId: item.spaceId,
  55. fileId: item.fileId,
  56. fileName: item.fileName,
  57. fileSize: item.fileSize,
  58. fileType: item.fileType,
  59. })
  60. })
  61. },
  62. //图片选择
  63. openImg(e) {
  64. let index = e.target.dataset.index
  65. let append = this.data.rvenotList[index].result_file.append;
  66. app.$get('api/drive/info').then(res => {
  67. let spaceId = res.data.data.space_id.toString()
  68. dd.uploadAttachmentToDingTalk({
  69. image: { multiple: true, compress: false, max: 5, spaceId: spaceId },
  70. space: { spaceId: spaceId, isCopy: 1, max: 5 },
  71. file: { spaceId: spaceId, max: 5 },
  72. types: ["photo", "file", "space"],//PC端仅支持["photo","file","space"]
  73. success: (res) => {
  74. console.log(res);
  75. append.push(...res.data);
  76. that.setData({
  77. [`rvenotList[${e.target.dataset.index}].result_file.append`]: append,
  78. });
  79. },
  80. fail: (err) => {
  81. console.log(err)
  82. }
  83. })
  84. })
  85. },
  86. // 提交
  87. save(e) {
  88. let num = e.target.dataset.index
  89. let isLr = false;
  90. let data = {
  91. id: this.data.id, // 个人考核包ID
  92. cache: num, // 是否暂存 1 是 0 否(提交)
  93. result_info: '' // 结果值信息
  94. };
  95. let result_info = [];
  96. this.data.rvenotList.some(item => {
  97. if(item.type==1){
  98. if (item.result) {
  99. result_info.push({
  100. result: item.result, // 单项目结果值
  101. dimension_key: item.message.dimension_key, // 维度索引
  102. index_key: item.message.index_key, // 指标索引
  103. index_id: item.id, // 指标ID
  104. result_file: item.result_file
  105. });
  106. isLr = true;
  107. }
  108. }else{
  109. // if (item.result_file.append.length > 0) {
  110. result_info.push({
  111. result: item.result, // 单项目结果值
  112. dimension_key: item.message.dimension_key, // 维度索引
  113. index_key: item.message.index_key, // 指标索引
  114. index_id: item.id, // 指标ID
  115. result_file: item.result_file
  116. });
  117. isLr = true;
  118. // }
  119. }
  120. });
  121. if (!isLr) {
  122. app.globalData.showToast('至少输入一项结果值');
  123. return false;
  124. }
  125. data.result_info = JSON.stringify(result_info);
  126. if (this.data.bootBool) {
  127. return;
  128. }
  129. this.setData({
  130. bootBool: true
  131. })
  132. app.$post('api/per/package/record_result', data)
  133. .then(res => {
  134. this.getPackageDtail();
  135. setTimeout(() => {
  136. app.globalData.showToast(num == '1' ? '暂存成功' : '提交成功');
  137. this.setData({
  138. bootBool: false
  139. })
  140. }, 1000);
  141. })
  142. },
  143. getPackageDtail() {
  144. app.$get2('api/per/package/employee/info', { id: this.data.id }).then(res => {
  145. let data = res.data.data;
  146. let dimension = data.dimension;
  147. let relevance_employee = data.relevance_employee;
  148. dimension.forEach((item, index) => {
  149. if (item.index.length > 0) {
  150. item.index.forEach((item2, index2) => {
  151. item2.wdName = item.name;
  152. item2.userName = relevance_employee.name;
  153. item2.userId = relevance_employee.id;
  154. item2.dept_list = relevance_employee.dept_list;
  155. item2.dil = [
  156. {
  157. lab: '考核标准',
  158. prop: item2.per_remark ? item2.per_remark : null
  159. },
  160. { lab: '目标值', prop: item2.target ? item2.target : null },
  161. { lab: '权重%', prop: item2.weight ? item2.weight : null },
  162. { lab: '备注', prop: item2.remark ? item2.remark : null }
  163. ];
  164. });
  165. }
  166. });
  167. let flow = data.flow;
  168. let list = []; // 结果值录入集合
  169. flow.forEach(item => {
  170. if (item.code == 'result_value') {
  171. item.target.forEach(item2 => {
  172. if (item2.employee_id == app.globalData.userData.id) {
  173. list = item2.list;
  174. // status = item2.status;
  175. }
  176. });
  177. }
  178. });
  179. let statusList = []; // 已录入指标
  180. let noStatusList = []; // 未录入指标
  181. list.forEach(item => {
  182. if (item.status == 2) {
  183. dimension[item.dimension_key].index[item.index_key].message = item;
  184. statusList.push(dimension[item.dimension_key].index[item.index_key]);
  185. }
  186. if (item.status == 1) {
  187. dimension[item.dimension_key].index[item.index_key].message = item;
  188. if (item.result_cache) {
  189. // 是否有暂存的数据有就显示出来
  190. dimension[item.dimension_key].index[item.index_key].result = item.result_cache;
  191. dimension[item.dimension_key].index[item.index_key].result_file = item.result_file;
  192. }
  193. noStatusList.push(dimension[item.dimension_key].index[item.index_key]);
  194. }
  195. });
  196. this.setData({
  197. statusList: statusList,
  198. noStatusList: noStatusList,
  199. })
  200. if (this.data.tabIndex == 1) {
  201. this.setData({
  202. rvenotList: this.data.noStatusList
  203. })
  204. } else if (this.data.tabIndex == 2) {
  205. this.setData({
  206. rvenotList: this.data.statusList
  207. })
  208. }
  209. this.setData({
  210. age: { num1: noStatusList.length, num2: statusList.length }
  211. })
  212. })
  213. }
  214. });