addHealth.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. const app = getApp()
  2. const util = require("../../../utils/util");
  3. const api = require('../../../api/api.js');
  4. const user = require('../../../utils/user.js');
  5. import moment from 'moment'
  6. Page({
  7. data: {
  8. certificateName:'',
  9. certificateNo:'',
  10. healthType:'1',
  11. startDate: '',
  12. endDate: '',
  13. issuanceDate:'',
  14. max: 1,
  15. fileList: [],
  16. date: moment(new Date()).format('YYYY-MM-DD'),
  17. currentDate: new Date().getTime(),
  18. minDate: new Date('2022-01-01').getTime(),
  19. pickerShow:false,
  20. type:'',
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.getHealthInfo();
  27. },
  28. onRadioChange (e){
  29. this.setData({
  30. healthType:e.detail
  31. });
  32. },
  33. onNameChange (e){
  34. this.setData({
  35. certificateName:e.detail
  36. });
  37. },
  38. onNoChange (e){
  39. this.setData({
  40. certificateNo:e.detail
  41. });
  42. },
  43. getHealthInfo(){
  44. let userInfo = wx.getStorageSync('userInfo');
  45. util.request(api.getHealthCert, {
  46. workerNo:userInfo.workerNo
  47. }, 'GET').then(res=> {
  48. if (res.errno === 0) {
  49. if(res.data.healthState!='未上传'){
  50. this.setData({
  51. certificateName:res.data.healthInfo.certificateName,
  52. certificateNo:res.data.healthInfo.certificateNo,
  53. issuanceDate:moment(res.data.healthInfo.issuanceDate).format('YYYY-MM-DD'),
  54. startDate:moment(res.data.healthInfo.expirationDateStart).format('YYYY-MM-DD'),
  55. endDate:moment(res.data.healthInfo.expirationDateEnd).format('YYYY-MM-DD'),
  56. });
  57. if(res.data.healthInfo.certificateFileUrl==''){
  58. this.setData({
  59. fileList:[]
  60. });
  61. }else{
  62. let list=res.data.healthInfo.certificateFileUrl.split(',');
  63. let imglist=[];
  64. list.forEach(item=>{
  65. let obj={url:item};
  66. imglist.push(obj);
  67. });
  68. this.setData({
  69. fileList:imglist
  70. });
  71. }
  72. }
  73. }
  74. }).catch(err=>{
  75. });
  76. },
  77. goDetail() {
  78. wx.navigateTo({
  79. url: '/pages/upgrade/xnbInfo/xnbInfo',
  80. })
  81. },
  82. issuancePicker(){
  83. this.setData({
  84. pickerShow:true,
  85. type:'issuance'
  86. });
  87. },
  88. startPicker(){
  89. this.setData({
  90. pickerShow:true,
  91. type:'start'
  92. });
  93. },
  94. endPicker(){
  95. this.setData({
  96. pickerShow:true,
  97. type:'end'
  98. });
  99. },
  100. onCancel(){
  101. this.setData({
  102. pickerShow:false
  103. })
  104. },
  105. onConfirm(e){
  106. console.log(e);
  107. let date=moment(e.detail).format('YYYY-MM-DD');
  108. if(this.data.type=='start'){
  109. this.setData({
  110. startDate:date,
  111. pickerShow:false
  112. });
  113. }else if(this.data.type=='end'){
  114. this.setData({
  115. endDate:date,
  116. pickerShow:false
  117. });
  118. }else{
  119. this.setData({
  120. issuanceDate:date,
  121. pickerShow:false
  122. });
  123. }
  124. },
  125. getDetail() {
  126. util.request(api.getDetail, {
  127. id: this.data.id
  128. }, 'GET').then(res => {
  129. if (res.errno === 0) {
  130. this.setData({
  131. isFinish: res.data.feedbackComment == '' ? false : true,
  132. feedbackInfo: res.data,
  133. content: res.data.feedbackComment
  134. });
  135. if (this.data.isFinish) {
  136. let imgs = res.data.feedbackImgs;
  137. if (imgs == '') {
  138. this.setData({
  139. uploadShow: false,
  140. });
  141. } else {
  142. let list = imgs.split(',');
  143. let current = [];
  144. list.forEach(item => {
  145. let obj = {
  146. url: item
  147. };
  148. current.push(obj);
  149. });
  150. this.setData({
  151. fileList: current,
  152. max: current.length,
  153. });
  154. }
  155. }
  156. }
  157. });
  158. },
  159. deleteImage(event) {
  160. const { fileList = [] } = this.data;
  161. fileList.splice(event.detail.index, 1)
  162. this.setData({
  163. fileList: fileList
  164. })
  165. let urls = [];
  166. fileList.forEach(function (e) {
  167. urls.push(e.url);
  168. })
  169. this.setData({
  170. "pictures": urls
  171. })
  172. },
  173. afterRead(event) {
  174. console.log(event);
  175. const { file } = event.detail
  176. let that = this;
  177. const uploadTask = wx.uploadFile({
  178. url: api.StorageUpload(),
  179. filePath: file.url,
  180. name: 'file',
  181. success: function (res) {
  182. console.log(res);
  183. var _res = JSON.parse(res.data);
  184. if (_res.errno === 0) {
  185. var url = _res.data.fileUrl;
  186. const { fileList = [] } = that.data;
  187. fileList.push({ ...file, url: url });
  188. that.setData({
  189. fileList: fileList
  190. })
  191. }
  192. },
  193. fail: function (e) {
  194. wx.showModal({
  195. title: '错误',
  196. content: '上传失败',
  197. showCancel: false
  198. })
  199. },
  200. })
  201. },
  202. submit() {
  203. if (
  204. this.data.certificateName == ''
  205. ) {
  206. wx.showToast({
  207. title: '请输入证件名称',
  208. icon: 'none'
  209. });
  210. }else if (
  211. this.data.certificateNo == ''
  212. ) {
  213. wx.showToast({
  214. title: '请输入证件编号',
  215. icon: 'none'
  216. });
  217. }else if (this.data.fileList.length == 0) {
  218. wx.showToast({
  219. title: '请上传健康证照片',
  220. icon: 'none'
  221. });
  222. } else if (
  223. this.data.issuanceDate == ''
  224. ) {
  225. wx.showToast({
  226. title: '请选择发证日期',
  227. icon: 'none'
  228. });
  229. }else if (
  230. this.data.startDate == ''
  231. ) {
  232. wx.showToast({
  233. title: '请选择开始时间',
  234. icon: 'none'
  235. });
  236. } else if (
  237. this.data.endDate == ''
  238. ) {
  239. wx.showToast({
  240. title: '请选择结束时间',
  241. icon: 'none'
  242. });
  243. } else {
  244. let imgs = [];
  245. this.data.fileList.forEach(item => {
  246. imgs.push(item.url)
  247. });
  248. let userInfo = wx.getStorageSync('userInfo');
  249. util.request(api.addWorkerCertificate, {
  250. workerNo:userInfo.workerNo,
  251. expirationDateStart:this.data.startDate,
  252. expirationDateEnd:this.data.endDate,
  253. issuanceDate:this.data.issuanceDate,
  254. certificateFileUrl:imgs.join(','),
  255. certificateName:this.data.certificateName,
  256. certificateNo:this.data.certificateNo,
  257. }, 'POST').then(res => {
  258. if (res.errno === 0) {
  259. // wx.showToast({
  260. // title: '提交成功',
  261. // icon:'none'
  262. // });
  263. wx.showModal({
  264. title: '提醒',
  265. content: '提交成功',
  266. showCancel: false, //是否显示取消按钮
  267. success: function (res) {
  268. wx.navigateBack({
  269. delta: 1,
  270. });
  271. }
  272. })
  273. }else{
  274. wx.showToast({
  275. title: res.errmsg,
  276. icon:'none'
  277. })
  278. }
  279. });
  280. }
  281. },
  282. onReachBottom() {
  283. // if (this.data.totalPages > this.data.page) {
  284. // this.setData({
  285. // page: this.data.page + 1
  286. // });
  287. // this.getGoodsList();
  288. // } else {
  289. // wx.showToast({
  290. // title: '没有更多商品了',
  291. // icon: 'none',
  292. // duration: 2000
  293. // });
  294. // return false;
  295. // }
  296. },
  297. /**
  298. * 生命周期函数--监听页面初次渲染完成
  299. */
  300. onReady: function () {
  301. },
  302. /**
  303. * 生命周期函数--监听页面显示
  304. */
  305. onShow: function () {
  306. },
  307. onHide: function () {
  308. },
  309. onUnload: function () {
  310. },
  311. /**
  312. * 页面相关事件处理函数--监听用户下拉动作
  313. */
  314. onPullDownRefresh: function () {
  315. },
  316. /**
  317. * 页面上拉触底事件的处理函数
  318. */
  319. onReachBottom: function () {
  320. },
  321. /**
  322. * 用户点击右上角分享
  323. */
  324. onShareAppMessage: function () {
  325. },
  326. })