微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
9.0 KiB

  1. // pages/bankDraft/add/add.js
  2. import * as UTIL from '../../../utils/util.js';
  3. import * as API from '../../../utils/API.js';
  4. let EVN_CONFIG = require('../../../env/env');
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. isIPX: app.globalData.isIPX,
  12. form:{
  13. eventTime: UTIL.formatDate(new Date()), //开票日期 必填
  14. remark: "",
  15. },
  16. showBtn:true,
  17. showEventTime:false,
  18. status:0,
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. let that = this
  25. //所属银行
  26. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'major_type', {method:'GET'}, {
  27. success: (res) => {
  28. this.setData({
  29. majorTypeOptions:res.data
  30. });
  31. }
  32. })
  33. let templateQueryParams = {
  34. // 分页
  35. type:'5'
  36. };
  37. UTIL.httpRequest(API.URL_GET_TEMPLATELIST , templateQueryParams, {
  38. success: (res) => {
  39. that.setData({
  40. approvalTemplateList:res.rows,
  41. ["form.approvalTemplateId"]:res.rows[0].id,
  42. ["form.approvalTemplateName"]:res.rows[0].name,
  43. })
  44. }
  45. })
  46. if(options.id!=null&&options.id!=""){
  47. this.setData({id:options.id})
  48. UTIL.httpRequest(API.URL_GET_MAJOREVENTGET + this.data.id, {method:'GET'}, {
  49. success: (res) => {
  50. console.log(res);
  51. if(res.data.auditStatus!='0'&&res.data.auditStatus!='2'){
  52. this.setData({'showBtn':false});
  53. }
  54. res.data.majorTypeText = UTIL.getTransform(res.data.majorType,that.data.majorTypeOptions);
  55. let op = that.data.approvalTemplateList.filter(function (e) { return e.id == res.data.approvalTemplateId; });
  56. res.data.approvalTemplateName = op[0].name;
  57. this.setData({'form':res.data})
  58. this.selectComponent('#hf_editor').setHtml(res.data.eventContent);
  59. this.selectComponent('#hf_editor2').setHtml(res.data.dzbty);
  60. this.selectComponent('#hf_editor3').setHtml(res.data.lwhsy);
  61. this.selectComponent('#hf_editor4').setHtml(res.data.dqyshsyhjy);
  62. this.selectComponent('#hf_editor5').setHtml(res.data.cydbhjy);
  63. this.selectComponent('#hf_editor6').setHtml(res.data.jcjggk);
  64. this.selectComponent('#hf_editor7').setHtml(res.data.ssqkgk);
  65. }
  66. })
  67. }else{
  68. this.onShow()
  69. }
  70. },
  71. onConfirmPickApproval(event) {
  72. console.log(event);
  73. var that = this;
  74. this.setData({
  75. ["form.showApprovalTemplateName"]: false,
  76. ["form.approvalTemplateName"]: event.detail.value.name,
  77. ["form.approvalTemplateId"]: event.detail.value.id,
  78. });
  79. },
  80. onConfirmEventTime(e){
  81. let data = this.getNewDate(new Date(e.detail.value));
  82. this.setData({'form.eventTime':data});
  83. },
  84. getHtml(e) {//从组件获取值
  85. this.setData({
  86. [e.currentTarget.dataset.name]:e.detail.content.html
  87. });
  88. },
  89. insertImage(e){ //图片上传插入示例
  90. wx.chooseMedia({
  91. count: 1,
  92. success: r => {
  93. // 本地测试图片插入
  94. // this.selectComponent('#hf_editor').insertSrc(res.tempFilePaths[0]);
  95. console.log(r.tempFiles[0]);
  96. wx.uploadFile({ //调用图片上传接口
  97. url: wx.getStorageSync('dressCode')+'/common/upload',
  98. filePath: r.tempFiles[0].tempFilePath,
  99. header: {
  100. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  101. },
  102. name: 'file',
  103. success: res => {
  104. console.log(111111);
  105. let imgUrl = JSON.parse(res.data).fileName
  106. this.selectComponent('#'+e.currentTarget.dataset.id).insertSrc(wx.getStorageSync('dressCode')+imgUrl);//调用组件insertSrc方法
  107. }
  108. })
  109. }
  110. })
  111. },
  112. getNewDate(date){
  113. //date是传过来的时间戳,注意需为13位,10位需*1000
  114. //也可以不传,获取的就是当前时间
  115. var time
  116. if(date){
  117. time = new Date(date);
  118. }else{
  119. time = new Date();
  120. }
  121. var year= time.getFullYear() //年
  122. var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
  123. var day = ("0" + time.getDate()).slice(-2); //日
  124. var mydate = year + "-" + month + "-" + day;
  125. return mydate
  126. },
  127. /**
  128. * 生命周期函数--监听页面初次渲染完成
  129. */
  130. onReady() {
  131. },
  132. /**
  133. * 生命周期函数--监听页面显示
  134. */
  135. onShow() {
  136. },
  137. openBox(even){
  138. console.log(even.currentTarget.dataset.name);
  139. this.setData({
  140. [even.currentTarget.dataset.name]:true
  141. })
  142. },
  143. onChange(event){
  144. console.log(event);
  145. this.setData({
  146. [event.currentTarget.dataset.value]: event.detail,
  147. })
  148. },
  149. closeBox(even){
  150. console.log(even.currentTarget.dataset.name);
  151. this.setData({
  152. [even.currentTarget.dataset.name]:false
  153. })
  154. },
  155. goSubmit(){
  156. if(this.data.form.eventName===''||this.data.form.eventName==null){ //事项名称
  157. UTIL.showToastNoneIcon('请填写事项名称!');
  158. return false;
  159. }else if(this.data.form.eventTime===''||this.data.form.eventTime==null){ //事项时间
  160. UTIL.showToastNoneIcon('事项时间不能为空!');
  161. return false;
  162. }else if(this.data.form.eventContent===''||this.data.form.eventContent==null){ //事项内容
  163. UTIL.showToastNoneIcon('事项内容不能为空!');
  164. return false;
  165. }else if(this.data.form.dzbty===''||this.data.form.dzbty==null){ //事项内容
  166. UTIL.showToastNoneIcon('村党支部提议不能为空!');
  167. return false;
  168. }else if(this.data.form.lwhsy===''||this.data.form.lwhsy==null){ //事项内容
  169. UTIL.showToastNoneIcon('两委会商议不能为空!');
  170. return false;
  171. }else if(this.data.form.dqyshsyhjy===''||this.data.form.dqyshsyhjy==null){ //事项内容
  172. UTIL.showToastNoneIcon('党群议事会审议和决议不能为空!');
  173. return false;
  174. }else if(this.data.form.jcjggk===''||this.data.form.jcjggk==null){ //事项内容
  175. UTIL.showToastNoneIcon('决策结果公开不能为空!');
  176. return false;
  177. }else if(this.data.form.ssqkgk===''||this.data.form.ssqkgk==null){ //事项内容
  178. UTIL.showToastNoneIcon('实施情况公开不能为空!');
  179. return false;
  180. }else if(this.data.status=='0'){
  181. this.setData({'status':'1'})
  182. var that = this;
  183. that.data.form.method = 'POST';
  184. that.data.form.eventContent = that.data.form.eventContent.replace(/\\/g,"/")
  185. that.data.form.eventContent = that.data.form.eventContent.replace(/"/g,"'")
  186. that.data.form.dzbty = that.data.form.dzbty.replace(/"/g,"'")
  187. that.data.form.lwhsy = that.data.form.lwhsy.replace(/"/g,"'")
  188. that.data.form.dqyshsyhjy = that.data.form.dqyshsyhjy.replace(/"/g,"'")
  189. that.data.form.cydbhjy = that.data.form.cydbhjy.replace(/"/g,"'")
  190. that.data.form.jcjggk = that.data.form.jcjggk.replace(/"/g,"'")
  191. that.data.form.ssqkgk = that.data.form.ssqkgk.replace(/"/g,"'")
  192. console.log(that.data.form);
  193. if(that.data.form.id==""||that.data.form.id==null){
  194. UTIL.httpRequest(API.URL_POST_MAJOREVENTADD, that.data.form , {
  195. success: (res) => {
  196. this.setData({'status':0})
  197. if(res.code == 200){
  198. UTIL.showToastNoneIcon('新增成功');
  199. setTimeout(function(){
  200. wx.navigateBack({
  201. delta:1
  202. })
  203. },2000)
  204. }else{
  205. UTIL.showToastNoneIcon('新增失败:'+res.msg);
  206. }
  207. }
  208. })
  209. }else{
  210. UTIL.httpRequest(API.URL_POST_MAJOREVENTUPDATE, that.data.form , {
  211. success: (res) => {
  212. this.setData({'status':0})
  213. if(res.code == 200){
  214. UTIL.showToastNoneIcon('修改成功');
  215. setTimeout(function(){
  216. wx.navigateBack({
  217. delta:1
  218. })
  219. },2000)
  220. }else{
  221. UTIL.showToastNoneIcon('修改失败:'+res.msg);
  222. }
  223. }
  224. })
  225. }
  226. }
  227. },
  228. onConfirmTime(event){
  229. this.setData({
  230. [event.currentTarget.dataset.name]: false,
  231. [event.currentTarget.dataset.value]: UTIL.formatDate(event.detail),
  232. });
  233. },
  234. openBox(even){
  235. console.log(even.currentTarget.dataset.name);
  236. this.setData({
  237. [even.currentTarget.dataset.name]:true
  238. })
  239. },
  240. closeBox(even){
  241. console.log(even.currentTarget.dataset.name);
  242. this.setData({
  243. [even.currentTarget.dataset.name]:false
  244. })
  245. },
  246. back:function(){
  247. wx.navigateBack({
  248. delta: 1
  249. })
  250. },
  251. onConfirm(event) {
  252. this.setData({
  253. [event.currentTarget.dataset.name]: false,
  254. [event.currentTarget.dataset.value]: event.detail.value.dictValue,
  255. [event.currentTarget.dataset.value+'Text']: event.detail.value.dictLabel,
  256. });
  257. },
  258. /**
  259. * 生命周期函数--监听页面隐藏
  260. */
  261. onHide() {
  262. },
  263. /**
  264. * 生命周期函数--监听页面卸载
  265. */
  266. onUnload() {
  267. },
  268. /**
  269. * 页面相关事件处理函数--监听用户下拉动作
  270. */
  271. onPullDownRefresh() {
  272. },
  273. /**
  274. * 页面上拉触底事件的处理函数
  275. */
  276. onReachBottom() {
  277. },
  278. /**
  279. * 用户点击右上角分享
  280. */
  281. onShareAppMessage() {
  282. }
  283. })