sampleTag.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.type}}</view>
  28. </view>
  29. <view class="lh">
  30. <view>存储条件:</view>
  31. <view>{{item1.condition}}</view>
  32. </view>
  33. <view class="lh">
  34. <view>流转状态:</view>
  35. <view>▢待检,▢已检,▢留样</view>
  36. </view>
  37. <view class="lh">
  38. <view>样品数量:</view>
  39. <view>{{index2+1}}/{{item1.num}}支</view>
  40. </view>
  41. <view>
  42. <vue-barcode :value="item1.serial" :width="2" :height="40"></vue-barcode>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <u-button type="primary" class="btn" @click="getAction()" 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 * from t_lhypb where parent_id_ = '${id}'`
  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. }
  110. list.push(obj)
  111. }
  112. if (item.yang_pin_lei_er_ != '' && parseInt(item.shu_liang_er_) > 0) {
  113. let obj = {
  114. name: item.yang_pin_ming_che,
  115. serial: item.yang_pin_bian_hao,
  116. type: item.yang_pin_lei_er_,
  117. num: item.shu_liang_er_,
  118. condition: item.yang_pin_yun_shu_
  119. }
  120. list.push(obj)
  121. }
  122. if (item.yang_pin_lei_san_ != '' && parseInt(item.shu_liang_san_) > 0) {
  123. let obj = {
  124. name: item.yang_pin_ming_che,
  125. serial: item.yang_pin_bian_hao,
  126. type: item.yang_pin_lei_san_,
  127. num: item.shu_liang_san_,
  128. condition: item.yang_pin_yun_san
  129. }
  130. list.push(obj)
  131. }
  132. if (item.yang_pin_lei_si_ != '' && parseInt(item.shu_liang_si_) > 0) {
  133. let obj = {
  134. name: item.yang_pin_ming_che,
  135. serial: item.yang_pin_bian_hao,
  136. type: item.yang_pin_lei_si_,
  137. num: item.shu_liang_si_,
  138. condition: item.yang_pin_yun_si_
  139. }
  140. list.push(obj)
  141. }
  142. })
  143. this.list = list
  144. if (list.length > 0) {
  145. this.$nextTick(() => {
  146. this.getBtn()
  147. })
  148. }
  149. }
  150. })
  151. },
  152. getBtn() {
  153. // document.getElementById("qrcode").appendChild(canvas);
  154. //点击生成canvas转换成base64的图片
  155. var width = document.getElementById('box').offsetWidth,
  156. height = document.getElementById('box').offsetHeight,
  157. scale = window.devicePixelRatio; //放大倍数
  158. html2canvas(document.getElementById('box'), {}).then(canvas => {
  159. const dataURL = canvas.toDataURL()
  160. this.imgSrc = dataURL
  161. uni.showToast({
  162. title: '标签图片已生成,可以保存或者下载',
  163. icon: 'none',
  164. duration: 2000
  165. })
  166. });
  167. },
  168. getAction() {
  169. let data = ['下载', '保存']
  170. uni.showActionSheet({
  171. itemList: data,
  172. success: (res) => {
  173. switch (res.tapIndex) {
  174. case 0:
  175. this.downloadImage()
  176. break;
  177. case 1:
  178. this.getSave()
  179. break;
  180. }
  181. },
  182. fail: function(res) {}
  183. });
  184. },
  185. downloadImage() {
  186. // const dataURL = canvas.toDataURL('image/png')
  187. const creatDom = document.createElement('a')
  188. document.body.appendChild(creatDom)
  189. creatDom.href = this.imgSrc
  190. creatDom.download = this.time + '样品标签图片'
  191. creatDom.click()
  192. },
  193. getSave() {
  194. let pp = {
  195. paramWhere: [{
  196. id_: this.id
  197. }],
  198. tableName: "t_lhwtsqb",
  199. paramCond: {
  200. biao_qian_tu_pian: this.imgSrc,
  201. update_time_: this.time,
  202. update_by_: this.userid
  203. }
  204. }
  205. let data = this.$sig(pp)
  206. this.$http.post("ibps/business/v3/sys/universal/updateDatasContextTable", data).then(res => {
  207. if (res.data.state == 200) {
  208. uni.showToast({
  209. title: '提交成功',
  210. icon: 'none',
  211. duration: 2000
  212. })
  213. this.$emit('saveSuccees')
  214. } else {
  215. uni.showToast({
  216. title: '提交失败',
  217. icon: 'none',
  218. duration: 2000
  219. })
  220. }
  221. });
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .bg {
  228. // height: auto;
  229. }
  230. .tagBox {
  231. width: 700rpx;
  232. height: 420rpx;
  233. border: 1rpx solid #000000;
  234. padding: 20rpx;
  235. display: flex;
  236. justify-content: space-around;
  237. flex-direction: column;
  238. margin: 20rpx auto;
  239. border-radius: 15rpx;
  240. background-color: #fff;
  241. }
  242. .la {
  243. display: flex;
  244. align-items: center;
  245. }
  246. .lh {
  247. // line-height: auto;
  248. font-size: 28rpx;
  249. display: flex;
  250. align-items: center;
  251. }
  252. </style>