addthePlan.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. },
  32. onLoad() {
  33. that = this;
  34. dd.setNavigationBar({ title: "编辑管理记录" });
  35. },
  36. onShow() {
  37. this.setData({
  38. rout: getCache('addthePlan')
  39. })
  40. this.init()
  41. },
  42. showDetil() {
  43. this.setData({
  44. isShowDetil: !this.data.isShowDetil
  45. })
  46. },
  47. showImg(e) {
  48. let img = e.target.dataset.img
  49. dd.previewImage({
  50. current: 0,
  51. urls: [img],
  52. });
  53. },
  54. deleteList() {
  55. dd.confirm({
  56. title: this.data.knowFrom == 'action' ? '删除计划' : '删除记录',
  57. content: '确认删除' + this.data.detailsTIt + ' :' + this.data.titValue + '',
  58. confirmButtonText: '取消',
  59. cancelButtonText: '确定',
  60. success: (result) => {
  61. if (result.confirm) {
  62. if (this.data.knowFrom == 'action') {
  63. // 执行计划
  64. this.deLists('api/per/package/action/del', 'action');
  65. } else if (this.data.knowFrom == 'admnin') {
  66. // 管理记录
  67. this.deLists('api/per/package/track/del', 'admnin');
  68. }
  69. }
  70. },
  71. });
  72. },
  73. deLists(urls, name) {
  74. let data = {
  75. package_employee_id: this.data.packId,
  76. index_id: this.data.apDetails.id,
  77. dimension_xb: this.data.planIndex
  78. };
  79. if (name == 'action') {
  80. data.action_id = this.data.keyszb.id;
  81. } else if (name == 'admnin') {
  82. if (this.data.keyszb.employee_id != app.globalData.userData.id) {
  83. app.globalData.showToast('不能删除其他管理者的管理记录!');
  84. return false;
  85. }
  86. data.track_id = this.data.keyszb.id;
  87. }
  88. app.$post(urls, data).then(res => {
  89. if (res.data.code == 1) {
  90. app.globalData.showToast('删除成功');
  91. this.routerBak();
  92. }
  93. });
  94. },
  95. save() {
  96. // 保存
  97. if (this.data.knowFrom == 'action') {
  98. // 执行计划
  99. this.saveAction('api/per/package/action');
  100. } else if (this.data.knowFrom == 'admnin') {
  101. // 管理记录
  102. this.saveAction('api/per/package/track');
  103. }
  104. },
  105. routerBak() {
  106. dd.navigateBack({
  107. delta: 1
  108. })
  109. },
  110. saveAction(urls) {
  111. if (this.data.bootBool) {
  112. return;
  113. }
  114. // 执行计划
  115. if (!this.data.titValue && this.data.titValue == '') {
  116. app.globalData.showToast('请输入标题');
  117. return;
  118. }
  119. let images = [];
  120. this.data.img_fileList.forEach(item => {
  121. let str = item.split("/")
  122. images.push(
  123. { name: str[str.length - 1], url: item }
  124. )
  125. })
  126. let data = {
  127. package_employee_id: this.data.packId,
  128. index_id: this.data.apDetails.id,
  129. title: this.data.titValue,
  130. remark: this.data.messageVal,
  131. dimension_xb: this.data.planIndex,
  132. images: JSON.stringify(images),
  133. append: '', //附件
  134. appendName: '' //附件名称
  135. };
  136. if (this.data.arrlist) {
  137. if (this.data.knowFrom == 'admnin') {
  138. if (this.data.keyszb.employee_id != app.globalData.userData.id) {
  139. app.globalData.showToast('不能编辑其他管理者的管理记录!');
  140. return false;
  141. }
  142. data.track_id = this.data.keyszb.id;
  143. } else {
  144. data.action_id = this.data.keyszb.id;
  145. }
  146. }
  147. this.setData({
  148. bootBool: true
  149. })
  150. app.$post(urls, data)
  151. .then(res => {
  152. if (res.data.code == 1) {
  153. app.globalData.showToast('提交成功');
  154. this.routerBak();
  155. }
  156. })
  157. .finally(() => {
  158. setTimeout(() => {
  159. this.setData({
  160. bootBool: false
  161. })
  162. }, 1000);
  163. });
  164. },
  165. bindTextAreaBlur: function (e) {
  166. this.setData({
  167. titValue: e.detail.value,
  168. });
  169. },
  170. bindTextAreaBlur2: function (e) {
  171. this.setData({
  172. messageVal: e.detail.value,
  173. });
  174. },
  175. deleteImg(e) {
  176. if (this.data.img_fileList.length == 1) {
  177. this.setData({
  178. img_fileList: []
  179. })
  180. return false
  181. }
  182. this.setData({
  183. img_fileList: this.data.img_fileList.splice(e.target.dataset.index, 1)
  184. })
  185. },
  186. init() {
  187. let rout = this.data.rout;
  188. this.setData({
  189. planIndex: rout.planIndex,
  190. assessID: rout.assessID,
  191. keyszb: JSON.parse(rout.keys),
  192. })
  193. if (this.data.keyszb) {
  194. this.setData({
  195. arrlist: true,
  196. titValue: this.data.keyszb.title,
  197. messageVal: this.data.keyszb.remark,
  198. appendObj: {
  199. append: this.data.keyszb.append,
  200. append_name: this.data.keyszb.append_name,
  201. }
  202. })
  203. let images = this.data.keyszb.images;
  204. let img_fileList = [];
  205. if (images.length > 0) {
  206. images.forEach(item => {
  207. img_fileList.push(item.url);
  208. })
  209. }
  210. this.setData({
  211. img_fileList: img_fileList
  212. })
  213. } else {
  214. this.setData({
  215. arrlist: false
  216. })
  217. }
  218. this.setData({
  219. knowFrom: rout.know
  220. })
  221. let apList = JSON.parse(rout.apList);
  222. this.setData({
  223. apDetails: apList,
  224. packId: rout.packId
  225. })
  226. if (this.data.knowFrom == 'action') {
  227. if (this.data.assessID == app.globalData.userData.id) {
  228. this.setData({
  229. isShowAdd: true
  230. })
  231. }
  232. // 执行计划
  233. this.setData({
  234. detailsTIt: '执行计划'
  235. })
  236. } else if (this.data.knowFrom == 'admnin') {
  237. this.setData({
  238. isShowAdd: apList.isOperation, //管理记录人判断
  239. })
  240. // this.$getEmployeeAll()[this.assessID].employee_detail.superior_list.some(item => {
  241. // // 判断被考核人的上级是否包含登录者
  242. // if (item.id == this.$getUserData_jx().id) {
  243. // this.isShowAdd = true;
  244. // return true;
  245. // }
  246. // });
  247. if (app.globalData.userData.is_creator == 1) {
  248. // 如果是创始人也可以操作
  249. this.setData({
  250. isShowAdd: true,
  251. })
  252. }
  253. if (app.getPermis(3)) {
  254. // 如果是子管理员并且管理范围权限为“全公司”
  255. this.setData({
  256. isShowAdd: true,
  257. })
  258. }
  259. // 管理记录
  260. this.setData({
  261. detailsTIt: '管理记录',
  262. })
  263. }
  264. },
  265. //图片选择
  266. openImg(e) {
  267. var files = that.data.img_fileList;
  268. if (files.length >= 3) {
  269. app.globalData.showToast("只能上传三张");
  270. return false;
  271. }
  272. dd.chooseImage({
  273. count: 1,
  274. success: (res) => {
  275. that.postImg(res.filePaths[0]);
  276. },
  277. });
  278. },
  279. postImg(img_url) {
  280. var files = that.data.img_fileList;
  281. dd.httpRequest({
  282. url: app.globalData.imgHttpUrl,
  283. method: 'POST',
  284. data: {
  285. md5: that.random_string(32),
  286. 'name': app.globalData.day
  287. },
  288. success: function (res) {
  289. if (app.globalData.userData.site_id) {
  290. var key = 'intesys/ddJx/' + app.globalData.userData.site_id + "/" + app.globalData.day + '/' + that.random_string(32) + '.png';
  291. } else {
  292. var key = 'intesys/ddJx/' + app.globalData.day + '/' + that.random_string(32) + '.png';
  293. }
  294. var obj = res.data.data;
  295. dd.uploadFile({
  296. url: app.globalData.ALIOSS_URL,
  297. fileType: 'image',
  298. fileName: 'file',
  299. filePath: img_url,
  300. formData: {
  301. key: key,
  302. policy: obj.policy,
  303. OSSAccessKeyId: obj.accessid,
  304. success_action_status: 200,
  305. signature: obj.signature
  306. },
  307. success: (res) => {
  308. if (res.statusCode == 200) {
  309. if (files.length > 0) {
  310. files.push(app.globalData.ALIOSS_URL + '/' + key)
  311. } else {
  312. files = [app.globalData.ALIOSS_URL + '/' + key];
  313. }
  314. that.setData({
  315. img_fileList: files
  316. });
  317. app.globalData.showToast("已上传");
  318. }
  319. },
  320. fail: (err) => {
  321. console.log(err);
  322. }
  323. });
  324. },
  325. fail: function (res) {
  326. app.globalData.showToast("上传失败");
  327. }
  328. })
  329. },
  330. random_string(len) {
  331. len = len || 32
  332. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  333. var maxPos = chars.length
  334. var pwd = ''
  335. for (let i = 0; i < len; i++) {
  336. pwd += chars.charAt(Math.floor(Math.random() * maxPos))
  337. }
  338. return pwd
  339. },
  340. });