index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <z-paging class="" ref="paging" bgColor="#fff" paging-class="paging-btm-shadow" safe-area-inset-bottom
  3. scroll-with-animation>
  4. <template #top>
  5. <ut-navbar :title="did ? '编辑GAP基地信息' : '添加GAP基地信息'" :fixed="false" border></ut-navbar>
  6. </template>
  7. <view class="pd-24">
  8. <up-form class="p-rtv" labelPosition="top" :model="form" :rules="rules" labelWidth="auto" ref="upFormRef">
  9. <!-- 校验定位:基地类型 -->
  10. <!-- 基地信息部分 -->
  11. <view>
  12. <view class="h-1" id="gapBaseTypepppp"></view>
  13. <ut-action-sheet v-model="form.gapBaseType" :tabs="pt_base_type" title="选择基地类型">
  14. <up-form-item borderBottom label="基地类型" required prop="baseType">
  15. <view v-if="form.gapBaseType" class="f-s-30 c-333 f-w-5 flex1">{{
  16. selectDictLabel(pt_base_type,
  17. form.gapBaseType) }}</view>
  18. <view v-else class="f-s-30 c-ccc f-w-4 flex1">请选择基地类型</view>
  19. <template #right>
  20. <up-icon size="22rpx" color="#2A6D52" name="arrow-down-fill"></up-icon>
  21. </template>
  22. </up-form-item>
  23. </ut-action-sheet>
  24. <!-- 基地名称 -->
  25. <view class="h-1" id="gapBaseNamepppp"></view>
  26. <up-form-item borderBottom label="基地名称" required prop="gapBaseName">
  27. <up-input v-model="form.gapBaseName" placeholder="请输入基地名称" border="none" clearable></up-input>
  28. </up-form-item>
  29. <!-- 选择获评品种 -->
  30. <view class="h-1" id="medicineCodepppp"></view>
  31. <up-form-item @click="selectMedicine" borderBottom label="获评品种" required prop="medicineCode">
  32. <view v-if="form.medicineCode" class="f-s-30 c-333 f-w-5 flex1">{{ form.medicineName }}</view>
  33. <view v-else class="f-s-30 c-ccc f-w-4 flex1">请选择获评品种</view>
  34. <template #right>
  35. <up-icon size="22rpx" color="#2A6D52" name="arrow-down-fill"></up-icon>
  36. </template>
  37. </up-form-item>
  38. <up-form-item borderBottom prop="basePic" required>
  39. <view class="flex1 ov-hd">
  40. <view class="d-flex a-c mb-10" style="margin-bottom: 5px">
  41. <view class="f-s-30 c-#666">基地范围</view>
  42. </view>
  43. <view class="bg-#ccc d-flex ov-hd p-rtv" @click="mapDrawArea">
  44. <image class="w-full h-380" v-if="form?.basePic" :src="form?.basePic" mode="widthFix" />
  45. <image class="w-full h-380" v-else src="https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/base/select_base_gap.png"
  46. mode="widthFix" />
  47. <view v-if="!form?.basePic" class="btn-aree-center d-flex flex-cln a-c j-c">
  48. <image class="w-52 h-52 mb-10" src="https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/base/draw_area_icon.png"
  49. mode="widthFix" />
  50. <view class="c-primary f-s-28 f-w-400">点击绘制基地范围</view>
  51. </view>
  52. </view>
  53. </view>
  54. </up-form-item>
  55. <view class="h-1" id="adcodepppp"></view>
  56. <up-form-item @click="showArea = true" borderBottom label="基地具体地址" required prop="adcode">
  57. <!-- <up-input v-model="form.address" placeholder="请选择基地所在省/市/县/镇(乡)" border="none" clearable></up-input> -->
  58. <view v-if="form?.adcode" class="f-s-30 c-333 f-w-5 flex1">{{ form?.adcodeName }}</view>
  59. <view v-else class="f-s-30 c-ccc f-w-4 flex1">请选择基地所在省/市/县/镇(乡)</view>
  60. <template #right>
  61. <up-icon size="22rpx" color="#2A6D52" name="arrow-down-fill"></up-icon>
  62. </template>
  63. </up-form-item>
  64. <up-form-item borderBottom prop="address">
  65. <up-input v-model="form.address" placeholder="请填写村级以下的具体地址信息" border="none"
  66. clearable></up-input>
  67. </up-form-item>
  68. <view class="h-1" id="areaPppp"></view>
  69. <up-form-item required borderBottom label="基地面积" prop="area">
  70. <up-input v-model="form.area" placeholder="地块绘制后自动带出可修改" border="none" clearable></up-input>
  71. <template #right>
  72. <span>{{ form.areaUnit }}</span>
  73. </template>
  74. </up-form-item>
  75. <!-- 基地经纬度 -->
  76. <view class="h-1" id="lngpppp"></view>
  77. <view class="h-1" id="latpppp"></view>
  78. <up-form-item required label="基地经纬度" class="form-item-wrap-column">
  79. <view class="d-flex" style="margin-top: -10px">
  80. <up-form-item prop="gapInfo.lng">
  81. <up-input v-model="form.lng" border="bottom" placeholder="70-150内的经度数值" clearable></up-input>
  82. </up-form-item>
  83. <view class="pd-5"></view>
  84. <up-form-item prop="gapInfo.lat">
  85. <up-input v-model="form.lat" placeholder="4-53内的纬度数值" border="bottom" clearable></up-input>
  86. </up-form-item>
  87. </view>
  88. </up-form-item>
  89. <!-- 校验定位:建设时间 -->
  90. <view class="h-1" id="ratedDatepppp"></view>
  91. <ut-datetime-picker v-model="form.ratedDate" mode="date" :minDate="new Date(1990, 0, 1)" dateFields="day">
  92. <up-form-item borderBottom label="获评GAP基地时间" required prop="ratedDate">
  93. <up-input v-model="form.ratedDate" placeholder="请选择获评GAP基地时间" border="none"
  94. clearable></up-input>
  95. <template #right>
  96. <up-icon size="22rpx" color="#2A6D52" name="arrow-down-fill"></up-icon>
  97. </template>
  98. </up-form-item>
  99. </ut-datetime-picker>
  100. <!-- 官方公示证明材料 -->
  101. <view class="h-1" id="certFilepppp"></view>
  102. <up-form-item borderBottom required prop="certFile">
  103. <view class="flex1">
  104. <view style="margin-bottom: 10rpx">
  105. <span class="c-666 f-s-30">官方公示证明材料</span>
  106. <span class="f-s-26 c-999">(可上传9张)</span>
  107. </view>
  108. <ut-upload v-model="form.certFile" :max-count="9"></ut-upload>
  109. </view>
  110. </up-form-item>
  111. <!-- 官方公示网址 -->
  112. <view class="h-1" id="urlpppp"></view>
  113. <up-form-item borderBottom label="官方公示网址" prop="url" required>
  114. <up-input v-model="form.url" placeholder="请输入官方公示网址" border="none" clearable></up-input>
  115. </up-form-item>
  116. </view>
  117. </up-form>
  118. </view>
  119. <template #bottom>
  120. <view class="pd-20 d-flex">
  121. <up-button @click="submitForm" type="primary">提交</up-button>
  122. </view>
  123. </template>
  124. </z-paging>
  125. <ut-picker-area v-model:show="showArea" v-model="form.adcode" @confirm="confirmArea"></ut-picker-area>
  126. </template>
  127. <script setup lang="ts">
  128. import { useUserStore } from '@/store';
  129. import { useClientRequest } from '@/utils/request';
  130. import { isOpenSetting } from '@/utils/common';
  131. import { generateUniqueId } from '@/utils/public';
  132. const tabs = reactive([
  133. { label: '基本信息', value: 'base' },
  134. { label: '地块信息', value: 'plot' },
  135. { label: '选址依据及环境信息', value: 'environment' },
  136. ]);
  137. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  138. const { yes_no, pt_org_type, pt_base_type } = toRefs<any>(proxy?.useDict('yes_no', 'pt_org_type', 'pt_base_type'));
  139. const paging = ref<any>(null);
  140. const upFormRef = ref<any>(null);
  141. const showArea = ref(false);
  142. const form = ref<any>({
  143. sourceType: '2', // 基地来源 1-GAP系统 2-手动录入
  144. gapBaseType: '',
  145. adcode: '',
  146. adcodeName: '',
  147. address: '',
  148. areaUnit: '亩',
  149. basePic: '',
  150. area: undefined,
  151. randomCode: generateUniqueId(),
  152. // 当前位置经纬度
  153. longitudeLatitude: {
  154. lng: '',
  155. lat: '',
  156. },
  157. coordinates: [],
  158. zoom: undefined,
  159. url: '',
  160. });
  161. const rules = reactive({
  162. gapBaseType: [{ required: true, message: '请选择基地类型' }],
  163. gapBaseName: [{ required: true, message: '请输入基地名称' }],
  164. medicineId: [{ required: true, message: '请选择获评品种' }],
  165. basePic: [{ required: true, message: '请绘制基地范围' }],
  166. adcode: [{ required: true, message: '请选择基地具体地址' }],
  167. area: [{ required: true, message: '请输入基地面积' }],
  168. ratedDate: [{ required: true, message: '请选择获评GAP基地时间' }],
  169. certFile: [{ required: true, message: '请上传官方公示证明材料' }],
  170. url: [{ required: true, message: '请输入官方公示网址' }],
  171. });
  172. const submitForm = async () => {
  173. uni.$u.debounce(
  174. async () => {
  175. try {
  176. await upFormRef.value?.validate();
  177. } catch (error: any) {
  178. // 滚动到第一个错误字段
  179. const firstErrorField = error && error[0].prop + 'pppp';
  180. paging.value?.scrollIntoViewById(firstErrorField, 30, true);
  181. return;
  182. }
  183. // 提交表单
  184. uni.showLoading({
  185. title: '提交中...',
  186. });
  187. try {
  188. const res = did.value ? await useClientRequest.post(`/plt-api/app/gapCertificationInfo/update`, form.value) : await useClientRequest.post('/plt-api/app/gapCertificationInfo/add', form.value);
  189. if (!res || res.code !== 200) return;
  190. uni.hideLoading();
  191. uni.showToast({
  192. title: '提交成功',
  193. icon: 'success',
  194. });
  195. uni.$emit('gapBaseInfoUpdated');
  196. // 返回上一页
  197. setTimeout(() => {
  198. uni.navigateBack({
  199. delta: 1,
  200. });
  201. }, 1500);
  202. } catch (error) {
  203. uni.hideLoading();
  204. }
  205. },
  206. 500,
  207. true
  208. );
  209. };
  210. const mapDrawArea = async () => {
  211. uni.$on('mapAreaData', (data: any) => {
  212. // 这里可以将 data 赋值给 form 中的相应字段
  213. form.value.basePic = data.gapInfo.basePic;
  214. form.value.area = String(data.gapInfo.area);
  215. form.value.areaUnit = data.gapInfo.areaUnit;
  216. form.value.coordinates = data.coordinates;
  217. form.value.lng = data.mapInfo.lng;
  218. form.value.lat = data.mapInfo.lat;
  219. form.value.lnglat = String(data.mapInfo.lng) + ',' + String(data.mapInfo.lat);
  220. form.value.zoom = data.mapInfo.zoom;
  221. uni.$off('mapAreaData');
  222. });
  223. if (form.value?.basePic) {
  224. // 暂存地图当前数据后跳转
  225. await useClientRequest.post('/plt-api/app/gapCertificationInfo/painting', {
  226. randomCode: form.value.id || form.value.randomCode,
  227. value: JSON.stringify({
  228. gapInfo: form.value,
  229. coordinates: form.value.coordinates,
  230. }),
  231. });
  232. }
  233. uni.$u.route({
  234. type: 'navigateTo',
  235. url: '/tools/map-draw-area/index',
  236. params: {
  237. drawId: form.value.id || form.value.randomCode,
  238. unit: form.value.areaUnit || '亩',
  239. lng: form.value.lng || form.value.longitudeLatitude.lng || '',
  240. lat: form.value.lat || form.value.longitudeLatitude.lat || '',
  241. zoom: form.value.zoom,
  242. },
  243. });
  244. };
  245. // 改成去选择获评品种页面
  246. const selectMedicine = () => {
  247. uni.$on('medicineSelected', (medicine: any) => {
  248. form.value.medicineCode = medicine.medicineCode;
  249. form.value.medicineName = medicine.medicineName;
  250. uni.$off('medicineSelected');
  251. });
  252. uni.$u.route({
  253. type: 'navigateTo',
  254. url: '/tools/select-medicine/index',
  255. params: {
  256. singleSelect: true,
  257. },
  258. });
  259. };
  260. const confirmArea = (area: any) => {
  261. form.value.adcodeName = area.fullName;
  262. };
  263. const getDetailById = async (id: string) => {
  264. if (!id) return;
  265. const res = await useClientRequest.get(`/plt-api/app/gapCertificationInfo/getInfoById/${id}`);
  266. if (res && res.code === 200) {
  267. form.value = {
  268. ...res.data,
  269. lnglat: res.data.lng + ',' + res.data.lat,
  270. };
  271. }
  272. };
  273. const did = ref('');
  274. onLoad((optins: any) => {
  275. if (optins.id) {
  276. // 编辑加载详
  277. did.value = optins.id;
  278. getDetailById(optins.id);
  279. } else {
  280. getLocationByAddress();
  281. }
  282. });
  283. // 获取当前经纬度返回地址
  284. const getLocationByAddress = async () => {
  285. const info = await uni.getSystemInfo();
  286. let locationEnabled = info.locationEnabled; //判断手机定位服务是否开启
  287. let locationAuthorized = info.locationAuthorized; //判断定位服务是否允许微信授权
  288. if (locationEnabled == false || locationAuthorized == false) {
  289. //手机定位服务(GPS)未授权
  290. uni.showModal({
  291. title: '提示',
  292. content: '请打开定位服务功能',
  293. showCancel: false, // 不显示取消按钮
  294. });
  295. return;
  296. }
  297. const scope = await isOpenSetting('scope.userLocation');
  298. if (!scope) return;
  299. const location = await uni.getLocation({ type: 'gcj02', isHighAccuracy: true });
  300. form.value.longitudeLatitude = {
  301. lng: location.longitude,
  302. lat: location.latitude,
  303. };
  304. };
  305. </script>
  306. <style lang="scss" scoped></style>