addthePlan.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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)
  162. .then(res => {
  163. if (res.data.code == 1) {
  164. app.globalData.showToast('提交成功');
  165. this.routerBak();
  166. }
  167. setTimeout(() => {
  168. this.setData({
  169. bootBool: false
  170. })
  171. }, 1000);
  172. })
  173. },
  174. bindTextAreaBlur: function (e) {
  175. this.setData({
  176. titValue: e.detail.value,
  177. });
  178. },
  179. bindTextAreaBlur2: function (e) {
  180. this.setData({
  181. messageVal: e.detail.value,
  182. });
  183. },
  184. deleteImg(e) {
  185. if (this.data.append.length == 1) {
  186. this.setData({
  187. append: []
  188. })
  189. return false
  190. }
  191. this.setData({
  192. append: this.data.append.splice(e.target.dataset.index-1, 1)
  193. })
  194. },
  195. init() {
  196. let rout = this.data.rout;
  197. this.setData({
  198. planIndex: rout.planIndex,
  199. assessID: rout.assessID,
  200. keyszb: JSON.parse(rout.keys),
  201. })
  202. if (this.data.keyszb) {
  203. this.setData({
  204. arrlist: true,
  205. titValue: this.data.keyszb.title,
  206. messageVal: this.data.keyszb.remark,
  207. append: this.data.keyszb.append,
  208. })
  209. } else {
  210. this.setData({
  211. arrlist: false
  212. })
  213. }
  214. this.setData({
  215. knowFrom: rout.know
  216. })
  217. let apList = JSON.parse(rout.apList);
  218. this.setData({
  219. apDetails: apList,
  220. packId: rout.packId
  221. })
  222. if (this.data.knowFrom == 'action') {
  223. if (this.data.assessID == app.globalData.userData.id) {
  224. this.setData({
  225. isShowAdd: true
  226. })
  227. }
  228. // 执行计划
  229. this.setData({
  230. detailsTIt: '执行计划'
  231. })
  232. } else if (this.data.knowFrom == 'admnin') {
  233. this.setData({
  234. isShowAdd: apList.isOperation, //管理记录人判断
  235. })
  236. // this.$getEmployeeAll()[this.assessID].employee_detail.superior_list.some(item => {
  237. // // 判断被考核人的上级是否包含登录者
  238. // if (item.id == this.$getUserData_jx().id) {
  239. // this.isShowAdd = true;
  240. // return true;
  241. // }
  242. // });
  243. if (app.globalData.userData.is_creator == 1) {
  244. // 如果是创始人也可以操作
  245. this.setData({
  246. isShowAdd: true,
  247. })
  248. }
  249. if (app.getPermis(3)) {
  250. // 如果是子管理员并且管理范围权限为“全公司”
  251. this.setData({
  252. isShowAdd: true,
  253. })
  254. }
  255. // 管理记录
  256. this.setData({
  257. detailsTIt: '管理记录',
  258. })
  259. }
  260. },
  261. //图片选择
  262. openImg(e) {
  263. let append = this.data.append;
  264. app.$get('api/drive/info').then(res => {
  265. let spaceId = res.data.data.space_id
  266. dd.uploadAttachmentToDingTalk({
  267. image: { multiple: true, compress: false, max: 5, spaceId: spaceId },
  268. space: { spaceId: spaceId, isCopy: 1, max: 5 },
  269. file: { spaceId: spaceId, max: 5 },
  270. types: ["photo", "file", "space"],//PC端仅支持["photo","file","space"]
  271. success: (res) => {
  272. append.push(...res.data);
  273. that.setData({
  274. append: append
  275. })
  276. },
  277. fail: (err) => {
  278. }
  279. })
  280. })
  281. return false
  282. var files = that.data.img_fileList;
  283. if (files.length >= 3) {
  284. app.globalData.showToast("只能上传三张");
  285. return false;
  286. }
  287. dd.chooseImage({
  288. count: 1,
  289. success: (res) => {
  290. that.postImg(res.filePaths[0]);
  291. },
  292. });
  293. },
  294. postImg(img_url) {
  295. var files = that.data.img_fileList;
  296. dd.httpRequest({
  297. url: app.globalData.imgHttpUrl,
  298. method: 'POST',
  299. data: {
  300. md5: that.random_string(32),
  301. 'name': app.globalData.day
  302. },
  303. success: function (res) {
  304. if (app.globalData.userData.site_id) {
  305. var key = 'intesys/ddJx/' + app.globalData.userData.site_id + "/" + app.globalData.day + '/' + that.random_string(32) + '.png';
  306. } else {
  307. var key = 'intesys/ddJx/' + app.globalData.day + '/' + that.random_string(32) + '.png';
  308. }
  309. var obj = res.data.data;
  310. dd.uploadFile({
  311. url: app.globalData.ALIOSS_URL,
  312. fileType: 'image',
  313. fileName: 'file',
  314. filePath: img_url,
  315. formData: {
  316. key: key,
  317. policy: obj.policy,
  318. OSSAccessKeyId: obj.accessid,
  319. success_action_status: 200,
  320. signature: obj.signature
  321. },
  322. success: (res) => {
  323. if (res.statusCode == 200) {
  324. if (files.length > 0) {
  325. files.push(app.globalData.ALIOSS_URL + '/' + key)
  326. } else {
  327. files = [app.globalData.ALIOSS_URL + '/' + key];
  328. }
  329. that.setData({
  330. img_fileList: files
  331. });
  332. app.globalData.showToast("已上传");
  333. }
  334. },
  335. fail: (err) => {
  336. console.log(err);
  337. }
  338. });
  339. },
  340. fail: function (res) {
  341. app.globalData.showToast("上传失败");
  342. }
  343. })
  344. },
  345. random_string(len) {
  346. len = len || 32
  347. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  348. var maxPos = chars.length
  349. var pwd = ''
  350. for (let i = 0; i < len; i++) {
  351. pwd += chars.charAt(Math.floor(Math.random() * maxPos))
  352. }
  353. return pwd
  354. },
  355. });