uploadPrescription.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view :style="[mainStyle]">
  3. <!-- 上传区域 -->
  4. <view class="upload-box">
  5. <block v-if="form.image && form.image.length > 0"><image v-for="(item, index) in form.image" style="width: 100%;" mode="widthFix" :src="item"></image></block>
  6. <block v-else>
  7. <view class="upload-area" @click="choiceImages"><image class="upload-icon" src="../static/images/plus.png"></image></view>
  8. <view class="upload-title">请上传处方图片</view>
  9. </block>
  10. <view class="note">您上传的处方图片要求字迹清楚、清晰可辨认、信息完整(含姓名,疾病,年龄,性别及医生签名等信息)</view>
  11. </view>
  12. <!-- 信息 -->
  13. <view class="form-box">
  14. <view class="form-item bottom-border">
  15. <view>是否需要代煎药</view>
  16. <view><switch :checked="form.isBoilMedicine" data-name="isBoilMedicine" @change="switchChange" color="#11bb8b" style="transform: scale(0.7)"></switch></view>
  17. </view>
  18. <view class="form-item bottom-border">
  19. <view>是否是孕妇</view>
  20. <view><switch :checked="form.isPregnantWoman" data-name="isPregnantWoman" @change="switchChange" color="#11bb8b" style="transform: scale(0.7)"></switch></view>
  21. </view>
  22. <view class="form-item">
  23. <view>备注</view>
  24. <view><input class="note-input" v-model="form.note" placeholder="备注,给商家留言" /></view>
  25. </view>
  26. </view>
  27. <!-- 收货地址 -->
  28. <view class="address-box">
  29. <view class="form-item" @tap="addOrUpdateAddress">
  30. <view>收货地址</view>
  31. <view style="display: flex;align-items: center">
  32. <input v-if="!address.address" class="note-input" disabled="true" placeholder="添加收货地址" />
  33. <view v-else>{{ address.address + address.house }}</view>
  34. <image class="arrow-icon" src="../static/images/arrow.png"></image>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 按钮 -->
  39. <view class="bottom-bar">
  40. <view class="bottom-btn" :disabled="buttonClicked" @click="submitUpdata()"><text>提交处方</text></view>
  41. </view>
  42. <canvas canvas-id="canvas" :style="'width:' + cWidth + 'px;height:' + cHeight + 'px;position: absolute;left:-1000px;top:-1000px;'"></canvas>
  43. </view>
  44. </template>
  45. <script>
  46. const app = getApp();
  47. const requsetmessage = require('../../utils/requestmessage.js');
  48. const req = require('../../utils/request.js');
  49. const api = require('../../utils/api.js');
  50. const utils = require('../../utils/util.js');
  51. export default {
  52. data() {
  53. return {
  54. mainStyle: app.globalData.mainStyle,
  55. form: {
  56. image: [],
  57. isBoilMedicine: false,
  58. isPregnantWoman: false,
  59. note: '',
  60. buttonClicked: false
  61. },
  62. address: {}
  63. };
  64. },
  65. onLoad(options) {},
  66. onShow() {},
  67. methods: {
  68. switchChange(e) {
  69. this.form[e.currentTarget.dataset.name] = e.detail.value;
  70. },
  71. addOrUpdateAddress() {
  72. let url = 'mine/address/address?isChoose=true';
  73. app.globalData.openPage(url);
  74. },
  75. //提交数据
  76. async submitUpdata() {
  77. var tha = this;
  78. if (!this.form.image || this.form.image.length <= 0) {
  79. req.msg('请上传处方图片');
  80. return;
  81. }
  82. if (!this.address.id) {
  83. req.msg('请选择收货地址');
  84. return;
  85. }
  86. if (tha.buttonClicked) {
  87. console.log('重复点击了,返回>>>>>');
  88. return;
  89. }
  90. tha.buttonClicked = true;
  91. //订阅处方审核通知
  92. await requsetmessage
  93. .prescribingAudit()
  94. .then(res => {
  95. req.postRequest(
  96. '/api/orderdurg/save',
  97. {
  98. drugImgUrl: tha.form.image.join(','),
  99. isFrying: tha.form.isBoilMedicine ? '1' : '0',
  100. isPregnant: tha.form.isPregnantWoman ? '1' : '0',
  101. remarks: tha.form.note,
  102. addressId: tha.address.id,
  103. merchantId:req.getStorage('MERCHANT').id,
  104. },
  105. data => {
  106. tha.buttonClicked = false;
  107. uni.navigateBack();
  108. },
  109. true
  110. );
  111. })
  112. .catch(() => {
  113. tha.buttonClicked = false;
  114. });
  115. },
  116. //处方图片上传
  117. choiceImages(event) {
  118. let that = this;
  119. wx.chooseImage({
  120. count: 9,
  121. sourceType: ['album', 'camera'],
  122. sizeType: ['compressed'],
  123. async success(res) {
  124. console.log(res);
  125. let list = res.tempFiles;
  126. console.log(list);
  127. let allList = [];
  128. for (let i = 0; i < list.length; i++) {
  129. //两M
  130. if (list[i].size > 50000) {
  131. var path = await that.compressImg(list[i].path);
  132. var data = {
  133. formData: {
  134. flag: 726
  135. },
  136. filePath: path,
  137. name: 'file'
  138. };
  139. allList.push(data);
  140. } else {
  141. var data = {
  142. formData: {
  143. flag: 722
  144. },
  145. filePath: list[i].path,
  146. name: 'file'
  147. };
  148. allList.push(data);
  149. }
  150. }
  151. console.log(allList);
  152. let successUp = 0;
  153. let failUp = 0;
  154. let count = 0;
  155. // 多图上传 allList:图片数组 successUp:上传成功次数 现在上传的下标
  156. that.uploadImgs(allList, successUp, failUp, count);
  157. },
  158. fail(err) {}
  159. });
  160. },
  161. //通过canvans缩放长宽来压缩图片 path:图片本地路径 limitNum:压缩到长宽多大
  162. async compressImg(path, multiple = 2, limitNum = 600) {
  163. console.log('图片链接', path);
  164. let that = this;
  165. return new Promise((resolve, reject) => {
  166. wx.getImageInfo({
  167. src: path,
  168. success(res) {
  169. var canvasWidth = res.width; //图片原始长宽
  170. var canvasHeight = res.height;
  171. console.log('图片的基本信息', res);
  172. // while循环 保证宽高在100以内 Math.trunc()去掉小数点右边数
  173. while (canvasWidth > limitNum || canvasHeight > limitNum) {
  174. canvasWidth = Math.trunc(res.width / multiple);
  175. canvasHeight = Math.trunc(res.height / multiple);
  176. multiple++;
  177. }
  178. //设置画布长宽
  179. that.setData({
  180. cWidth: canvasWidth,
  181. cHeight: canvasHeight
  182. });
  183. //----------绘制图形并取出图片路径--------------
  184. var ctx = wx.createCanvasContext('canvas');
  185. ctx.drawImage(res.path, 0, 0, canvasWidth, canvasHeight);
  186. ctx.draw(
  187. false,
  188. setTimeout(() => {
  189. wx.canvasToTempFilePath({
  190. canvasId: 'canvas',
  191. destWidth: canvasWidth,
  192. destHeight: canvasHeight,
  193. success: function(res) {
  194. console.log(res.tempFilePath); //图片路径
  195. resolve(res.tempFilePath);
  196. },
  197. fail: function(res) {
  198. console.log(res.errMsg);
  199. }
  200. });
  201. }, 100)
  202. );
  203. },
  204. fail: function(res) {
  205. console.log(res.errMsg);
  206. }
  207. });
  208. });
  209. },
  210. //多张图片上传
  211. uploadImgs: function(allList, successUp, failUp, count) {
  212. console.log(allList, successUp, failUp, count);
  213. let tha = this;
  214. let length = allList.length; //总共上传的数量
  215. uni.showLoading({
  216. title: '上传中'
  217. });
  218. var index = 0;
  219. var promise = Promise.all(
  220. allList.map(tempFilePath => {
  221. return new Promise(function(resolve, reject) {
  222. req.uploadFile('/api/upload', tempFilePath.filePath, res => {
  223. let fileUrls = tha.form.image;
  224. tha.form.image = fileUrls.concat(res.src);
  225. if (index == allList.length - 1) {
  226. uni.hideLoading();
  227. }
  228. index++;
  229. });
  230. });
  231. })
  232. );
  233. promise.then(function(results) {}).catch(function(err) {});
  234. }
  235. }
  236. };
  237. </script>
  238. <style>
  239. @import './uploadPrescription.css';
  240. </style>