camera-scan-code.uvue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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>
  11. <view>
  12. <text class="demo-view-label">{{ item?.name ?? ''}}</text>
  13. </view>
  14. </swiper-item>
  15. </swiper>
  16. <view class="camera-scan-code-back-wrap">
  17. <button class="btn block bg-blue lg round" @click="chooseImage">
  18. 浏览相册
  19. </button>
  20. </view>
  21. <view class="camera-scan-code-table">
  22. <view class="camera-scan-code-table-pair" v-if="joinRecord.imgname!=''" >
  23. <view class="camera-scan-code-table-pair-label">
  24. <text>已存图片(最多能存{{joinRecord.num}}张)</text>
  25. </view>
  26. <view class="camera-scan-code-table-pair-value">
  27. <text class="txt">{{joinRecord.imgname}}</text>
  28. </view>
  29. </view>
  30. <view class="camera-scan-code-table-pair">
  31. <view class="camera-scan-code-table-pair-label">
  32. <text>待存图片</text>
  33. </view>
  34. <view class="camera-scan-code-table-pair-value">
  35. <!--
  36. <checkbox-group @change="checkboxChange">
  37. <view v-for="(item, index) in data">
  38. <checkbox :value="item.name" :checked="true"></checkbox>
  39. <view>{{ dyImgName+"-"+(index+1)+".jpg"}}</view>
  40. </view>
  41. </checkbox-group>-->
  42. <text class="txt">{{ dyImgName+"-"+(imgArrLen + 1)+".jpg"}}</text>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="camera-scan-code-back-wrap">
  47. <button class="btn block bg-blue lg round" @click="saveImage">
  48. 保存图片
  49. </button>
  50. </view>
  51. <view class="camera-scan-code-back-wrap">
  52. <button type="default" class="btn bg-blue round" @click="navigateBack">返回拍照</button>
  53. </view>
  54. <view class="camera-scan-code-back-wrap">
  55. <button type="default" class="btn bg-blue round" @click="navigateExit">退出拍照</button>
  56. </view>
  57. </view>
  58. </template>
  59. <script lang="uts">
  60. type CameraScanCodeResult = {
  61. type : string | null;
  62. result : string | null;
  63. }
  64. type ImageItem = {
  65. image : string,
  66. name : string,
  67. checked : boolean
  68. }
  69. import { getJoinList, JoinRecord, updateData } from '@/api/work';
  70. export default {
  71. data() {
  72. return {
  73. result: null as CameraScanCodeResult | null,
  74. swiperDotIndex: 0 as number,
  75. path: '',
  76. recordId: 0,
  77. imgArrLen: 0,
  78. joinRecord: {
  79. sxid: 0,
  80. senum: 0,
  81. photoitem: "",
  82. productno: "",
  83. descb:"",
  84. part: "",
  85. date: "",
  86. partno : "",
  87. num : 0,
  88. status : 1,
  89. urlspl : "",
  90. imgname : "",
  91. urlpdt : "",
  92. pid: 0,
  93. workorder: "",
  94. invname: ""
  95. } as JoinRecord,
  96. num: 0,
  97. dyImgName: '',
  98. data: [{
  99. image: '/static/images/banner/banner01.png',
  100. name: 'banner01.png',
  101. checked: true,
  102. },
  103. ] as ImageItem[]
  104. }
  105. },
  106. onLoad(options) {
  107. this.path = options?.['path'] ?? ''
  108. let recordId = options?.['recordId'] ?? ''
  109. let num = options?.['num'] ?? ''
  110. console.log(this.path)
  111. if (this.path != '') {
  112. this.data = []
  113. this.data.push({ image: this.path, name: '', checked: true })
  114. }
  115. if (recordId != '') {
  116. this.recordId = parseInt(recordId)
  117. 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) => {
  118. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
  119. if (dataList != null && dataList.length > 0) {
  120. dataList.forEach(item => {
  121. if (item != null) {
  122. let record = JSON.parse<JoinRecord>(item.toJSONString());
  123. if (record != null) {
  124. this.num = record.num;
  125. this.dyImgName = record.workorder + record.invname + record.part + record.photoitem + record.partno;
  126. this.joinRecord = record
  127. this.imgArrLen = record.imgname.indexOf(",")>-1? record.imgname.split(",").length : (record.imgname!=''?1:0)
  128. }
  129. }
  130. });
  131. }
  132. });
  133. }
  134. if (num != '') {
  135. this.num = parseInt(num)
  136. }
  137. },
  138. methods: {
  139. navigateBack() {
  140. //uni.navigateBack()
  141. uni.navigateTo({
  142. url: `/pages/work/record/Camera?id=${this.recordId}&num=${this.num}`
  143. })
  144. },
  145. navigateExit(){
  146. uni.navigateTo({
  147. url: `/pages/work/record/InfoDetail?id=${this.joinRecord.pid}`
  148. })
  149. },
  150. checkboxChange() {
  151. console.log("选择图片名称")
  152. },
  153. chooseImage() {
  154. uni.chooseImage({
  155. sourceType: ['album'],
  156. success: (res) => {
  157. //this.data = res.tempFilePaths; // 获取选中的图片路径
  158. this.data = []
  159. for (let i = 0; i < res.tempFilePaths.length; i++) {
  160. this.data.push({ image: res.tempFilePaths[i], name: '', checked: true })
  161. }
  162. },
  163. fail: (err) => {
  164. console.error('选择图片失败', err);
  165. }
  166. });
  167. },
  168. saveImage() {
  169. //保存图片进入相册文件
  170. if(this.path==''){
  171. uni.showToast({
  172. title: '没有拍照文件',
  173. icon: 'error',
  174. duration: 2000
  175. });
  176. return;
  177. }
  178. if(this.imgArrLen == this.joinRecord.num){
  179. uni.showToast({
  180. title: '拍照图片已满',
  181. icon: 'error',
  182. duration: 2000
  183. });
  184. return;
  185. }
  186. /*
  187. uni.saveImageToPhotosAlbum({
  188. filePath: this.path,
  189. success: () => {
  190. uni.showToast({
  191. title: "保存成功!",
  192. });
  193. },
  194. fail: () => {
  195. uni.showToast({
  196. title: "保存失败",
  197. });
  198. },
  199. }); */
  200. let updateImgs = ''
  201. let updateNames = ''
  202. let updateStatus = ''
  203. if(this.imgArrLen == 0){
  204. updateImgs = this.path
  205. updateNames = this.dyImgName+"-"+(this.imgArrLen + 1)+".jpg"
  206. }else{
  207. updateImgs = this.joinRecord.urlpdt + "," + this.path
  208. updateNames = this.joinRecord.imgname + "," + (this.dyImgName+"-"+(this.imgArrLen + 1)+".jpg")
  209. }
  210. let updatedData = "imgname='" + updateNames + "',urlpdt='" + updateImgs + "'"
  211. if(this.joinRecord.num === this.imgArrLen + 1 ){
  212. updateStatus = "status='3'"
  213. updatedData = updatedData + "," + updateStatus
  214. }else if(this.joinRecord.status === 1){
  215. updateStatus = "status='2'"
  216. updatedData = updatedData + "," + updateStatus
  217. }
  218. console.log(updatedData)
  219. updateData('app_media_record', updatedData, 'sxid', this.recordId.toString()).then((res : UTSJSONObject) => {
  220. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
  221. if (dataList != null && dataList.length > 0) {
  222. console.log(dataList[0])
  223. uni.showToast({
  224. title: "保存成功!",
  225. });
  226. /*
  227. uni.reLaunch({
  228. url: '/pages/record/camera-scan-code?path='+this.path+'&recordId='+this.recordId+'&num='+this.num
  229. }); */
  230. }
  231. });
  232. },
  233. previewSingleImage(imageUrl : string) {
  234. uni.previewImage({
  235. urls: [imageUrl], // 需要预览的图片链接列表
  236. current: 0, // 当前显示图片的索引
  237. indicator: 'number', // 图片指示器样式
  238. loop: false // 是否可循环预览
  239. });
  240. },
  241. handleScanCode(ev : UniCameraScanCodeEvent) {
  242. const deatil = ev.detail;
  243. this.result = {
  244. type: deatil.type,
  245. result: deatil.result
  246. } as CameraScanCodeResult
  247. }
  248. }
  249. }
  250. </script>
  251. <style>
  252. .camera-scan-code-back-wrap {
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. }
  257. .camera-scan-code-table {
  258. background-color: white;
  259. margin-top: 20px;
  260. }
  261. .camera-scan-code-table-pair {
  262. height: 150px;
  263. flex-direction: column;
  264. justify-content: space-between;
  265. align-items: center;
  266. }
  267. .camera-scan-code-table-pair-label {
  268. flex-grow: 1;
  269. margin-left: 15px;
  270. }
  271. .camera-scan-code-table-pair-value {
  272. flex-grow: 2;
  273. }
  274. .camera-scan-code-table-pair-value .txt {
  275. font-size: 14px;
  276. }
  277. .camera-scan-code-table-top-line {
  278. border-top: 1px solid #eee;
  279. }
  280. .swiper {
  281. height: 300rpx;
  282. }
  283. .swiper-box {
  284. height: 150px;
  285. }
  286. .swiper-item {
  287. /* #ifndef APP-NVUE */
  288. display: flex;
  289. /* #endif */
  290. flex-direction: column;
  291. justify-content: center;
  292. align-items: center;
  293. color: #fff;
  294. height: 300rpx;
  295. line-height: 300rpx;
  296. }
  297. .btn {
  298. margin-top: 30px;
  299. height: 45px;
  300. }
  301. </style>