storeCode.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div>
  3. <div class="" v-if="insert">
  4. <p style="margin: 0" @click="uploadImg">
  5. <van-icon name="scan" size="24px" color="#1989fa" />
  6. </p>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. import axios from 'axios';
  12. import { getOptionByResult } from '@/api/index';
  13. export default {
  14. name: 'storeCode',
  15. props: {
  16. index: {
  17. type: Number,
  18. default: -1,
  19. },
  20. tid: {
  21. type: String,
  22. default: '',
  23. },
  24. cid: {
  25. type: Number,
  26. default: -1,
  27. },
  28. code: {
  29. type: String,
  30. default: '',
  31. },
  32. index1: {
  33. type: [String, Number],
  34. default: '',
  35. },
  36. index2: {
  37. type: [String, Number],
  38. default: '',
  39. },
  40. index3: {
  41. type: [String, Number],
  42. default: '',
  43. },
  44. index4: {
  45. type: [String, Number],
  46. default: '',
  47. },
  48. index5: {
  49. type: [String, Number],
  50. default: '',
  51. },
  52. index6: {
  53. type: [String, Number],
  54. default: '',
  55. },
  56. index7: {
  57. type: [String, Number],
  58. default: '',
  59. },
  60. index8: {
  61. type: [String, Number],
  62. default: '',
  63. },
  64. taskId: {
  65. type: String,
  66. default: '',
  67. },
  68. collectionId: {
  69. type: String,
  70. default: '',
  71. },
  72. type: {
  73. type: String,
  74. default: '',
  75. },
  76. insert: {
  77. type: Boolean,
  78. default: true,
  79. },
  80. },
  81. data() {
  82. return {
  83. shows: false,
  84. url: '',
  85. };
  86. },
  87. methods: {
  88. uploadImg() {
  89. let url = window.location.href;
  90. let that = this;
  91. let wx = this.wx;
  92. let qiyeData;
  93. console.log(that.code);
  94. debugger;
  95. const instance = axios.create();
  96. instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
  97. instance
  98. .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
  99. params: {
  100. url: url,
  101. },
  102. })
  103. .then((response) => {
  104. if (response.status == 200) {
  105. qiyeData = response.data.data;
  106. wx.config({
  107. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  108. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  109. appId: qiyeData.appId, // 必填,企业微信的corpID
  110. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  111. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  112. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  113. jsApiList: ['ready', 'scanQRCode'],
  114. });
  115. wx.ready(function () {
  116. wx.scanQRCode({
  117. desc: 'scanQRCode desc',
  118. needResult: 1,
  119. scanType: ['barCode'],
  120. success: function (res) {
  121. console.log(res);
  122. var result = res.resultStr;
  123. console.log(result);
  124. var success = false;
  125. if (that.code == result && that.code != '' && that.code != null) {
  126. success = true;
  127. }
  128. let loading1 = that.$toast.loading({
  129. duration: 0,
  130. message: '数据加载中...',
  131. forbidClick: true,
  132. });
  133. getOptionByResult({
  134. taskId: that.tid,
  135. collectionId: that.cid,
  136. smResult: success,
  137. }).then((response) => {
  138. loading1.clear();
  139. if (response.code == 200) {
  140. that.$emit('newcode', {
  141. cid: response.data.collectionId,
  142. cpid: response.data.collectionOptionId,
  143. nocpid: response.data.diffCollectionOptionId,
  144. type: that.type,
  145. index: that.index,
  146. code: that.code + ',' + result,
  147. success: success,
  148. index1: that.index1,
  149. index2: that.index2,
  150. index3: that.index3,
  151. index4: that.index4,
  152. index5: that.index5,
  153. index6: that.index6,
  154. index7: that.index7,
  155. index8: that.index8,
  156. });
  157. }
  158. });
  159. },
  160. error: function (res) {
  161. if (res.errMsg.indexOf('function_not_exist') > 0) {
  162. alert('版本过低请升级');
  163. }
  164. },
  165. });
  166. });
  167. }
  168. });
  169. },
  170. },
  171. };
  172. </script>
  173. <style scoped>
  174. .cameraDiv1 {
  175. position: relative;
  176. height: 164px;
  177. width: 100%;
  178. }
  179. .cameraDiv1 img {
  180. position: absolute;
  181. width: 100%;
  182. display: block;
  183. height: 164px;
  184. top: 0;
  185. }
  186. .imgPre {
  187. height: 164px;
  188. width: 100%;
  189. background-color: white;
  190. border-radius: 6px;
  191. overflow: hidden;
  192. }
  193. .photos1 {
  194. margin: 70px auto;
  195. left: 50%;
  196. margin-left: -14px;
  197. }
  198. .photobrowsing {
  199. position: absolute;
  200. padding: 4px;
  201. right: 0;
  202. top: 0;
  203. z-index: 99;
  204. background-color: rgba(255, 255, 255, 0.8);
  205. border-bottom-left-radius: 3px;
  206. border-top-left-radius: 3px;
  207. }
  208. .coverImg {
  209. text-align: center;
  210. position: absolute;
  211. top: 0;
  212. left: 0;
  213. height: 164px;
  214. width: 100%;
  215. }
  216. .coverImg .ico {
  217. top: 42%;
  218. }
  219. </style>