index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. const util = require("../../../utils/util");
  2. const api = require('../../../api/api.js');
  3. const check = require('../../../utils/check.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. operType:1,//1核酸2抗原
  11. anicResult:'阴性',
  12. checkDate:'',
  13. files: [],
  14. picUrls: null,
  15. hasPicture: false,
  16. list: [],
  17. bbt: '',
  18. canAttendance:1,
  19. },
  20. bindBBT(e) {
  21. this.setData({
  22. bbt: e.detail.value
  23. })
  24. },
  25. radioAcceptChange(e){
  26. this.setData({
  27. canAttendance:e.detail.value
  28. });
  29. },
  30. radioTypeChange(e){
  31. this.setData({
  32. operType:e.detail.value
  33. });
  34. },
  35. checkDateChange(e){
  36. this.setData({
  37. checkDate:e.detail.value
  38. });
  39. },
  40. anicResultChange(e){
  41. this.setData({
  42. anicResult:e.detail.value
  43. });
  44. },
  45. chooseImage: function (e) {
  46. if (this.data.bbt == '') {
  47. util.showErrorToast('请先输入体温')
  48. return false;
  49. }
  50. if(this.data.bbt>42){
  51. util.showErrorToast('请输入正确体温')
  52. return false;
  53. }
  54. if(this.data.operType==2&&this.data.checkDate==''){
  55. util.showErrorToast('请选择检测日期')
  56. return false;
  57. }
  58. if(this.data.canAttendance==null){
  59. util.showErrorToast('请选择是否能接单')
  60. return false;
  61. }
  62. if (this.data.files.length >= 5) {
  63. util.showErrorToast('只能上传五张图片')
  64. return false;
  65. }
  66. var that = this;
  67. wx.chooseImage({
  68. count: 1,
  69. sizeType: ['original', 'compressed'],
  70. sourceType: ['album', 'camera'],
  71. success: function (res) {
  72. that.setData({
  73. files: that.data.files.concat(res.tempFilePaths)
  74. });
  75. console.info(res.tempFilePaths[0])
  76. that.upload(res)
  77. }
  78. })
  79. },
  80. upload: function (res) {
  81. wx.showLoading({
  82. title: '识别中',
  83. })
  84. var that = this;
  85. console.log(that.data);
  86. const uploadTask = wx.uploadFile({
  87. url: api.NucleicOCR(),
  88. filePath: res.tempFilePaths[0],
  89. name: 'file',
  90. formData: {
  91. bbt: that.data.bbt,
  92. operType:that.data.operType,//1核酸2抗原
  93. anicResult:that.data.operType==1?'':that.data.anicResult,
  94. checkDate:that.data.operType==1?'':that.data.checkDate,
  95. canAttendance:that.data.canAttendance
  96. },
  97. header: {
  98. 'Content-Type': 'multipart/form-data',
  99. 'X-JZ-Token': wx.getStorageSync('token')
  100. },
  101. success: function (res) {
  102. wx.hideLoading();
  103. var _res = JSON.parse(res.data);
  104. console.info(_res)
  105. if (_res.errno === 0) {
  106. wx.showToast({
  107. title: '提交成功',
  108. duration: 3000
  109. });
  110. setTimeout(() => {
  111. wx.navigateBack({
  112. delta: 1,
  113. });
  114. }, 3000);
  115. } else {
  116. wx.showModal({
  117. title: '错误',
  118. content: _res.errmsg,
  119. showCancel: false
  120. })
  121. }
  122. },
  123. fail: function (e) {
  124. wx.hideLoading();
  125. wx.showModal({
  126. title: '错误',
  127. content: '上传失败',
  128. showCancel: false
  129. })
  130. },
  131. })
  132. uploadTask.onProgressUpdate((res) => {
  133. console.log('上传进度', res.progress)
  134. console.log('已经上传的数据长度', res.totalBytesSent)
  135. console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
  136. })
  137. },
  138. previewImage: function (e) {
  139. wx.previewImage({
  140. current: e.currentTarget.id, // 当前显示图片的http链接
  141. urls: this.data.files // 需要预览的图片http链接列表
  142. })
  143. },
  144. //预览图片
  145. previewSampleImage: function (e) {
  146. var current = e.target.dataset.src;
  147. var imgList = [];
  148. imgList.push(current);
  149. wx.previewImage({
  150. current: current, //当前点击的图片链接
  151. urls: imgList //图片数组
  152. })
  153. },
  154. bindMobile(e) {
  155. this.setData({
  156. mobile: e.detail.value
  157. })
  158. },
  159. getList() {
  160. let that = this;
  161. if (that.data.mobile == '') return;
  162. wx.showLoading({
  163. title: '获取中',
  164. });
  165. util.request(api.ocrList, {
  166. phone: this.data.mobile
  167. }).then(function (res) {
  168. console.info(res)
  169. wx.hideLoading();
  170. if (res.errno == 0) {
  171. that.setData({
  172. list: res.data
  173. });
  174. } else {
  175. wx.showToast({
  176. title: res.errmsg,
  177. duration: 5000
  178. })
  179. }
  180. }).catch(res => {
  181. wx.hideLoading();
  182. util.showErrorToast(res)
  183. })
  184. },
  185. /**
  186. * 生命周期函数--监听页面加载
  187. */
  188. onLoad: function (options) {
  189. },
  190. /**
  191. * 生命周期函数--监听页面初次渲染完成
  192. */
  193. onReady: function () {
  194. },
  195. /**
  196. * 生命周期函数--监听页面显示
  197. */
  198. onShow: function () {},
  199. /**
  200. * 生命周期函数--监听页面隐藏
  201. */
  202. onHide: function () {
  203. },
  204. /**
  205. * 生命周期函数--监听页面卸载
  206. */
  207. onUnload: function () {
  208. },
  209. /**
  210. * 页面相关事件处理函数--监听用户下拉动作
  211. */
  212. onPullDownRefresh: function () {
  213. },
  214. /**
  215. * 页面上拉触底事件的处理函数
  216. */
  217. onReachBottom: function () {
  218. },
  219. /**
  220. * 用户点击右上角分享
  221. */
  222. onShareAppMessage: function () {
  223. }
  224. })