contactList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view class="after_sales">
  3. <view class="bth_oper" v-if="type != 'view'">
  4. <view class="btn add" @click="goContact('add')">添加</view>
  5. <view class="btn del" @click="batchDelete">删除</view>
  6. <text class="reserve">请至少保留一条联系人数据</text>
  7. </view>
  8. <u-list class="listContent">
  9. <checkbox-group v-for="(item, index) in contactList" :key="index" @change="e => selectVal(e, item, index)">
  10. <label>
  11. <view class="listBox">
  12. <view class="listBox-sel">
  13. <checkbox v-if="type != 'view'" :value="item.id" color="#fff" :disabled="item.disabled" :checked="item.checked" />
  14. </view>
  15. <view class="listBox-con">
  16. <view class="listBox-bottom">
  17. <view>姓名:{{ item.contactName }}</view>
  18. <view>手机:{{ item.contactPhone }}</view>
  19. <view>电话:{{ item.telephone }}</view>
  20. <view>微信号:{{ item.wechat }}</view>
  21. <view>邮箱:{{ item.email }}</view>
  22. <view>部门:{{ item.deptName }}</view>
  23. <view>职务:{{ item.post }}</view>
  24. <view>备注:{{ item.remark }}</view>
  25. <view class="action">
  26. <text class="text">
  27. 操作:
  28. </text>
  29. <u-button v-if="type != 'view'" @click="goContact('edit',index,item)" :plain="true" :hairline="true"
  30. size='mini' type="default" text="编辑"></u-button>
  31. <u-button v-if="type != 'view'" @click="del(index)" :plain="true" :hairline="true" size='mini' type="default"
  32. class="delete" text="删除"></u-button>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </label>
  38. </checkbox-group>
  39. <u-empty class="noDate" style="margin-top: 20vh" v-if="!contactList.length"></u-empty>
  40. </u-list>
  41. <u-toast ref="uToast"></u-toast>
  42. </view>
  43. </template>
  44. <script>
  45. // import myCard from '@/pages/saleManage/components/myCard.vue'
  46. export default {
  47. components: {
  48. // myCard
  49. },
  50. props: {
  51. itemList: {
  52. type: Array,
  53. default: () => []
  54. },
  55. type:{
  56. type:String,
  57. default:''
  58. }
  59. },
  60. watch: {
  61. itemList: {
  62. handler(newVal) {
  63. let list = JSON.parse(JSON.stringify(newVal));
  64. this.contactList = list
  65. },
  66. deep: true,
  67. immediate: true
  68. }
  69. },
  70. computed: {},
  71. data() {
  72. return {
  73. contactList: []
  74. }
  75. },
  76. onLoad({}) {},
  77. created() {
  78. uni.$off('updateContactList')
  79. uni.$on('updateContactList', ({
  80. type,
  81. data,
  82. index
  83. }) => {
  84. console.log(data, 'data');
  85. if (type == 'add') {
  86. this.contactList.push(data);
  87. } else {
  88. this.$set(this.contactList, index, data);
  89. }
  90. })
  91. },
  92. methods: {
  93. // 勾选数据
  94. selectVal(e, val, index) {
  95. this.$set(this.contactList[index], 'checked', !this.contactList[index].checked)
  96. },
  97. // 删除联系人
  98. del(index) {
  99. uni.showModal({
  100. title: '确认删除',
  101. content: '确定要删除这条联系人数据吗?',
  102. confirmText: '删除',
  103. confirmColor: '#FF4D4F',
  104. success: (res) => {
  105. if (res.confirm) {
  106. this.contactList.splice(index, 1);
  107. } else if (res.cancel) {
  108. // 用户点击了取消按钮
  109. console.log('用户取消删除');
  110. }
  111. }
  112. });
  113. },
  114. // 批量删除
  115. batchDelete() {
  116. let list = this.contactList.filter(item=> item.checked);
  117. console.log(list,'list')
  118. if (list.length == 0) {
  119. this.$refs.uToast.show({
  120. type: "warning",
  121. message: "至少选择一条数据进行删除",
  122. })
  123. return;
  124. }
  125. uni.showModal({
  126. title: '确认删除',
  127. content: '确定要删除所选联系人数据吗?',
  128. confirmText: '删除',
  129. confirmColor: '#FF4D4F',
  130. success: (res) => {
  131. if (res.confirm) {
  132. this.contactList = this.contactList.filter(item=> !item.checked);
  133. } else if (res.cancel) {
  134. // 用户点击了取消按钮
  135. console.log('用户取消删除');
  136. }
  137. }
  138. });
  139. },
  140. // 现在只针对做 一 对 多 的 故障数据
  141. goContact(type, index, obj) {
  142. let data = obj ? JSON.stringify(obj) : '';
  143. uni.navigateTo({
  144. url: `/pages/salesServiceManagement/demandList/components/contactAdd?type=${type}&index=${index}&data=${data}`
  145. })
  146. },
  147. addFault() {
  148. },
  149. getTabData() {
  150. return this.contactList || []
  151. }
  152. },
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. @import './invoice.scss';
  157. .bth_oper {
  158. display: flex;
  159. align-items: center;
  160. margin-top: 16rpx;
  161. border-bottom: 1px solid #e5e5e5;
  162. padding-bottom: 16rpx;
  163. .btn {
  164. width: 80rpx;
  165. height: 48rpx;
  166. line-height: 48rpx;
  167. text-align: center;
  168. background: #1890ff;
  169. font-size: 26rpx;
  170. color: #ffffff;
  171. border-radius: 8rpx;
  172. }
  173. .del {
  174. background: #ff4d4f;
  175. }
  176. .reserve {
  177. color: #e6a23c;
  178. font-size: 26rpx;
  179. margin-left: 18rpx;
  180. }
  181. }
  182. .action {
  183. display: flex;
  184. line-height: 22px;
  185. .text {
  186. margin-right: 12rpx;
  187. }
  188. /deep/ .u-button {
  189. width: 100rpx;
  190. font-size: 26rpx;
  191. margin-left: 10rpx;
  192. margin-right: 0rpx;
  193. background: #157a2c;
  194. color: #fff !important;
  195. }
  196. }
  197. </style>