| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- <template>
- <view class="content">
- <view class="supplyInfo">
- <view class="flex">
- <label>发布标题:</label>
- <input type="text" v-model="supplyInfo.title" class="input card" />
- </view>
- <view class="flex">
- <label>选择类型:</label>
- <view class="picker">
- <picker
- @change="bindPickerChange"
- :value="index"
- :range="array"
- range-key="name"
- class="pick"
- >
- <view class="picker_title">
- <view class="pickername">
- <view>
- {{ array[index].name }}
- </view>
- </view>
- <view class="triangle-down"></view>
- </view>
- </picker>
- </view>
- </view>
- <view class="flex">
- <label>详情:</label>
- <textarea v-model="supplyInfo.msg" class="area card"></textarea>
- </view>
- <view class="update_photo">
- <view class="title"></view>
- <view>上传图片:</view>
- <view class="update_container card upload-parent-box">
- <view class="update_button display-flex">
- <view class="upload-box" @click="getImage('album')">
- <view class="img">
- <image src="/static/appeal/photo.png" class="photo"></image>
- </view>
- <view class="txt">上传</view>
- </view>
- <view
- class="display-flex upload-box-photo"
- v-for="(item, index) in uploadList"
- :key="index"
- >
- <image
- :src="item"
- mode="aspectFit"
- style="width: 100%; height: 100%"
- @click="showLarge(item)"
- />
- <image
- src="../../static/del.png"
- class="del-icon"
- mode="aspectFit"
- style="width: 30rpx; height: 30rpx"
- @click="delPhoto(index)"
- ></image>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="info">
- <view class="title">企业信息</view>
- <view class="name flex">
- <label>企业名称:</label>
- <input type="text" class="card input" v-model="company.name" />
- </view>
- <view class="tel flex">
- <label>统一社会信用代码:</label>
- <input type="text" class="card input" v-model="company.code" />
- </view>
- <view class="tel flex">
- <label>联系电话:</label>
- <input type="text" class="card input" v-model="company.tel" />
- </view>
- </view>
- <button class="submit" @tap="submit">提交</button>
- </view>
- </template>
- <script>
- import md5 from "@/common/md5.js";
- export default {
- data() {
- return {
- array: [{ name: "供需" }, { name: "需求" }],
- index: 0,
- supplyInfo: {
- title: "",
- msg: "",
- },
- company: {
- name: uni.getStorageSync("supply_name") || "",
- code: uni.getStorageSync("supply_code") || "",
- tel: uni.getStorageSync("supply_tel") || "",
- },
- uploadList: [],
- imgIdList: [],
- };
- },
- methods: {
- submit() {
- if (
- this.company.name === "" ||
- this.company.code === "" ||
- this.company.tel === ""
- ) {
- uni.showToast({
- title: "企业信息不完善",
- icon: "error",
- });
- return;
- }
- let md5Sign = md5(
- "method=" +
- "need" +
- "×tamp=" +
- getApp().globalData.globalTimestamp +
- "&secret=" +
- getApp().globalData.secret
- );
- let url =
- getApp().globalData.shareUrl +
- "api/api.php" +
- "?method=need&source=need&action=add×tamp=" +
- getApp().globalData.globalTimestamp +
- "&sign=" +
- md5Sign;
- let postData = {
- title: this.supplyInfo.title,
- type: +this.index == 0 ? 2 : 1,
- content: this.supplyInfo.msg,
- company_name: this.company.name,
- company_code: this.company.code,
- phone: this.company.tel,
- attach_ids: this.imgIdList.join(),
- openId: getApp().globalData.open_id,
- };
- uni.request({
- url: url,
- method: "POST",
- header: {
- "content-type": "application/x-www-form-urlencoded",
- },
- data: postData,
- success: (res) => {
- if (res.data.code === 200) {
- uni.showToast({
- title: "发布供需成功",
- icon: "none",
- duration: 2000,
- });
- uni.setStorageSync("supply_name", this.company.name);
- uni.setStorageSync("supply_code", this.company.code);
- uni.setStorageSync("supply_tel", this.company.tel);
- setTimeout(() => {
- uni.navigateBack({});
- }, 1500);
- } else {
- uni.showToast({
- title: res.data.msg,
- icon: "none",
- duration: 2500,
- });
- }
- },
- fail: () => {
- console.log("连接失败");
- },
- });
- },
- bindPickerChange(e) {
- this.index = e.detail.value;
- },
- getImage(type) {
- let that = this;
- if (that.uploadList.length >= 3) {
- uni.showToast({
- title: "最多上传3张图片",
- icon: "none",
- duration: 2500,
- });
- return;
- }
- uni.chooseImage({
- sourceType: [type],
- count: 3 - that.uploadList.length,
- sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
- success: (res) => {
- for (let i = 0; i < res.tempFilePaths.length; i++) {
- that.uploadList.push(res.tempFilePaths[i]);
- that.uploadFileRequest(res.tempFilePaths[i]);
- }
- },
- });
- },
- uploadFileRequest(fileVal) {
- uni.showLoading({
- title: "上传中",
- mask: true,
- });
- let that = this;
- let md5Sign = md5(
- "method=" +
- "upload" +
- "×tamp=" +
- getApp().globalData.globalTimestamp +
- "&secret=" +
- getApp().globalData.secret
- );
- let url =
- getApp().globalData.shareUrl +
- "api/api.php" +
- "?method=upload&source=consult×tamp=" +
- getApp().globalData.globalTimestamp +
- "&sign=" +
- md5Sign;
- uni.uploadFile({
- url: url, //需要设置为全局
- filePath: fileVal,
- name: "file",
- formData: {
- file: fileVal,
- },
- success: (res) => {
- let tmpres = JSON.parse(res.data);
- console.log(tmpres);
- uni.hideLoading();
- that.imgIdList.push(tmpres.data.id);
- },
- fail: (res) => {
- console.log("上传请求失败");
- console.log(res);
- },
- });
- },
- delPhoto(idx) {
- this.uploadList.splice(idx, 1);
- this.imgIdList.splice(idx, 1);
- },
- showLarge(src) {
- uni.previewImage({
- urls: [src],
- longPressActions: {
- itemList: ["发送给朋友", "保存图片"],
- success: function (data) {},
- fail: function (err) {
- console.log(err.errMsg);
- },
- },
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .upload-parent-box {
- height: 150rpx;
- padding-top: 25rpx;
- padding-left: 20rpx;
- }
- .upload-box {
- display: flex;
- flex-flow: column;
- width: 25%;
- background-color: #e0e0e0;
- height: 140rpx;
- border-radius: 10rpx;
- padding-top: 15rpx;
- image {
- width: 60rpx !important;
- height: 60rpx !important;
- }
- }
- .upload-box-photo {
- width: 25%;
- height: 110rpx;
- border-radius: 10rpx;
- padding-top: 15rpx;
- position: relative;
- }
- .del-icon {
- position: absolute;
- right: 0;
- width: 30rpx;
- height: 30rpx;
- }
- .update_button {
- text-align: center;
- display: flex;
- }
- .content {
- font-size: 28rpx;
- font-weight: 200;
- padding: 1% 2%;
- .title {
- font-size: 30rpx;
- margin: 4% 0;
- }
- label {
- display: inline-block;
- width: 25%;
- vertical-align: middle;
- }
- .card {
- background-color: rgb(248, 247, 247);
- border-radius: 10rpx;
- }
- .flex {
- display: flex;
- align-items: center;
- margin-bottom: 2%;
- }
- .input {
- padding: 0 2%;
- margin: 2% 0;
- display: inline-block;
- width: 80%;
- height: 70rpx;
- }
- .supplyInfo {
- border-radius: 40rpx;
- padding: 4%;
- box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
- margin: 30rpx 0 30rpx 0;
- .area {
- height: 200rpx;
- padding: 20rpx;
- box-sizing: border-box;
- }
- .picker {
- width: 80%;
- height: 70rpx;
- background: rgb(248, 247, 247);
- display: flex;
- align-items: center;
- position: relative;
- .pick {
- width: 100%;
- }
- .picker_title {
- display: flex;
- width: 100%;
- margin-left: 30rpx;
- align-items: center;
- justify-content: space-between;
- .triangle-down {
- width: 0;
- height: 0;
- border-top: 15rpx solid rgb(173, 173, 173);
- border-left: 15rpx solid transparent;
- border-right: 15rpx solid transparent;
- position: absolute;
- right: 10rpx;
- }
- .pickername {
- font-weight: 100;
- }
- }
- }
- .upload-box {
- width: 25%;
- background-color: #e0e0e0;
- height: 110rpx;
- border-radius: 10rpx;
- padding-top: 15rpx;
- }
- .upload-box-photo {
- width: 25%;
- height: 110rpx;
- border-radius: 10rpx;
- padding-top: 15rpx;
- position: relative;
- }
- .del-icon {
- position: absolute;
- right: 0;
- width: 30rpx;
- height: 30rpx;
- }
- image {
- width: 60rpx;
- height: 60rpx;
- }
- .update_button {
- text-align: center;
- display: flex;
- }
- }
- .info {
- margin-top: 2%;
- border-radius: 40rpx;
- padding: 2% 4%;
- box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
- }
- .submit {
- color: white;
- font-weight: normal;
- width: 70%;
- border-radius: 20rpx;
- background-color: #02a7f0;
- margin: 50rpx auto;
- }
- }
- </style>
|