economicsPlant.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. 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.tempFiles);
  151. this.urlData = res;
  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. // 确定上传
  165. axiosData(ev) {
  166. setTimeout(() => {
  167. uni.showLoading({
  168. title: '识别中。。。',
  169. });
  170. });
  171. let that = this;
  172. if (that.serialNum == '' && that.insectNum !== '') {
  173. // 老接口
  174. var url = 'other_discern';
  175. var num = that.insectNum;
  176. } else if (that.serialNum !== '' && that.insectNum == '') {
  177. //新接口
  178. var url = 'discern';
  179. var num = that.serialNum;
  180. }
  181. uni.uploadFile({
  182. url: 'https://wx.hnyfwlw.com/bigservers/' + url + '?type=' + num,
  183. fileType: 'image',
  184. file: this.urlData.tempFiles[0],
  185. filePath: this.urlData.tempFiles[0].path,
  186. name: 'img_addr',
  187. success(res) {
  188. uni.hideLoading();
  189. that.url = '';
  190. // 判断是否识别成功 -新接口
  191. // if (data.code == 200) {
  192. if (res.statusCode !== 500) {
  193. var data = JSON.parse(res.data);
  194. if (data.returnResult.returnStatus == 1) {
  195. // 成功
  196. var img = [];
  197. img.push(that.urlFile);
  198. if (that.urlName == '其他') {
  199. var f = JSON.parse(res.data);
  200. if (
  201. f.data == null ||
  202. f.data[0].prevention == '[防治方法] null'
  203. ) {
  204. console.log('失败');
  205. uni.navigateTo({
  206. url:
  207. '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  208. img +
  209. '&name=' +
  210. that.urlName,
  211. });
  212. } else {
  213. uni.navigateTo({
  214. url:
  215. '/pages/identifyPest/recognizeSucceedWorn/recognizeSucceedWorn?data=' +
  216. JSON.stringify(data.data) +
  217. '&name=' +
  218. that.urlName +
  219. '&img=' +
  220. img,
  221. });
  222. console.log('成功');
  223. }
  224. console.log('老接口');
  225. } else {
  226. uni.navigateTo({
  227. url:
  228. '/pages/identifyPest/recognizeSucceed/recognizeSucceed?data=' +
  229. JSON.stringify(data.returnResult),
  230. });
  231. console.log('新接口');
  232. }
  233. } else if (data.code !== 200) {
  234. //失败
  235. var img = [];
  236. img.push(that.urlFile);
  237. uni.navigateTo({
  238. url:
  239. '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  240. img +
  241. '&name=' +
  242. that.urlName,
  243. });
  244. }
  245. } else {
  246. //失败
  247. var img = [];
  248. img.push(that.urlFile);
  249. uni.navigateTo({
  250. url:
  251. '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  252. img +
  253. '&name=' +
  254. that.urlName,
  255. });
  256. }
  257. },
  258. fail(err) {
  259. var img = [];
  260. img.push(that.urlFile);
  261. uni.navigateTo({
  262. url:
  263. '/pages/identifyPest/recognizeFail/recognizeFail?data=' +
  264. img +
  265. '&name=' +
  266. that.urlName,
  267. });
  268. },
  269. complete(com) {
  270. that.loadingShow = false;
  271. uni.hideLoading()
  272. },
  273. });
  274. },
  275. // 其他--老识别接口
  276. restsData() {
  277. this.show = true;
  278. },
  279. // 确定
  280. insectData(num) {
  281. this.urlName = '其他';
  282. this.serialNum = '';
  283. this.insectNum = num;
  284. uni.chooseImage({
  285. count: 1,
  286. success: (res) => {
  287. // 设置url的值,显示控件
  288. this.urlData = res;
  289. this.url = res.tempFilePaths[0];
  290. this.urlFile = res.tempFilePaths[0]; //失败跳转显示的图片
  291. },
  292. });
  293. },
  294. },
  295. components: {
  296. kpsImageCutter,
  297. },
  298. onShow() {
  299. var that = this;
  300. uni.getStorage({
  301. key: 'lastTime',
  302. success: function (res) {
  303. that.lastTimeShow = true;
  304. console.log(res.data);
  305. that.lastTimeIndex = res.data;
  306. },
  307. fail: function (err) {
  308. that.lastTimeShow = false;
  309. console.log(err);
  310. },
  311. });
  312. },
  313. };
  314. </script>
  315. <style lang="scss">
  316. // 搜索
  317. uni-view,
  318. uni-text {
  319. // width: 740rpx;
  320. // margin: 0 auto;
  321. }
  322. // 作物选择
  323. .plantList_ul {
  324. .plantList_li {
  325. margin: 55rpx 0 55rpx 0;
  326. .plantList_tlt {
  327. font-weight: 550;
  328. font-size: 16px;
  329. width: 700rpx;
  330. margin: 0 auto;
  331. text {
  332. color: #7e7e7e;
  333. font-size: 12px;
  334. }
  335. }
  336. .plantList_li_ul {
  337. display: flex;
  338. flex-wrap: wrap;
  339. margin-top: 10rpx;
  340. .plantList_li_List {
  341. margin: 10rpx 0 0 18rpx;
  342. width: 150rpx;
  343. image {
  344. width: 130rpx;
  345. height: 130rpx;
  346. border-radius: 55px;
  347. margin: 0 auto;
  348. display: block;
  349. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  350. }
  351. view {
  352. width: 150rpx;
  353. color: #646464;
  354. text-align: center;
  355. margin: 10rpx 0 0 0;
  356. font-size: 13px;
  357. }
  358. }
  359. }
  360. }
  361. }
  362. </style>