economicsPlant.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <view>
  3. <!-- 搜索 -->
  4. <!-- <u-search :disabled="true" margin="15rpx auto" :input-style="{width: '20rpx'}" input-align="center" :animation="true"
  5. placeholder="搜索作物名称" shape="square" :show-action="false" v-model="keyword"></u-search> -->
  6. <!-- 作物列表 -->
  7. <view class="plantList_ul">
  8. <!-- 上次定位 -->
  9. <view class="plantList_li" v-if="lastTimeShow">
  10. <view class="plantList_tlt"> 上次选择 </view>
  11. <view class="plantList_li_ul">
  12. <view
  13. class="plantList_li_List"
  14. @click="
  15. recognizeData(
  16. allPlantData[lastTimeIndex].num,
  17. allPlantData[lastTimeIndex].name,
  18. lastTimeIndex
  19. )
  20. "
  21. >
  22. <image
  23. :src="
  24. 'http://web.hnyfwlw.com:58003/bigservers/' +
  25. allPlantData[lastTimeIndex].img
  26. "
  27. mode=""
  28. ></image>
  29. <view class="">
  30. {{ allPlantData[lastTimeIndex].name }}
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 全部 -->
  36. <view class="plantList_li">
  37. <view class="plantList_tlt"> 全部 </view>
  38. <view class="plantList_li_ul">
  39. <view
  40. @click="recognizeData(item.num, item.name, index)"
  41. class="plantList_li_List"
  42. v-for="(item, index) in allPlantData"
  43. :key="index"
  44. >
  45. <image
  46. :src="'http://web.hnyfwlw.com:58003/bigservers/' + item.img"
  47. mode=""
  48. ></image>
  49. <view class="">
  50. {{ item.name }}
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 其他 -->
  56. <!-- <view class="plantList_li">
  57. <view class="plantList_tlt">
  58. 其他
  59. <text>(此项目开发中,结果可能会有误差)</text>
  60. </view>
  61. <view class="plantList_li_ul">
  62. <view class="plantList_li_List" @click="restsData()">
  63. <image :src="'http://web.hnyfwlw.com:58003/bigservers/' + 'images/detail_9.png'" mode=""></image>
  64. <view class="">
  65. 其他
  66. </view>
  67. </view>
  68. </view>
  69. </view> -->
  70. </view>
  71. <!-- 裁剪组件 -->
  72. <kps-image-cutter
  73. @ok="axiosData"
  74. @cancel="oncancle"
  75. :url="url"
  76. :fixed="false"
  77. :blob="false"
  78. :maxWidth="500"
  79. :maxHeight="500"
  80. ></kps-image-cutter>
  81. <!-- 弹框 -->
  82. <u-modal
  83. :mask-close-able="true"
  84. @cancel="insectData('1')"
  85. @confirm="insectData('2')"
  86. confirm-text="虫害"
  87. cancel-text="病害"
  88. v-model="show"
  89. :show-cancel-button="true"
  90. :content="content"
  91. ></u-modal>
  92. <!--loading-->
  93. <ourLoading v-show="loadingShow" isFullScreen active text="识别中..." />
  94. </view>
  95. </template>
  96. <script>
  97. import kpsImageCutter from '@/components/ksp-image-cutter/ksp-image-cutter.vue'; //裁剪图片
  98. export default {
  99. data() {
  100. return {
  101. path:'',
  102. keyword: '', //搜索
  103. show: false,
  104. content: '请选择测试虫害还是病害',
  105. allPlantData: [
  106. // {
  107. // 'name': '棉花',
  108. // 'img': 'images/plant_2.jpg',
  109. // 'num': '21'
  110. // },
  111. // {
  112. // 'name': '茶',
  113. // 'img': 'images/plant_1.jpg',
  114. // 'num': '22'
  115. // },
  116. {
  117. name: '油菜',
  118. img: 'images/plant_3.jpg',
  119. num: '13',
  120. },
  121. ],
  122. url: '', //裁剪
  123. serialNum: '', //获取到作物序号码
  124. urlData: {}, //图片全部信息
  125. urlName: '', //识别失败作物名称
  126. insectNum: '', //区别病虫害 1病 2虫
  127. lastTimeShow: false, //是否显示上次选择
  128. lastTimeIndex: null, //上次选择下标
  129. loadingShow: false, //加载
  130. };
  131. },
  132. methods: {
  133. recognizeData(num, name, index) {
  134. console.log(index);
  135. uni.setStorage({
  136. key: 'lastTime',
  137. data: index,
  138. success: function () {
  139. console.log('success');
  140. },
  141. });
  142. this.urlName = name;
  143. this.insectNum = '';
  144. this.serialNum = num;
  145. console.log('-------------------------------- recogonization');
  146. uni.chooseImage({
  147. count: 1,
  148. sourceType: ['camera', 'album'], //从相册选择
  149. success: (res) => {
  150. // 设置url的值,显示控件
  151. console.log(res);
  152. this.urlData = res.tempFiles[0];
  153. this.url = res.tempFilePaths[0];
  154. this.urlFile = res.tempFilePaths[0]; //失败跳转显示的图片
  155. },
  156. fail(err) {
  157. console.log(err, '------------------------ choose image');
  158. },
  159. });
  160. },
  161. // 取消上传
  162. oncancle() {
  163. this.url = '';
  164. },
  165. axiosData(ev) {
  166. console.log(ev);
  167. this.urlData = ev;
  168. this.urlFile = ev.path;
  169. setTimeout(() => {
  170. uni.showLoading({
  171. title: '识别中。。。',
  172. });
  173. });
  174. let that = this;
  175. if (that.serialNum == '' && that.insectNum !== '') {
  176. // 老接口
  177. var url = 'other_discern';
  178. var num = that.insectNum;
  179. } else if (that.serialNum !== '' && that.insectNum == '') {
  180. //新接口
  181. var url = 'discern';
  182. var num = that.serialNum;
  183. }
  184. const session_key = uni.getStorageSync('session_key');
  185. uni.uploadFile({
  186. // url: 'https://wx.hnyfwlw.com/bigservers/' + url + '?type=' + num,
  187. url: `http://192.168.2.157:8003/api/api_gateway?method=wheat.discreen.plan`,
  188. fileType: 'image',
  189. // file: this.urlData,
  190. filePath: ev.path,
  191. formData: {
  192. type: num,
  193. token: session_key
  194. },
  195. name: 'img_addr',
  196. success(res) {
  197. console.log(res);
  198. uni.hideLoading();
  199. that.url = '';
  200. // 判断是否识别成功 -新接口
  201. // if (data.code == 200) {
  202. if (res.statusCode !== 500) {
  203. var data = JSON.parse(res.data).data;
  204. if (data.returnResult.returnStatus == 1) {
  205. // 成功
  206. var img = [];
  207. img.push(that.urlFile);
  208. if (that.urlName == '其他') {
  209. var f = res.data.data;
  210. if (
  211. f.data == null ||
  212. f.data[0].prevention == '[防治方法] null'
  213. ) {
  214. console.log('失败');
  215. uni.navigateTo({
  216. url:
  217. '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  218. img +
  219. '&name=' +
  220. that.urlName,
  221. });
  222. } else {
  223. uni.navigateTo({
  224. url:
  225. '/pages/identifyPest/recognizeSucceedWorn/recognizeSucceedWorn?data=' +
  226. JSON.stringify(data) +
  227. '&name=' +
  228. that.urlName +
  229. '&img=' +
  230. img,
  231. });
  232. console.log('成功');
  233. }
  234. console.log('老接口');
  235. } else {
  236. uni.navigateTo({
  237. url:
  238. '/pages/identifyPest/recognizeSucceed/recognizeSucceed?data=' +
  239. JSON.stringify(data.returnResult),
  240. });
  241. console.log('新接口');
  242. }
  243. } else if (data.returnResult.returnStatus == 0) {
  244. //失败
  245. var img = [];
  246. img.push(that.urlFile);
  247. uni.navigateTo({
  248. url:
  249. '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  250. img +
  251. '&name=' +
  252. that.urlName,
  253. });
  254. }
  255. } else {
  256. //失败
  257. var img = [];
  258. img.push(that.urlFile);
  259. uni.navigateTo({
  260. url:
  261. '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  262. img +
  263. '&name=' +
  264. that.urlName,
  265. });
  266. }
  267. },
  268. fail(err) {
  269. var img = [];
  270. img.push(that.urlFile);
  271. uni.navigateTo({
  272. url:
  273. '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  274. img +
  275. '&name=' +
  276. that.urlName,
  277. });
  278. },
  279. complete(com) {
  280. that.loadingShow = false;
  281. uni.hideLoading()
  282. },
  283. });
  284. },
  285. // 其他--老识别接口
  286. restsData() {
  287. this.show = true;
  288. },
  289. // 确定
  290. insectData(num) {
  291. this.urlName = '其他';
  292. this.serialNum = '';
  293. this.insectNum = num;
  294. uni.chooseImage({
  295. count: 1,
  296. success: (res) => {
  297. // 设置url的值,显示控件
  298. this.urlData = res.tempFiles[0];
  299. this.url = res.tempFilePaths[0];
  300. this.urlFile = res.tempFilePaths[0]; //失败跳转显示的图片
  301. },
  302. });
  303. },
  304. },
  305. components: {
  306. kpsImageCutter,
  307. },
  308. onShow() {
  309. var that = this;
  310. uni.getStorage({
  311. key: 'lastTime',
  312. success: function (res) {
  313. that.lastTimeShow = true;
  314. console.log(res.data);
  315. that.lastTimeIndex = res.data;
  316. },
  317. fail: function (err) {
  318. that.lastTimeShow = false;
  319. console.log(err);
  320. },
  321. });
  322. },
  323. };
  324. </script>
  325. <style lang="scss">
  326. // 搜索
  327. uni-view,
  328. uni-text {
  329. // width: 740rpx;
  330. // margin: 0 auto;
  331. }
  332. // 作物选择
  333. .plantList_ul {
  334. .plantList_li {
  335. margin: 55rpx 0 55rpx 0;
  336. .plantList_tlt {
  337. font-weight: 550;
  338. font-size: 16px;
  339. width: 700rpx;
  340. margin: 0 auto;
  341. text {
  342. color: #7e7e7e;
  343. font-size: 12px;
  344. }
  345. }
  346. .plantList_li_ul {
  347. display: flex;
  348. flex-wrap: wrap;
  349. margin-top: 10rpx;
  350. .plantList_li_List {
  351. margin: 10rpx 0 0 18rpx;
  352. width: 150rpx;
  353. image {
  354. width: 130rpx;
  355. height: 130rpx;
  356. border-radius: 55px;
  357. margin: 0 auto;
  358. display: block;
  359. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  360. }
  361. view {
  362. width: 150rpx;
  363. color: #646464;
  364. text-align: center;
  365. margin: 10rpx 0 0 0;
  366. font-size: 13px;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. </style>