actionplanDetails.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. var app = getApp();
  2. var that;
  3. import { returnStr, setCache, getCache, _debounce, getRole } from '../../../utils/util'
  4. Page({
  5. data: {
  6. detailsshow: false,
  7. apdList: [],
  8. detailsTIt: '',
  9. apDetails: {},
  10. apList: [],
  11. knowFrom: '',
  12. packId: 0, // 记录id
  13. assessID: 0, // 记录人
  14. planIndex: [], // 维度下标,指标下标
  15. isShowAdd: false, // 是否显示添加按钮
  16. isWt: false,
  17. titValue: '', // 执行计划名
  18. messageVal: '', // 备注
  19. bootBool: false,// 防止多次请求
  20. has_finish: 0,
  21. // 上传图标与附件
  22. img_fileList: [], // 图片附件
  23. isShowText: false,
  24. isShowDetil: false,//显示详情
  25. append: [],
  26. },
  27. onLoad() {
  28. that = this;
  29. },
  30. onShow() {
  31. this.setData({
  32. query: getCache('actionplanDetails')
  33. })
  34. this.init()
  35. },
  36. showDetil() {
  37. this.setData({
  38. isShowDetil: !this.data.isShowDetil
  39. })
  40. },
  41. showText() {
  42. this.setData({
  43. isShowText: !this.data.isShowText
  44. })
  45. },
  46. deleteImg(e) {
  47. if (this.data.append.length == 1) {
  48. this.setData({
  49. append: []
  50. })
  51. return false
  52. }
  53. let append = this.data.append;
  54. append.splice(e.target.dataset.index, 1)
  55. this.setData({
  56. append: append
  57. })
  58. },
  59. // 返回时刷新列表数据
  60. routeBack() {
  61. let query = getCache('actionplanList');
  62. if (query) {
  63. let data = {
  64. know: this.data.knowFrom,
  65. apList: this.data.apList,
  66. packId: this.data.packId,
  67. assessID: this.data.assessID,
  68. recordMemberIds: query.recordMemberIds ? query.recordMemberIds : []
  69. };
  70. setCache('actionplanList', data);
  71. }
  72. },
  73. save() {
  74. // 保存
  75. if (this.data.knowFrom == 'action') {
  76. // 执行计划
  77. this.saveAction('api/per/package/action');
  78. } else if (this.data.knowFrom == 'admnin') {
  79. // 管理记录
  80. this.saveAction('api/per/package/track');
  81. }
  82. },
  83. saveAction(urls) {
  84. if (this.data.bootBool) {
  85. return;
  86. }
  87. // 执行计划
  88. if (!this.data.titValue && this.data.titValue == '') {
  89. app.globalData.showToast('请输入标题');
  90. return;
  91. }
  92. let data = {
  93. package_employee_id: this.data.packId,
  94. index_id: this.data.apDetails.id,
  95. title: this.data.titValue,
  96. remark: this.data.messageVal,
  97. dimension_xb: this.data.planIndex[0],
  98. // images: JSON.stringify(images),
  99. append: JSON.stringify(this.data.append), //附件
  100. // appendName: '' //附件名称
  101. };
  102. this.setData({
  103. bootBool: true
  104. })
  105. app.$post(urls, data).then(res => {
  106. if (res.data.code == 1) {
  107. app.globalData.showToast('提交成功');
  108. this.setData({
  109. titValue: '',
  110. messageVal: '',
  111. append: [],
  112. })
  113. this.employeeDet();
  114. }
  115. })
  116. setTimeout(() => {
  117. this.setData({
  118. bootBool: false
  119. })
  120. }, 1000);
  121. },
  122. closeWt() {
  123. localStorage.setItem('isWt', true);
  124. this.isWt = false;
  125. },
  126. addThePlan(item) {
  127. if (!this.isShowAdd || this.has_finish) {
  128. return false
  129. }
  130. let data = {
  131. know: this.knowFrom,
  132. keys: JSON.stringify(item) || null,
  133. apList: JSON.stringify(this.apDetails),
  134. packId: this.packId,
  135. assessID: this.assessID,
  136. planIndex: this.planIndex[0] //维度下标
  137. };
  138. this.$setCache('addthePlan', data);
  139. // 添加
  140. this.$router.push({ name: 'addthePlan' });
  141. },
  142. bindTextAreaBlur: function (e) {
  143. this.setData({
  144. titValue: e.detail.value,
  145. });
  146. },
  147. bindTextAreaBlur2: function (e) {
  148. this.setData({
  149. messageVal: e.detail.value,
  150. });
  151. },
  152. employeeDet() {
  153. let params = {
  154. id: this.data.packId
  155. };
  156. app.$get('api/per/package/employee/info', params).then(res => {
  157. if (res.data.code == 1) {
  158. let data = res.data.data;
  159. this.setData({
  160. has_finish: data.has_finish
  161. })
  162. let dimension = data.dimension[this.data.planIndex[0]].index[this.data.planIndex[1]];
  163. this.setData({
  164. apList: JSON.stringify(data.dimension)
  165. })
  166. if (this.data.knowFrom == 'action') {
  167. // 执行计划
  168. if (dimension.schedule) {
  169. dimension.schedule.map(item => {
  170. if (app.globalData.usersList[item.employee_id]) {
  171. item.userName = app.globalData.usersList[item.employee_id] ? app.globalData.usersList[item.employee_id].name : ''
  172. }
  173. })
  174. this.setData({
  175. apdList: dimension.schedule
  176. })
  177. }
  178. } else if (this.data.knowFrom == 'admnin') {
  179. // 管理记录
  180. if (dimension.mamage_record) {
  181. dimension.mamage_record.map(item => {
  182. if (app.globalData.usersList[item.employee_id]) {
  183. item.userName = app.globalData.usersList[item.employee_id] ? app.globalData.usersList[item.employee_id].name : ''
  184. }
  185. })
  186. this.setData({
  187. apdList: dimension.mamage_record
  188. })
  189. }
  190. }
  191. }
  192. this.routeBack();
  193. })
  194. },
  195. init() {
  196. let query = this.data.query;
  197. let apList = JSON.parse(query.apList);
  198. this.setData({
  199. knowFrom: query.know,
  200. packId: query.packId,
  201. assessID: query.assessID,
  202. planIndex: apList.planIndex,
  203. apDetails: apList,
  204. append:this.data.append.length>0? this.data.append:[],
  205. })
  206. if (this.data.knowFrom == 'action') {
  207. if (this.data.assessID == app.globalData.userData.id) {
  208. this.setData({
  209. isShowAdd: true
  210. })
  211. }
  212. // 执行计划
  213. this.setData({
  214. detailsTIt: '执行计划'
  215. })
  216. } else if (this.data.knowFrom == 'admnin') {
  217. this.setData({//管理记录人判断
  218. isShowAdd: apList.isOperation
  219. })
  220. this.getSuperior(query.assessID);
  221. // this.$getEmployeeAll()[this.assessID].employee_detail.superior_list.some(item => {
  222. // // 判断被考核人的上级是否包含登录者
  223. // if (item.id == this.$getUserData_jx().id) {
  224. // this.isShowAdd = true;
  225. // return true;
  226. // }
  227. // });
  228. if (app.globalData.userData.is_creator == 1) {
  229. // 如果是创始人也可以操作
  230. this.setData({
  231. isShowAdd: true
  232. })
  233. }
  234. if (app.getPermis(3)) {
  235. // 如果是子管理员并且管理范围权限为“全公司”
  236. this.setData({
  237. isShowAdd: true
  238. })
  239. }
  240. this.setData({
  241. detailsTIt: '管理记录'
  242. })
  243. }
  244. this.employeeDet();
  245. },
  246. // 判断是否当前被考核人的上级
  247. getSuperior(id) {
  248. app.$get('api/per/user/manager_list', { id_code: app.returnCode(id) }).then(res => {
  249. let superiorList = res.data.data; //被考核人上级
  250. superiorList.some(item => {
  251. if (item.id == app.globalData.userData.id) {
  252. this.setData({
  253. isShowAdd: true
  254. })
  255. return true
  256. }
  257. })
  258. });
  259. },
  260. showImg(e) {
  261. let item = e.target.dataset.item
  262. app.$get('api/drive/grant', { file_id: item.fileId }).then(res => {
  263. dd.previewFileInDingTalk({
  264. corpId: app.globalData.corpId,
  265. spaceId: item.spaceId,
  266. fileId: item.fileId,
  267. fileName: item.fileName,
  268. fileSize: item.fileSize,
  269. fileType: item.fileType,
  270. })
  271. })
  272. },
  273. openDetail(e) {
  274. let item = e.target.dataset.item
  275. if (!this.data.isShowAdd || this.data.has_finish) {
  276. return false
  277. }
  278. let data = {
  279. know: this.data.knowFrom,
  280. keys: JSON.stringify(item) || null,
  281. apList: JSON.stringify(this.data.apDetails),
  282. packId: this.data.packId,
  283. assessID: this.data.assessID,
  284. planIndex: this.data.planIndex[0] //维度下标
  285. };
  286. setCache('addthePlan', data);
  287. dd.navigateTo({
  288. url: `../addthePlan/addthePlan`
  289. })
  290. },
  291. //图片选择
  292. openImg(e) {
  293. let append = this.data.append;
  294. app.$get('api/drive/info').then(res => {
  295. let spaceId = res.data.data.space_id.toString()
  296. dd.uploadAttachmentToDingTalk({
  297. image: { multiple: true, compress: false, max: 5, spaceId: spaceId },
  298. space: { spaceId: spaceId, isCopy: 1, max: 5 },
  299. file: { spaceId: spaceId, max: 5 },
  300. types: ["photo", "file", "space"],//PC端仅支持["photo","file","space"]
  301. success: (res) => {
  302. console.log(res);
  303. append.push(...res.data);
  304. that.setData({
  305. append: append
  306. })
  307. },
  308. fail: (err) => {
  309. console.log(err)
  310. }
  311. })
  312. })
  313. return false
  314. var files = that.data.img_fileList;
  315. if (files.length >= 3) {
  316. app.globalData.showToast("只能上传三张");
  317. return false;
  318. }
  319. dd.chooseImage({
  320. count: 1,
  321. success: (res) => {
  322. that.postImg(res.filePaths[0]);
  323. },
  324. });
  325. },
  326. postImg(img_url) {
  327. var files = that.data.img_fileList;
  328. dd.httpRequest({
  329. url: app.globalData.imgHttpUrl,
  330. method: 'POST',
  331. data: {
  332. md5: that.random_string(32),
  333. 'name': app.globalData.day
  334. },
  335. success: function (res) {
  336. if (app.globalData.userData.site_id) {
  337. var key = 'intesys/ddJx/' + app.globalData.userData.site_id + "/" + app.globalData.day + '/' + that.random_string(32) + '.png';
  338. } else {
  339. var key = 'intesys/ddJx/' + app.globalData.day + '/' + that.random_string(32) + '.png';
  340. }
  341. var obj = res.data.data;
  342. dd.uploadFile({
  343. url: app.globalData.ALIOSS_URL,
  344. fileType: 'image',
  345. fileName: 'file',
  346. filePath: img_url,
  347. formData: {
  348. key: key,
  349. policy: obj.policy,
  350. OSSAccessKeyId: obj.accessid,
  351. success_action_status: 200,
  352. signature: obj.signature
  353. },
  354. success: (res) => {
  355. if (res.statusCode == 200) {
  356. if (files.length > 0) {
  357. files.push(app.globalData.ALIOSS_URL + '/' + key)
  358. } else {
  359. files = [app.globalData.ALIOSS_URL + '/' + key];
  360. }
  361. that.setData({
  362. img_fileList: files
  363. });
  364. app.globalData.showToast("已上传");
  365. }
  366. },
  367. fail: (err) => {
  368. console.log(err);
  369. }
  370. });
  371. },
  372. fail: function (res) {
  373. app.globalData.showToast("上传失败");
  374. }
  375. })
  376. },
  377. random_string(len) {
  378. len = len || 32
  379. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  380. var maxPos = chars.length
  381. var pwd = ''
  382. for (let i = 0; i < len; i++) {
  383. pwd += chars.charAt(Math.floor(Math.random() * maxPos))
  384. }
  385. return pwd
  386. },
  387. });