economicsPlant.vue 10 KB

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