camera-scan-code.uvue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view style="flex:1">
  3. <!--
  4. <camera style="width: 100%; height: 300px;" :resolution="'high'" :mode="'scanCode'" @scancode="handleScanCode">
  5. </camera> -->
  6. <swiper class="swiper-box my-swiper" :current="swiperDotIndex" :indicator-dots="true" >
  7. <swiper-item v-for="item in data" >
  8. <view class="swiper-item" @tap="previewSingleImage(item.image)">
  9. <image class="my-image" :src="item.image" mode="aspectFill" />
  10. <view class="img-name">{{ item.name }}</view>
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. <view class="camera-scan-code-back-wrap">
  15. <button class="btn block bg-blue lg round" @click="chooseImage">
  16. 浏览相册
  17. </button>
  18. </view>
  19. <view class="camera-scan-code-table">
  20. <view class="camera-scan-code-table-pair">
  21. <view class="camera-scan-code-table-pair-label">
  22. <text></text>
  23. </view>
  24. <view class="camera-scan-code-table-pair-value">
  25. <checkbox-group @change="checkboxChange">
  26. <view v-for="(item, index) in data">
  27. <checkbox :value="item.name" :checked="true"></checkbox>
  28. {{ dyImgName+"-"+(index+1)}}
  29. </view>
  30. </checkbox-group>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="camera-scan-code-back-wrap">
  35. <button class="btn block bg-blue lg round" @click="saveImage">
  36. 保存图片
  37. </button>
  38. </view>
  39. <view class="camera-scan-code-back-wrap">
  40. <button type="default" class="btn bg-blue round" @click="navigateBack">返回拍照</button>
  41. </view>
  42. </view>
  43. </template>
  44. <script lang="uts">
  45. type CameraScanCodeResult = {
  46. type : string | null;
  47. result : string | null;
  48. }
  49. type ImageItem={
  50. image:string,
  51. name:string,
  52. checked: boolean
  53. }
  54. import { getJoinList, JoinRecord, updateData } from '@/api/work';
  55. export default {
  56. data() {
  57. return {
  58. result: null as CameraScanCodeResult | null,
  59. swiperDotIndex: 0 as number,
  60. recordId: 0,
  61. num:0,
  62. dyImgName: '',
  63. data: [{
  64. image: '/static/images/banner/banner01.png',
  65. name: 'banner01.png',
  66. checked: true,
  67. },
  68. ] as ImageItem[]
  69. }
  70. },
  71. onLoad(options) {
  72. let path = options?.['path'] ?? ''
  73. let recordId = options?.['recordId'] ?? ''
  74. let num = options?.['num'] ?? ''
  75. console.log(path)
  76. if(path!=''){
  77. this.data = []
  78. this.data.push({image:path, name:'', checked:true})
  79. }
  80. if(recordId!=''){
  81. this.recordId = parseInt(recordId)
  82. getJoinList('app_media_record as r','app_media_info as i', 'r.*,i.workorder,i.invname', 'r.pid=i.pdid', 'sxid', recordId, null).then((res:UTSJSONObject) => {
  83. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
  84. if(dataList!=null && dataList.length>0){
  85. dataList.forEach(item =>{
  86. if(item!=null){
  87. let record = JSON.parse<JoinRecord>(item.toJSONString());
  88. if(record!=null){
  89. this.num = record.num;
  90. this.dyImgName = record.workorder+record.invname+record.part+record.photoitem+record.partno;
  91. }
  92. }
  93. });
  94. }
  95. });
  96. }
  97. if(num!=''){
  98. this.num = parseInt(num)
  99. }
  100. },
  101. methods: {
  102. navigateBack() {
  103. uni.navigateBack()
  104. },
  105. checkboxChange(){
  106. console.log("选择图片名称")
  107. },
  108. chooseImage() {
  109. uni.chooseImage({
  110. sourceType: ['album'],
  111. success: (res) => {
  112. //this.data = res.tempFilePaths; // 获取选中的图片路径
  113. this.data = []
  114. for(let i=0; i<res.tempFilePaths.length; i++){
  115. this.data.push({image: res.tempFilePaths[i], name:'', checked:true})
  116. }
  117. },
  118. fail: (err) => {
  119. console.error('选择图片失败', err);
  120. }
  121. });
  122. },
  123. saveImage() {
  124. //let data = 'imgname='++',urlpdt=';
  125. let updateImgs = this.data.filter(item=>item.checked == true).map(item=>item.image);
  126. let updateNames = this.data.filter(item=>item.checked == true).map(item=>item.name);
  127. let updatedData = 'imgname='+ updateNames.join(",") +',urlpdt='+ updateImgs.join(",")
  128. updateData('app_media_record',updatedData, 'sxid', this.recordId.toString()).then((res:UTSJSONObject) => {
  129. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
  130. if(dataList!=null && dataList.length>0){
  131. console.log(dataList[0])
  132. }
  133. });
  134. },
  135. previewSingleImage(imageUrl:string) {
  136. uni.previewImage({
  137. urls: [imageUrl], // 需要预览的图片链接列表
  138. current: 0, // 当前显示图片的索引
  139. indicator: 'number', // 图片指示器样式
  140. loop: false // 是否可循环预览
  141. });
  142. },
  143. handleScanCode(ev : UniCameraScanCodeEvent) {
  144. const deatil = ev.detail;
  145. this.result = {
  146. type: deatil.type,
  147. result: deatil.result
  148. } as CameraScanCodeResult
  149. }
  150. }
  151. }
  152. </script>
  153. <style>
  154. .camera-scan-code-back-wrap {
  155. display: flex;
  156. justify-content: center;
  157. align-items: center;
  158. }
  159. .camera-scan-code-table {
  160. background-color: white;
  161. margin-top: 20px;
  162. }
  163. .camera-scan-code-table-pair {
  164. height: 250px;
  165. flex-direction: row;
  166. justify-content: space-between;
  167. align-items: center;
  168. }
  169. .camera-scan-code-table-pair-label {
  170. flex-grow: 1;
  171. margin-left: 15px;
  172. }
  173. .camera-scan-code-table-pair-value{
  174. flex-grow: 2;
  175. }
  176. .camera-scan-code-table-top-line {
  177. border-top: 1px solid #eee;
  178. }
  179. .swiper {
  180. height: 300rpx;
  181. }
  182. .swiper-box {
  183. height: 150px;
  184. }
  185. .swiper-item {
  186. /* #ifndef APP-NVUE */
  187. display: flex;
  188. /* #endif */
  189. flex-direction: column;
  190. justify-content: center;
  191. align-items: center;
  192. color: #fff;
  193. height: 300rpx;
  194. line-height: 300rpx;
  195. }
  196. .btn {
  197. margin-top: 30px;
  198. height: 45px;
  199. }
  200. </style>