actionplanDetails.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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.setData({
  35. append: [],
  36. })
  37. this.init()
  38. },
  39. showDetil() {
  40. this.setData({
  41. isShowDetil: !this.data.isShowDetil
  42. })
  43. },
  44. showText() {
  45. this.setData({
  46. isShowText: !this.data.isShowText
  47. })
  48. },
  49. deleteImg(e) {
  50. if (this.data.append.length == 1) {
  51. this.setData({
  52. append: []
  53. })
  54. return false
  55. }
  56. this.setData({
  57. append: this.data.append.splice(e.target.dataset.index-1, 1)
  58. })
  59. },
  60. // 返回时刷新列表数据
  61. routeBack() {
  62. let query = getCache('actionplanList');
  63. if (query) {
  64. let data = {
  65. know: this.data.knowFrom,
  66. apList: this.data.apList,
  67. packId: this.data.packId,
  68. assessID: this.data.assessID,
  69. recordMemberIds: query.recordMemberIds ? query.recordMemberIds : []
  70. };
  71. setCache('actionplanList', data);
  72. }
  73. },
  74. save() {
  75. // 保存
  76. if (this.data.knowFrom == 'action') {
  77. // 执行计划
  78. this.saveAction('api/per/package/action');
  79. } else if (this.data.knowFrom == 'admnin') {
  80. // 管理记录
  81. this.saveAction('api/per/package/track');
  82. }
  83. },
  84. saveAction(urls) {
  85. if (this.data.bootBool) {
  86. return;
  87. }
  88. // 执行计划
  89. if (!this.data.titValue && this.data.titValue == '') {
  90. app.globalData.showToast('请输入标题');
  91. return;
  92. }
  93. let data = {
  94. package_employee_id: this.data.packId,
  95. index_id: this.data.apDetails.id,
  96. title: this.data.titValue,
  97. remark: this.data.messageVal,
  98. dimension_xb: this.data.planIndex[0],
  99. // images: JSON.stringify(images),
  100. append: JSON.stringify(this.data.append), //附件
  101. // appendName: '' //附件名称
  102. };
  103. this.setData({
  104. bootBool: true
  105. })
  106. app.$post(urls, data)
  107. .then(res => {
  108. if (res.data.code == 1) {
  109. app.globalData.showToast('提交成功');
  110. this.setData({
  111. titValue: '',
  112. messageVal: '',
  113. append: [],
  114. })
  115. this.employeeDet();
  116. }
  117. setTimeout(() => {
  118. this.setData({
  119. bootBool: false
  120. })
  121. }, 1000);
  122. })
  123. },
  124. closeWt() {
  125. localStorage.setItem('isWt', true);
  126. this.isWt = false;
  127. },
  128. addThePlan(item) {
  129. if (!this.isShowAdd || this.has_finish) {
  130. return false
  131. }
  132. let data = {
  133. know: this.knowFrom,
  134. keys: JSON.stringify(item) || null,
  135. apList: JSON.stringify(this.apDetails),
  136. packId: this.packId,
  137. assessID: this.assessID,
  138. planIndex: this.planIndex[0] //维度下标
  139. };
  140. this.$setCache('addthePlan', data);
  141. // 添加
  142. this.$router.push({ name: 'addthePlan' });
  143. },
  144. bindTextAreaBlur: function (e) {
  145. this.setData({
  146. titValue: e.detail.value,
  147. });
  148. },
  149. bindTextAreaBlur2: function (e) {
  150. this.setData({
  151. messageVal: e.detail.value,
  152. });
  153. },
  154. employeeDet() {
  155. let params = {
  156. id: this.data.packId
  157. };
  158. app.$get('api/per/package/employee/info', params).then(res => {
  159. if (res.data.code == 1) {
  160. let data = res.data.data;
  161. this.setData({
  162. has_finish: data.has_finish
  163. })
  164. let dimension = data.dimension[this.data.planIndex[0]].index[this.data.planIndex[1]];
  165. this.setData({
  166. apList: JSON.stringify(data.dimension)
  167. })
  168. if (this.data.knowFrom == 'action') {
  169. // 执行计划
  170. if (dimension.schedule) {
  171. dimension.schedule.map(item => {
  172. if (app.globalData.usersList[item.employee_id]) {
  173. item.userName = app.globalData.usersList[item.employee_id] ? app.globalData.usersList[item.employee_id].name : ''
  174. }
  175. })
  176. this.setData({
  177. apdList: dimension.schedule
  178. })
  179. }
  180. } else if (this.data.knowFrom == 'admnin') {
  181. // 管理记录
  182. if (dimension.mamage_record) {
  183. dimension.mamage_record.map(item => {
  184. if (app.globalData.usersList[item.employee_id]) {
  185. item.userName = app.globalData.usersList[item.employee_id] ? app.globalData.usersList[item.employee_id].name : ''
  186. }
  187. })
  188. this.setData({
  189. apdList: dimension.mamage_record
  190. })
  191. }
  192. }
  193. }
  194. this.routeBack();
  195. })
  196. },
  197. init() {
  198. let query = this.data.query;
  199. let apList = JSON.parse(query.apList);
  200. this.setData({
  201. knowFrom: query.know,
  202. packId: query.packId,
  203. assessID: query.assessID,
  204. planIndex: apList.planIndex,
  205. apDetails: apList,
  206. })
  207. if (this.data.knowFrom == 'action') {
  208. if (this.data.assessID == app.globalData.userData.id) {
  209. this.setData({
  210. isShowAdd: true
  211. })
  212. }
  213. // 执行计划
  214. this.setData({
  215. detailsTIt: '执行计划'
  216. })
  217. } else if (this.data.knowFrom == 'admnin') {
  218. this.setData({//管理记录人判断
  219. isShowAdd: apList.isOperation
  220. })
  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. showImg(e) {
  247. let item = e.target.dataset.item
  248. app.$get('api/drive/grant',{file_id:item.fileId}).then(res => {
  249. dd.previewFileInDingTalk({
  250. corpId: app.globalData.corpId,
  251. spaceId:item.spaceId,
  252. fileId: item.fileId,
  253. fileName: item.fileName,
  254. fileSize: item.fileSize,
  255. fileType: item.fileType,
  256. })
  257. })
  258. },
  259. openDetail(e) {
  260. let item = e.target.dataset.item
  261. if (!this.data.isShowAdd || this.data.has_finish) {
  262. return false
  263. }
  264. let data = {
  265. know: this.data.knowFrom,
  266. keys: JSON.stringify(item) || null,
  267. apList: JSON.stringify(this.data.apDetails),
  268. packId: this.data.packId,
  269. assessID: this.data.assessID,
  270. planIndex: this.data.planIndex[0] //维度下标
  271. };
  272. setCache('addthePlan', data);
  273. dd.navigateTo({
  274. url: `../addthePlan/addthePlan`
  275. })
  276. },
  277. //图片选择
  278. openImg(e) {
  279. let append = this.data.append;
  280. app.$get('api/drive/info').then(res => {
  281. let spaceId = res.data.data.space_id
  282. dd.uploadAttachmentToDingTalk({
  283. image: { multiple: true, compress: false, max: 5, spaceId: spaceId },
  284. space: { spaceId: spaceId, isCopy: 1, max: 5 },
  285. file: { spaceId: spaceId, max: 5 },
  286. types: ["photo", "file", "space"],//PC端仅支持["photo","file","space"]
  287. success: (res) => {
  288. append.push(...res.data);
  289. that.setData({
  290. append: append
  291. })
  292. },
  293. fail: (err) => {
  294. }
  295. })
  296. })
  297. return false
  298. var files = that.data.img_fileList;
  299. if (files.length >= 3) {
  300. app.globalData.showToast("只能上传三张");
  301. return false;
  302. }
  303. dd.chooseImage({
  304. count: 1,
  305. success: (res) => {
  306. that.postImg(res.filePaths[0]);
  307. },
  308. });
  309. },
  310. postImg(img_url) {
  311. var files = that.data.img_fileList;
  312. dd.httpRequest({
  313. url: app.globalData.imgHttpUrl,
  314. method: 'POST',
  315. data: {
  316. md5: that.random_string(32),
  317. 'name': app.globalData.day
  318. },
  319. success: function (res) {
  320. if (app.globalData.userData.site_id) {
  321. var key = 'intesys/ddJx/' + app.globalData.userData.site_id + "/" + app.globalData.day + '/' + that.random_string(32) + '.png';
  322. } else {
  323. var key = 'intesys/ddJx/' + app.globalData.day + '/' + that.random_string(32) + '.png';
  324. }
  325. var obj = res.data.data;
  326. dd.uploadFile({
  327. url: app.globalData.ALIOSS_URL,
  328. fileType: 'image',
  329. fileName: 'file',
  330. filePath: img_url,
  331. formData: {
  332. key: key,
  333. policy: obj.policy,
  334. OSSAccessKeyId: obj.accessid,
  335. success_action_status: 200,
  336. signature: obj.signature
  337. },
  338. success: (res) => {
  339. if (res.statusCode == 200) {
  340. if (files.length > 0) {
  341. files.push(app.globalData.ALIOSS_URL + '/' + key)
  342. } else {
  343. files = [app.globalData.ALIOSS_URL + '/' + key];
  344. }
  345. that.setData({
  346. img_fileList: files
  347. });
  348. app.globalData.showToast("已上传");
  349. }
  350. },
  351. fail: (err) => {
  352. console.log(err);
  353. }
  354. });
  355. },
  356. fail: function (res) {
  357. app.globalData.showToast("上传失败");
  358. }
  359. })
  360. },
  361. random_string(len) {
  362. len = len || 32
  363. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  364. var maxPos = chars.length
  365. var pwd = ''
  366. for (let i = 0; i < len; i++) {
  367. pwd += chars.charAt(Math.floor(Math.random() * maxPos))
  368. }
  369. return pwd
  370. },
  371. });