sampleTag.vue 6.9 KB

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