cerealPlant.vue 8.6 KB

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