index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div class="service-manage">
  3. <custom-header name="服务维护"></custom-header>
  4. <div class="main-content">
  5. <div class="service-title">
  6. <img class="label-icon" src="@/assets/img/home/label-icon.png" alt="">
  7. 服务信息
  8. </div>
  9. <div class="service-content">
  10. <div class="service-item">
  11. <div class="sub-title">服务作物</div>
  12. <div class="tag-group" v-if="!isEdit">
  13. <div class="tag-item" v-for="(item, idx) in crops" :key="'c-'+idx">{{ item.name }}</div>
  14. </div>
  15. <div class="tag-group add-tag-group" v-else>
  16. <div class="tag-item" :class="{ self: item.isSelf === 1 }" v-for="(item, idx) in crops" :key="'ce-'+idx">
  17. <span class="text">{{ item.name }}<el-icon @click.stop="handleEdit(item.name)" v-if="item.isSelf===1" class="edit-icon"><Edit /></el-icon></span>
  18. <el-icon v-if="item.isSelf===1" class="del-icon" @click.stop="handleDelete('crops', idx)"><Close /></el-icon>
  19. </div>
  20. <div class="tag-item last-add" @click="handleAdd('作物')"><el-icon class="add-icon"><Plus /></el-icon>作物</div>
  21. </div>
  22. </div>
  23. <div class="service-item">
  24. <div class="sub-title">服务类型</div>
  25. <div class="tag-group" v-if="!isEdit">
  26. <div class="tag-item" v-for="(item, idx) in serviceTypes" :key="'t-'+idx">{{ item.name }}</div>
  27. </div>
  28. <div class="tag-group add-tag-group" v-else>
  29. <div class="tag-item" :class="{ self: item.isSelf === 1 }" v-for="(item, idx) in serviceTypes" :key="'te-'+idx">
  30. <span class="text">{{ item.name }}<el-icon @click.stop="handleEdit(item.name)" v-if="item.isSelf===1" class="edit-icon"><Edit /></el-icon></span>
  31. <el-icon v-if="item.isSelf===1" class="del-icon" @click.stop="handleDelete('serviceTypes', idx)"><Close /></el-icon>
  32. </div>
  33. <div class="tag-item last-add" @click="handleAdd('类型')"><el-icon class="add-icon"><Plus /></el-icon>类型</div>
  34. </div>
  35. </div>
  36. <div class="service-item">
  37. <div class="sub-title">农机设备</div>
  38. <div class="tag-group" v-if="!isEdit">
  39. <div class="tag-item" v-for="(item, idx) in machines" :key="'m-'+idx">{{ item.name }}</div>
  40. </div>
  41. <div class="tag-group add-tag-group" v-else>
  42. <div class="tag-item" :class="{ self: item.isSelf === 1 }" v-for="(item, idx) in machines" :key="'me-'+idx">
  43. <span class="text">{{ item.name }}<el-icon @click.stop="handleEdit(item.name)" v-if="item.isSelf===1" class="edit-icon"><Edit /></el-icon></span>
  44. <el-icon v-if="item.isSelf===1" class="del-icon" @click.stop="handleDelete('machines', idx)"><Close /></el-icon>
  45. </div>
  46. <div class="tag-item last-add" @click="handleAdd('设备')"><el-icon class="add-icon"><Plus /></el-icon>设备</div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="page-action" v-if="isEdit">
  52. <div class="btn-item cancel" @click="isEdit = false">取消</div>
  53. <div class="btn-right">
  54. <div class="btn-item primary" @click="isEdit = false">保存服务类型</div>
  55. </div>
  56. </div>
  57. <div class="page-action" v-else>
  58. <div class="btn-item primary center-btn" @click="isEdit = true">编辑服务类型</div>
  59. </div>
  60. </div>
  61. <popup class="add-tag-popup" round v-model:show="showAddPopup">
  62. <div class="popup-title" v-if="isEditPopup">编辑标签</div>
  63. <div class="popup-title" v-else>添加{{addTypeName}}<span class="ml-2">标签</span></div>
  64. <el-input class="popup-input" v-model="input" placeholder="标签" size="large" />
  65. <div class="popup-button">
  66. <div class="cancel" @click="showAddPopup = false">取消</div>
  67. <div>{{isEditPopup ? '确定' : '添加'}}</div>
  68. </div>
  69. </popup>
  70. </template>
  71. <script setup>
  72. import { ref } from "vue";
  73. import customHeader from "@/components/customHeader.vue";
  74. import { Popup} from "vant";
  75. import { Edit, Close, Plus } from '@element-plus/icons-vue'
  76. const isEdit = ref(true);
  77. const showAddPopup = ref(false);
  78. const input = ref("");
  79. const addTypeName = ref("");
  80. function handleAdd(type) {
  81. isEditPopup.value = false
  82. addTypeName.value = type;
  83. input.value = "";
  84. showAddPopup.value = true;
  85. }
  86. // 三类数据:数组对象形式,随意赋值 isSelf=0/1
  87. const crops = ref([
  88. { name: "荔枝", isSelf: 1 },
  89. { name: "龙眼", isSelf: 1 },
  90. { name: "芒果", isSelf: 0 }
  91. ]);
  92. const serviceTypes = ref([
  93. { name: "飞防类", isSelf: 1 },
  94. { name: "技术类", isSelf: 1 },
  95. { name: "劳力类", isSelf: 0 },
  96. { name: "机械类", isSelf: 0 }
  97. ]);
  98. const machines = ref([
  99. { name: "收割机", isSelf: 1 },
  100. { name: "M3E", isSelf: 0 }
  101. ]);
  102. function handleDelete(category, index) {
  103. if (category === 'crops') crops.value.splice(index, 1);
  104. if (category === 'serviceTypes') serviceTypes.value.splice(index, 1);
  105. if (category === 'machines') machines.value.splice(index, 1);
  106. }
  107. const isEditPopup = ref(false);
  108. function handleEdit(val) {
  109. isEditPopup.value = true;
  110. input.value = val;
  111. showAddPopup.value = true;
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .service-manage {
  116. width: 100%;
  117. height: 100vh;
  118. background: #F5F7FB;
  119. .main-content {
  120. max-height: calc(100% - 40px);
  121. overflow: auto;
  122. padding: 15px 12px;
  123. margin: 14px 12px;
  124. border-radius: 12px;
  125. background: #fff;
  126. .service-title {
  127. font-size: 18px;
  128. color: #222222;
  129. font-weight: 500;
  130. margin-bottom: 10px;
  131. .label-icon {
  132. width: 14px;
  133. padding-right: 5px;
  134. }
  135. }
  136. .service-content {
  137. margin-top: 12px;
  138. padding-top: 12px;
  139. border-top: 1px solid #F5F5F5;
  140. .service-item {
  141. .sub-title {
  142. font-size: 16px;
  143. font-weight: 500;
  144. color: rgba(0, 0, 0, 0.9);
  145. }
  146. .tag-group {
  147. display: flex;
  148. align-items: center;
  149. flex-wrap: wrap;
  150. gap: 0 12px;
  151. font-size: 16px;
  152. .tag-item {
  153. margin-top: 10px;
  154. position: relative;
  155. background: #E8F5FF;
  156. border-radius: 8px;
  157. color: #2199f8;
  158. padding: 0 12px;
  159. box-sizing: border-box;
  160. min-width: 26vw;
  161. height: 48px;
  162. text-align: center;
  163. line-height: 48px;
  164. .text { display: inline-flex; align-items: center; }
  165. .edit-icon { margin-left: 8px; }
  166. .del-icon {
  167. position: absolute;
  168. right: -8px;
  169. top: -8px;
  170. background: #2199F8;
  171. border-radius: 50%;
  172. width: 16px; height: 16px;
  173. font-size: 10px;
  174. display: flex; align-items: center; justify-content: center;
  175. color: #fff;
  176. }
  177. }
  178. &.add-tag-group {
  179. .tag-item {
  180. color: #000000;
  181. background: none;
  182. border: 1px solid #999999;
  183. &.self {
  184. border: 1px solid #2199F8;
  185. background: #E8F5FF;
  186. color: #2199F8;
  187. }
  188. &.last-add {
  189. background: #F7F7F7;
  190. color: #343434;
  191. border: none;
  192. display: flex;
  193. align-items: center;
  194. justify-content: center;
  195. .add-icon {
  196. font-size: 14px;
  197. font-weight: bold;
  198. margin-right: 3px;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. .service-item + .service-item {
  206. margin-top: 20px;
  207. }
  208. }
  209. }
  210. .page-action {
  211. position: fixed;
  212. left: 0;
  213. right: 0;
  214. bottom: 0;
  215. padding: 12px 12px;
  216. background: #fff;
  217. box-shadow: 2px 2px 4.5px rgba(0, 0, 0, 0.4);
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. .btn-item {
  222. height: 40px;
  223. line-height: 41px;
  224. border-radius: 20px;
  225. width: fit-content;
  226. padding: 0 20px;
  227. color: #666666;
  228. font-size: 14px;
  229. &.del {
  230. color: #ff943d;
  231. background: rgba(255, 148, 61, 0.1);
  232. }
  233. &.cancel {
  234. border: 1px solid rgba(153, 153, 153, 0.5);
  235. }
  236. &.primary {
  237. color: #fff;
  238. background: linear-gradient(#76c3ff, #2199f8);
  239. }
  240. }
  241. .center-btn {
  242. margin: 0 auto;
  243. }
  244. .btn-right {
  245. display: flex;
  246. gap: 10px;
  247. }
  248. }
  249. }
  250. .add-tag-popup{
  251. width: 90%;
  252. padding: 20px 16px;
  253. .popup-title{
  254. font-size: 18px;
  255. font-weight: 500;
  256. text-align: center;
  257. margin-bottom: 12px;
  258. }
  259. .ml-2 {
  260. margin-left: 3px;
  261. }
  262. .popup-input{
  263. margin-bottom: 30px;
  264. }
  265. .popup-button{
  266. display: flex;
  267. padding-top: 20px;
  268. border-top: 1px solid rgba(0, 0, 0, 0.1);
  269. div{
  270. flex: 1;
  271. font-size: 16px;
  272. padding: 9px;
  273. border-radius: 20px;
  274. background: #2199F8;
  275. color: #fff;
  276. text-align: center;
  277. }
  278. .cancel{
  279. margin-right: 20px;
  280. color: #000;
  281. background: #fff;
  282. border: 1px solid #999999;
  283. }
  284. }
  285. }
  286. </style>