executionList.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <s-layout
  3. title="执行对象"
  4. navbar="inner"
  5. showBackButton
  6. showImportButton
  7. :bgStyle="{ color: '#FAFAFA' }"
  8. @import="state.showImport = true;state.importVal=''"
  9. >
  10. <view v-if="reason!==3" class="form_label">请添加执行对象</view>
  11. <uni-forms ref="formRef" v-model="formData" :rules="rules">
  12. <view class="form_item" v-for="(item, index) in formData.phoneList" :key="index">
  13. <view class="close_icon" @tap="removeItem(index)"></view>
  14. <view class="label">对象{{index+1}}:</view>
  15. <uni-forms-item
  16. :name="`phoneList.${index}.phone`"
  17. :rules="rules['phoneList.*.phone'].rules"
  18. >
  19. <uni-easyinput
  20. v-model="item.phone"
  21. placeholder="手机号"
  22. :clearable="false"
  23. :inputBorder="false"
  24. :maxlength="11"
  25. />
  26. </uni-forms-item>
  27. <uni-forms-item
  28. :name="`phoneList.${index}.name`"
  29. >
  30. <uni-easyinput
  31. v-model="item.name"
  32. placeholder="姓名"
  33. :clearable="false"
  34. :inputBorder="false"
  35. />
  36. </uni-forms-item>
  37. <uni-forms-item
  38. :name="`phoneList.${index}.gender`"
  39. >
  40. <uni-data-select
  41. v-model="item.gender"
  42. placeholder="性别"
  43. :clear="false"
  44. :localdata="genderOptions"
  45. />
  46. </uni-forms-item>
  47. </view>
  48. </uni-forms>
  49. <view class="add_btn_box">
  50. <view class="add_btn" @tap="addItem"></view>
  51. </view>
  52. <view class="submit_btn" @click="submitForm">{{reason===3?'开始执行任务':'下一步'}}</view>
  53. <su-popup :show="state.showImport" round="20" type="center" :isMaskClick="false" showClose @close="state.showImport=false">
  54. <view class="import_wrap">
  55. <view class="import_cont">
  56. <view class="title">
  57. <view class="label">批量导入</view>
  58. <view class="span">(单次仅支持识别1000个)</view>
  59. </view>
  60. <view class="cont">
  61. <uni-easyinput
  62. :inputBorder="false"
  63. type="textarea"
  64. v-model="state.importVal"
  65. placeholderStyle="color:#999999;font-size:24rpx;font-weight:400;line-height:34rpx;"
  66. placeholder="请按照以下格式粘贴,用逗号隔开电话号码如:13800138000,13812341234,18912341234"
  67. :clearable="false"
  68. :maxlength="-1"
  69. />
  70. </view>
  71. </view>
  72. <view class="group_btn">
  73. <view class="item_btn confirm_btn" @tap="onImport">导入</view>
  74. </view>
  75. </view>
  76. </su-popup>
  77. </s-layout>
  78. </template>
  79. <script setup>
  80. import { ref, reactive, unref, computed } from 'vue'
  81. import sheep from '@/common'
  82. import { onLoad } from '@dcloudio/uni-app'
  83. import taskApi from '@/common/api/member/task'
  84. const formRef = ref(null)
  85. const formData = reactive({
  86. phoneList: [{ phone: null, name: null, gender: null }]
  87. })
  88. const state = reactive({
  89. showImport: false,
  90. importVal: ''
  91. })
  92. const reason = ref(null)
  93. const genderOptions = [
  94. { value: 1, text: '男' },
  95. { value: 2, text: '女' },
  96. { value: 0, text: '未知' }
  97. ]
  98. const rules = reactive({
  99. 'phoneList.*.phone': {
  100. rules: [
  101. { required: true, errorMessage: '请输入手机号' },
  102. { pattern: /^1[3-9]\d{9}$/, errorMessage: '请输入正确的手机号' },
  103. ]
  104. },
  105. 'phoneList.*.name': {
  106. rules: [
  107. { required: true, errorMessage: '请输入姓名' },
  108. { minLength: 2, maxLength: 10, errorMessage: '姓名长度2-10个字符' }
  109. ]
  110. },
  111. 'phoneList.*.gender': {
  112. rules: [
  113. { required: true, errorMessage: '请选择性别' }
  114. ]
  115. }
  116. })
  117. const taskFormInfo = computed(() => sheep.$store('task').taskFormInfo)
  118. onLoad(async (options) => {
  119. reason.value = Number(options.reason||null)
  120. formData.phoneList = taskFormInfo.value.phoneList
  121. })
  122. const addItem = () => {
  123. formData.phoneList.push({ phone: null, name: null, gender: null })
  124. }
  125. const removeItem = (index) => {
  126. if (formData.phoneList.length > 1) {
  127. formData.phoneList.splice(index, 1)
  128. } else {
  129. uni.showToast({
  130. title: '至少保留一项',
  131. icon: 'none'
  132. })
  133. }
  134. }
  135. const submitForm = async () => {
  136. const validate = await unref(formRef).validate().catch((error) => {
  137. console.log('error: ', error)
  138. })
  139. if (!validate) return
  140. sheep.$store('task').updateTaskFormInfo(formData)
  141. if(reason.value===3){
  142. const { code, data } = await taskApi.addTask({
  143. ...taskFormInfo.value,
  144. planTime: taskFormInfo.value.planTime+':00'
  145. })
  146. if (code === 1) {
  147. sheep.$store('task').resetTaskData()
  148. sheep.$router.go('/pages/index/index')
  149. }
  150. }else{
  151. sheep.$router.go('/pages/task/speechTest')
  152. }
  153. }
  154. function convertPhoneNumbers(input,maxlength=50) {
  155. // 使用正则表达式分割字符串(支持逗号、中文逗号、空格等分隔符)
  156. const phoneRegex = /1[3-9]\d{9}/g;
  157. let phones = input.match(phoneRegex)
  158. // const phones = input.split(/[,,\s]+/)
  159. // .filter(phone => {
  160. // // 验证是否为有效的手机号(11位且以1开头)
  161. // return /^1[3-9]\d{9}$/.test(phone);
  162. // })
  163. if(!phones){
  164. phones=[]
  165. }
  166. return phones.slice(0,maxlength).map(phone => ({
  167. phone: phone,
  168. name: null,
  169. gender: null
  170. }))
  171. }
  172. function onImport(){
  173. uni.showLoading({
  174. title: '识别中',
  175. })
  176. const phones = convertPhoneNumbers(state.importVal,1000)
  177. if(!phones||!phones.length){
  178. uni.hideLoading()
  179. uni.showToast({
  180. title: '识别失败',
  181. icon: 'none'
  182. })
  183. return
  184. }
  185. if(formData.phoneList.length===1&&!formData.phoneList[0].phone&&!formData.phoneList[0].name&&!formData.phoneList[0].gender){
  186. formData.phoneList = phones
  187. }else{
  188. phones.forEach((item) => {
  189. formData.phoneList.push(item);
  190. })
  191. }
  192. uni.hideLoading()
  193. state.showImport = false
  194. }
  195. </script>
  196. <style lang="scss" scoped>
  197. .form_label{
  198. font-weight: bold;
  199. font-size: 40rpx;
  200. color: #222222;
  201. line-height: 58rpx;
  202. padding: 40rpx 30rpx 10rpx;
  203. }
  204. .form_item {
  205. margin: 30rpx;
  206. padding: 20rpx 20rpx 10rpx;
  207. width: 690rpx;
  208. min-height: 172rpx;
  209. background: #FFFFFF;
  210. border-radius: 20rpx;
  211. display: flex;
  212. align-items: center;
  213. box-sizing: border-box;
  214. flex-wrap: wrap;
  215. position: relative;
  216. .close_icon{
  217. width: 48rpx;
  218. height: 48rpx;
  219. position: absolute;
  220. top: 20rpx;
  221. right: 20rpx;
  222. background: url('/static/close-icon.png') no-repeat center/48rpx 48rpx;
  223. }
  224. .label{
  225. width: 100%;
  226. font-weight: bold;
  227. font-size: 28rpx;
  228. color: #222222;
  229. line-height: 40rpx;
  230. margin-bottom: 20rpx;
  231. }
  232. :deep(){
  233. .uni-forms-item__inner{
  234. padding-bottom: 40rpx;
  235. }
  236. .uni-easyinput__placeholder-class{
  237. font-weight: 400;
  238. font-size: 28rpx;
  239. color: #CCCCCC;
  240. }
  241. .uni-easyinput{
  242. background: #FAFAFA;
  243. border-radius: 20rpx;
  244. width: 236rpx;
  245. margin-right: 20rpx;
  246. }
  247. .uni-easyinput__content-input{
  248. height: 72rpx;
  249. line-height: 72rpx;
  250. padding: 0 20rpx !important;
  251. box-sizing: border-box;
  252. font-weight: 500;
  253. font-size: 28rpx;
  254. color: #222222;
  255. }
  256. .uni-stat__select{
  257. .uni-stat-box{
  258. border-radius: 20rpx;
  259. }
  260. }
  261. .uni-select{
  262. height: 72rpx;
  263. width: 136rpx;
  264. border: none;
  265. padding: 0 20rpx !important;
  266. background: #FAFAFA;
  267. box-sizing: border-box;
  268. .uni-select__input-box{
  269. height: 72rpx;
  270. .uni-select__input-placeholder{
  271. font-weight: 400;
  272. font-size: 28rpx;
  273. color: #999999;
  274. }
  275. }
  276. }
  277. }
  278. }
  279. .add_btn_box{
  280. padding: 80rpx 0 534rpx;
  281. .add_btn{
  282. margin: 0 auto;
  283. width: 216rpx;
  284. height: 82rpx;
  285. min-height: 82rpx;
  286. background: url('/static/add_btn.png') no-repeat center/216rpx 82rpx;
  287. }
  288. }
  289. .submit_btn{
  290. width: 630rpx;
  291. height: 104rpx;
  292. line-height: 104rpx;
  293. background: #35E89A;
  294. border-radius: 40rpx;
  295. font-weight: bold;
  296. font-size: 32rpx;
  297. color: #222222;
  298. text-align: center;
  299. position: fixed;
  300. left: calc(50%);
  301. transform: translateX(-50%);
  302. bottom: 40rpx;
  303. }
  304. .import_wrap{
  305. width: 610rpx;
  306. min-height: 450rpx;
  307. padding: 34rpx 30rpx 30rpx;
  308. background: #FFFFFF;
  309. box-sizing: border-box;
  310. display: flex;
  311. flex-direction: column;
  312. justify-content: space-between;
  313. .import_cont{
  314. .title{
  315. font-size: 28rpx;
  316. line-height: 40rpx;
  317. display: flex;
  318. align-items: center;
  319. .label{
  320. font-weight: bold;
  321. color: #222222;
  322. }
  323. .span{
  324. font-weight: 400;
  325. color: #999999;
  326. }
  327. }
  328. .cont{
  329. margin: 30rpx 0;
  330. background: #FAFAFA;
  331. border-radius: 20rpx;
  332. padding: 30rpx;
  333. height: 480rpx;
  334. box-sizing: border-box;
  335. :deep(.uni-easyinput){
  336. .uni-easyinput__content{
  337. .uni-easyinput__content-textarea{
  338. height: 420rpx;
  339. overflow-y: auto;
  340. padding: 0;
  341. }
  342. }
  343. }
  344. }
  345. }
  346. .group_btn{
  347. display: flex;
  348. align-items: center;
  349. .item_btn{
  350. flex: 1;
  351. height: 104rpx;
  352. line-height: 104rpx;
  353. border-radius: 40rpx;
  354. text-align: center;
  355. font-weight: bold;
  356. font-size: 32rpx;
  357. color: #FFFFFF;
  358. margin-left: 18rpx;
  359. }
  360. .item_btn:first-child{
  361. margin-left: 0;
  362. }
  363. .cancel_btn{
  364. background: #CCCCCC;
  365. }
  366. .confirm_btn{
  367. background: #222222;
  368. }
  369. .logout-btn{
  370. background: #FF4E4E;
  371. }
  372. }
  373. }
  374. </style>