photo.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <view
  3. style="
  4. background-color: #f7f7f7;
  5. padding-top: 88rpx;
  6. height: calc(100vh - 88rpx);
  7. "
  8. >
  9. <uni-nav-bar
  10. @clickLeft="clickLeft"
  11. left-icon="back"
  12. title="查看图片"
  13. backgroundColor="#F7F7F7"
  14. ></uni-nav-bar>
  15. <view class="search-item">
  16. <u-dropdown>
  17. <u-dropdown-item
  18. @change="dropDownChange"
  19. v-model="searchObj.is_pest"
  20. title="害虫筛选"
  21. :options="pestOptions"
  22. ></u-dropdown-item>
  23. </u-dropdown>
  24. <span v-if="!delShow" class="right" @click="imgOperate"> 管理 </span>
  25. <span v-else class="right" @click="delShow = false"> 完成 </span>
  26. </view>
  27. <view style="padding: 0 48rpx" v-if="searchObj.is_pest != '2'">
  28. <u-search
  29. bg-color="#fff"
  30. height="92"
  31. shape="square"
  32. placeholder="请输入害虫名称"
  33. v-model="searchObj.pest_name"
  34. @search="dropDownChange"
  35. :show-action="false"
  36. ></u-search>
  37. </view>
  38. <u-calendar
  39. v-model="calendarShow"
  40. mode="range"
  41. @maxDate="maxDate"
  42. @change="change"
  43. range-color="#999"
  44. btn-type="success"
  45. active-bg-color="#0BBC58"
  46. range-bg-color="rgba(11,188,88,0.13)"
  47. ></u-calendar>
  48. <view class="tile-item">
  49. <view @click="calendarShow = true" class="calendar"
  50. >{{ start_time }} <span style="margin: 0 40rpx"> -</span>
  51. {{ end_time }}</view
  52. >
  53. <u-icon
  54. name="camera"
  55. color="#018B3F"
  56. size="52"
  57. @click="takephoto"
  58. ></u-icon>
  59. </view>
  60. <view class="imglist" v-if="imglists.length > 0">
  61. <view class="imglist_box" v-for="(item, index) in imglists" :key="index">
  62. <view class="top"
  63. >识别:{{ item.indentify_count }}
  64. <span
  65. class="yficonfont icon-shanchu float-right"
  66. v-if="delShow"
  67. @click="delImage(item)"
  68. ></span>
  69. <!-- <u-icon v-if="delShow" @click="delImage(item)" class="float-right" name="trash-fill" color="#FF5951" size="28"></u-icon> -->
  70. </view>
  71. <!-- <image class="img-flex" v-if="showPlaceholder" src="/static/images/image.png"></image> -->
  72. <image
  73. class="img-flex"
  74. @error="handleImgErr($event, index)"
  75. :src="item.addr + '?x-oss-process=image/resize,w_130/quality,q_50'"
  76. mode=""
  77. @click="imageDetail(item)"
  78. ></image>
  79. <view class="bottom">{{ item.addtime }}</view>
  80. </view>
  81. </view>
  82. <view v-else class="notip"> 暂无数据 </view>
  83. </view>
  84. </template>
  85. <script>
  86. import jsencrypt from '@/components/jsencrypt/jsencrypt.vue';
  87. export default {
  88. data() {
  89. return {
  90. maxDate: '2050-12-31',
  91. value1: '',
  92. value2: '',
  93. searchObj: {
  94. is_pest: '',
  95. pest_name: '',
  96. },
  97. pestOptions: [
  98. { label: '全部', value: '' },
  99. { label: '有虫', value: '1' },
  100. { label: '无虫', value: '2' },
  101. ],
  102. timeend: '',
  103. timestart: '',
  104. imglists: [],
  105. page: 1,
  106. device_type: '',
  107. device_id: '',
  108. d_id: '',
  109. calendarShow: false,
  110. start_time: '',
  111. end_time: '',
  112. delShow: false,
  113. loadMore: true,
  114. noImage: '/static/images/image.png',
  115. };
  116. },
  117. methods: {
  118. handleImgErr(e, index) {
  119. console.log(e, '图片加载出错了');
  120. this.imglists[index].addr = this.noImage;
  121. // this.showPlaceholder = true
  122. },
  123. imageDetail(item) {
  124. console.log(item);
  125. if (this.delShow) {
  126. return;
  127. }
  128. uni.navigateTo({
  129. url:
  130. '/pages/cb/cbd/equip-set/photoResults' +
  131. '?d_id=' +
  132. this.d_id +
  133. '&device_id=' +
  134. this.device_id +
  135. '&device_type=' +
  136. this.device_type +
  137. '&time=' +
  138. item.addtime,
  139. });
  140. },
  141. imgOperate() {
  142. this.delShow = true;
  143. },
  144. clickLeft() {
  145. uni.navigateBack();
  146. },
  147. dropDownChange() {
  148. this.loadMore = true;
  149. this.page = 1;
  150. this.imglists = [];
  151. this.getImgData();
  152. },
  153. change(e) {
  154. this.loadMore = true;
  155. console.log(e);
  156. this.start_time = e.startDate;
  157. this.end_time = e.endDate;
  158. this.page = 1;
  159. this.imglists = [];
  160. this.getImgData();
  161. },
  162. async getImgData() {
  163. const res = await this.$myRequest({
  164. url: '/api/api_gateway?method=new_gateway.photo_info.photo_list',
  165. data: {
  166. id: this.d_id,
  167. device_type_id: this.device_type,
  168. page: this.page,
  169. page_size: 20,
  170. start: +new Date(this.start_time + ' 00:00:00') / 1000,
  171. end: +new Date(this.end_time + ' 23:59:59') / 1000,
  172. ...this.searchObj,
  173. },
  174. });
  175. if (res.data.length == 0) {
  176. // 加载完了
  177. this.loadMore = false;
  178. return;
  179. }
  180. this.imglists = this.imglists.concat(res.data);
  181. },
  182. // 删除
  183. delImage(item) {
  184. uni.showModal({
  185. title: '提示',
  186. content: '确认删除?',
  187. success: async (res) => {
  188. if (res.confirm) {
  189. const res = await this.$myRequest({
  190. url: '/api/api_gateway?method=new_gateway.photo_info.delete_photo',
  191. data: {
  192. device_type_id: this.device_type,
  193. ids: item.id,
  194. },
  195. });
  196. this.delShow = false;
  197. uni.showToast({
  198. title: res.msg,
  199. duration: 2000,
  200. });
  201. this.imglists = [];
  202. this.getImgData();
  203. } else if (res.cancel) {
  204. }
  205. },
  206. });
  207. },
  208. onReachBottom() {
  209. if (this.loadMore) {
  210. this.page++;
  211. this.getImgData();
  212. }
  213. },
  214. anew() {
  215. this.discern('again');
  216. this.imgbg = true;
  217. },
  218. examine(url) {
  219. console.log(url);
  220. var imgarr = [];
  221. imgarr.push(url.image);
  222. console.log(imgarr);
  223. uni.previewImage({
  224. urls: imgarr,
  225. });
  226. },
  227. async takephoto() {
  228. //拍照
  229. const res = await this.$myRequest({
  230. url: '/api/api_gateway?method=new_gateway.device_info.send_control',
  231. data: {
  232. device_type_id: this.device_type,
  233. id: this.device_id,
  234. COMMAND:this.device_type=='33'?'takephoto': '0004',
  235. },
  236. });
  237. console.log(res);
  238. if (res == true) {
  239. uni.showToast({
  240. title: '指令下发成功!',
  241. duration: 2000,
  242. });
  243. } else {
  244. uni.showToast({
  245. title: '指令下发失败!',
  246. duration: 2000,
  247. icon: 'none',
  248. });
  249. }
  250. },
  251. },
  252. onLoad(option) {
  253. console.log('图片详情', option);
  254. this.device_id = option.device_id;
  255. this.d_id = option.d_id;
  256. this.device_type = option.device_type;
  257. let endTime = +new Date() / 1000;
  258. let startTime = endTime - 60 * 60 * 24;
  259. this.end_time = this.formatTime(endTime * 1000, 'yyyy-MM-dd');
  260. this.start_time = this.formatTime(startTime * 1000, 'yyyy-MM-dd');
  261. // this.imglists = []
  262. this.getImgData();
  263. },
  264. };
  265. </script>
  266. <style lang="scss" scoped>
  267. ::v-deep .u-calendar__action {
  268. display: flex;
  269. justify-content: space-around;
  270. .u-calendar__action__text {
  271. line-height: 25px;
  272. }
  273. }
  274. ::v-deep .u-flex {
  275. display: flex;
  276. }
  277. page {
  278. background: #f7f7f7;
  279. .notip {
  280. text-align: center;
  281. color: #666666;
  282. margin-top: 100rpx;
  283. }
  284. .search-item {
  285. // padding: 0rpx 48rpx;
  286. box-sizing: border-box;
  287. background: #f7f7f7;
  288. line-height: 80rpx;
  289. color: #656c74;
  290. position: relative;
  291. .right {
  292. position: absolute;
  293. z-index: 11;
  294. right: 48rpx;
  295. top: 0;
  296. }
  297. .right::before {
  298. content: '|';
  299. color: #c3cbcf;
  300. padding-right: 10rpx;
  301. }
  302. }
  303. .tile-item {
  304. margin-top: 16rpx;
  305. padding: 0rpx 48rpx;
  306. box-sizing: border-box;
  307. height: 92rpx;
  308. line-height: 92rpx;
  309. display: flex;
  310. justify-content: space-between;
  311. background: #f7f7f7;
  312. .calendar {
  313. width: 83%;
  314. background-color: #fff;
  315. border-radius: 10rpx;
  316. padding: 0 18rpx;
  317. color: #5c5c5c;
  318. text-align: center;
  319. }
  320. .camera {
  321. }
  322. }
  323. .imglist {
  324. display: flex;
  325. flex-flow: row wrap;
  326. padding: 0rpx 48rpx;
  327. box-sizing: border-box;
  328. background: #f7f7f7;
  329. margin-top: 6rpx;
  330. // justify-content: space-around;
  331. // gap: 16rpx;
  332. .imglist_box {
  333. box-sizing: border-box;
  334. flex: 0 0 33.3333%;
  335. height: 224rpx;
  336. padding: 6rpx;
  337. border-radius: 4rpx;
  338. position: relative;
  339. .top {
  340. position: absolute;
  341. top: 6rpx;
  342. left: 6rpx;
  343. background: rgba(0, 0, 0, 0.6);
  344. color: #fff;
  345. border-top-left-radius: 4rpx;
  346. border-top-right-radius: 4rpx;
  347. padding: 0 20rpx;
  348. font-size: 10px;
  349. z-index: 1;
  350. width: 75.5%;
  351. .float-right {
  352. float: right;
  353. color: #ff5951;
  354. font-size: 36rpx;
  355. }
  356. }
  357. .bottom {
  358. position: absolute;
  359. bottom: 6rpx;
  360. left: 6rpx;
  361. background: rgba(0, 0, 0, 0.6);
  362. color: #fff;
  363. border-bottom-left-radius: 4rpx;
  364. border-bottom-right-radius: 4rpx;
  365. text-align: center;
  366. font-size: 10px;
  367. width: 94.5%;
  368. padding: 4rpx 0;
  369. }
  370. .img-flex {
  371. border-radius: 4rpx;
  372. width: 100%;
  373. height: 100%;
  374. }
  375. }
  376. }
  377. }
  378. </style>