sampleTag.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="bg">
  3. <cu-custom bgColor="bg-gradual-pink" :isBack="true">
  4. <block slot="backview">返回</block>
  5. <block slot="content">样品标签</block>
  6. </cu-custom>
  7. <view ref="qrcode" id="box">
  8. <view v-for="(item1,index1) in list" :key="index1">
  9. <view v-for="(item2,index2) in parseInt(item1.num)" :key="index2">
  10. <view class="tagBox">
  11. <view class="lh">
  12. <view>样品名称:</view>
  13. <view>{{item1.name}}</view>
  14. </view>
  15. <view class="la">
  16. <view class="lh">
  17. <view>样品编号:</view>
  18. <view>{{item1.serial}}</view>
  19. </view>
  20. <view class="lh" style="margin-left: 15rpx">
  21. <view>收样时间:</view>
  22. <view></view>
  23. </view>
  24. </view>
  25. <view class="lh">
  26. <view>存储条件:</view>
  27. <view>{{item1.condition}}</view>
  28. </view>
  29. <view class="lh">
  30. <view>流转状态:</view>
  31. <view>▢待检,▢已检,▢留样</view>
  32. </view>
  33. <view class="lh">
  34. <view>样品数量:</view>
  35. <view>{{index2+1}}/{{item1.num}}支</view>
  36. </view>
  37. <view>
  38. <vue-barcode :value="item1.serial" :width="2" :height="45"></vue-barcode>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <u-button type="primary" class="btn" @click="getAction()" style="margin: 20rpx;" v-if="imgSrc != ''">操作</u-button>
  45. </view>
  46. </template>
  47. <script>
  48. import html2canvas from "html2canvas";
  49. import VueBarcode from 'vue-barcode';
  50. import {
  51. ACCESS_TOKEN,
  52. USER_NAME,
  53. USER_INFO
  54. } from "@/common/util/constants"
  55. export default {
  56. components: {
  57. VueBarcode
  58. },
  59. data() {
  60. return {
  61. value: '',
  62. id: '',
  63. list: [],
  64. imgSrc: '',
  65. userid: '',
  66. time: ''
  67. }
  68. },
  69. created() {
  70. this.getInit()
  71. },
  72. onLoad(options) {
  73. if (options.id) {
  74. this.id = options.id
  75. this.getLook(options.id)
  76. }
  77. },
  78. methods: {
  79. getInit() {
  80. let info = uni.getStorageSync(USER_INFO);
  81. if (info.employee.id) {
  82. this.userid = info.employee.id || ''
  83. }
  84. var nowDate = new Date((new Date).getTime() + 8 * 60 * 60 * 1000)
  85. var time = nowDate.toJSON().split('T').join(' ').substr(0, 19)
  86. this.time = time
  87. },
  88. getLook(id) {
  89. let sql =
  90. `select * from t_lhypb where parent_id_ = '${id}'`
  91. let requestData = this.$sig(sql)
  92. this.$http.post("/ibps/business/v3/sys/universal/inputSqlSelectData", requestData).then(res => {
  93. if (res.data.state == 200) {
  94. const data = res.data.variables.data
  95. let list = []
  96. data.forEach(item => {
  97. if (item.yang_pin_lei_xing != '' && parseInt(item.shu_liang_) > 0) {
  98. let obj = {
  99. name: item.yang_pin_ming_che,
  100. serial: item.yang_pin_bian_hao,
  101. type: item.yang_pin_lei_xing,
  102. num: item.shu_liang_,
  103. condition: item.yang_ben_yun_shu_
  104. }
  105. list.push(obj)
  106. }
  107. if (item.yang_pin_lei_er_ != '' && parseInt(item.shu_liang_er_) > 0) {
  108. let obj = {
  109. name: item.yang_pin_ming_che,
  110. serial: item.yang_pin_bian_hao,
  111. type: item.yang_pin_lei_er_,
  112. num: item.shu_liang_er_,
  113. condition: item.yang_pin_yun_shu_
  114. }
  115. list.push(obj)
  116. }
  117. if (item.yang_pin_lei_san_ != '' && parseInt(item.shu_liang_san_) > 0) {
  118. let obj = {
  119. name: item.yang_pin_ming_che,
  120. serial: item.yang_pin_bian_hao,
  121. type: item.yang_pin_lei_san_,
  122. num: item.shu_liang_san_,
  123. condition: item.yang_pin_gui_ge_s
  124. }
  125. list.push(obj)
  126. }
  127. if (item.yang_pin_lei_si_ != '' && parseInt(item.shu_liang_si_) > 0) {
  128. let obj = {
  129. name: item.yang_pin_ming_che,
  130. serial: item.yang_pin_bian_hao,
  131. type: item.yang_pin_lei_si_,
  132. num: item.shu_liang_si_,
  133. condition: item.yang_pin_gui_si_
  134. }
  135. list.push(obj)
  136. }
  137. })
  138. this.list = list
  139. this.$nextTick(() => {
  140. this.getBtn()
  141. })
  142. }
  143. })
  144. },
  145. getBtn() {
  146. // document.getElementById("qrcode").appendChild(canvas);
  147. //点击生成canvas转换成base64的图片
  148. var width = document.getElementById('box').offsetWidth,
  149. height = document.getElementById('box').offsetHeight,
  150. scale = window.devicePixelRatio; //放大倍数
  151. html2canvas(document.getElementById('box'), {}).then(canvas => {
  152. const dataURL = canvas.toDataURL()
  153. this.imgSrc = dataURL
  154. uni.showToast({
  155. title:'标签图片已生成,可以保存或者下载',
  156. icon: 'none',
  157. duration: 2000
  158. })
  159. });
  160. },
  161. getAction() {
  162. let data = ['下载', '保存']
  163. uni.showActionSheet({
  164. itemList: data,
  165. success: (res) => {
  166. switch (res.tapIndex) {
  167. case 0:
  168. this.downloadImage()
  169. break;
  170. case 1:
  171. this.getSave()
  172. break;
  173. }
  174. },
  175. fail: function(res) {
  176. }
  177. });
  178. },
  179. downloadImage() {
  180. // const dataURL = canvas.toDataURL('image/png')
  181. const creatDom = document.createElement('a')
  182. document.body.appendChild(creatDom)
  183. creatDom.href = this.imgSrc
  184. creatDom.download = this.time + '样品标签图片'
  185. creatDom.click()
  186. },
  187. getSave() {
  188. let pp = {
  189. paramWhere: [{
  190. id_: this.id
  191. }],
  192. tableName: "t_lhwtsqb",
  193. paramCond: {
  194. biao_qian_tu_pian: this.imgSrc,
  195. update_time_: this.time,
  196. update_by_: this.userid
  197. }
  198. }
  199. let data = this.$sig(pp)
  200. this.$http.post("ibps/business/v3/sys/universal/updateDatasContextTable", data).then(res => {
  201. if (res.data.state == 200) {
  202. uni.showToast({
  203. title: '提交成功',
  204. icon: 'none',
  205. duration: 2000
  206. })
  207. this.$emit('saveSuccees')
  208. } else {
  209. uni.showToast({
  210. title: '提交失败',
  211. icon: 'none',
  212. duration: 2000
  213. })
  214. }
  215. });
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .bg {
  222. // height: auto;
  223. }
  224. .tagBox {
  225. width: 700rpx;
  226. height: 420rpx;
  227. border: 1rpx solid #000000;
  228. padding: 20rpx;
  229. display: flex;
  230. justify-content: space-around;
  231. flex-direction: column;
  232. margin: 20rpx auto;
  233. border-radius: 15rpx;
  234. background-color: #fff;
  235. }
  236. .la {
  237. display: flex;
  238. align-items: center;
  239. }
  240. .lh {
  241. // line-height: auto;
  242. font-size: 28rpx;
  243. display: flex;
  244. align-items: center;
  245. }
  246. </style>