addthePlan.js 10 KB

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